Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 13, 2023
1 parent e3d382f commit 355cf6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
39 changes: 23 additions & 16 deletions src/ripple/rpc/impl/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <ripple/rpc/impl/Handler.h>
#include <ripple/rpc/impl/RPCHelpers.h>

#include <map>

namespace ripple {
namespace RPC {
namespace {
Expand Down Expand Up @@ -57,6 +59,19 @@ handle(JsonContext& context, Object& object)
return status;
};

template <typename HandlerImpl>
Handler
handlerFrom()
{
return {
HandlerImpl::name,
&handle<Json::Value, HandlerImpl>,
HandlerImpl::role,
HandlerImpl::condition,
HandlerImpl::minApiVer,
HandlerImpl::maxApiVer};
}

Handler const handlerArray[]{
// Some handlers not specified here are added to the table via addHandler()
// Request-response methods
Expand Down Expand Up @@ -244,15 +259,15 @@ class HandlerTable
std::vector<char const*>
getHandlerNames() const
{
static constexpr auto less = [](const char* const lh,
const char* const rh) -> bool {
return std::strcmp(lh, rh);
};
std::set<const char* const, decltype(less)> names;
std::vector<char const*> ret;
for (auto const& i : table_)
names.insert(i.second.name_);
{
// Note, table_ is always ordered, allowing such a simple check
if (ret.empty() || std::strcmp(ret.back(), i.second.name_) != 0)
ret.push_back(i.second.name_);
}

return std::vector<char const*>{names.begin(), names.end()};
return ret;
}

private:
Expand All @@ -270,15 +285,7 @@ class HandlerTable
HandlerImpl::minApiVer,
HandlerImpl::maxApiVer));

Handler h;
h.name_ = HandlerImpl::name;
h.valueMethod_ = &handle<Json::Value, HandlerImpl>;
h.role_ = HandlerImpl::role;
h.condition_ = HandlerImpl::condition;
h.minApiVer_ = HandlerImpl::minApiVer;
h.maxApiVer_ = HandlerImpl::maxApiVer;

table_.insert({HandlerImpl::name, h});
table_.insert({HandlerImpl::name, handlerFrom<HandlerImpl>()});
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct Handler
RPC::Condition condition_;

unsigned minApiVer_ = 1;
unsigned maxApiVer_ = RPC::apiMaximumValidVersion;
unsigned maxApiVer_ = apiMaximumValidVersion;
};

Handler const*
Expand Down

0 comments on commit 355cf6c

Please sign in to comment.