Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.h
Show All 22 Lines | |||||
static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1; | static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1; | ||||
class ContextFreeRPCCommand; | class ContextFreeRPCCommand; | ||||
namespace RPCServerSignals { | namespace RPCServerSignals { | ||||
void OnStarted(std::function<void()> slot); | void OnStarted(std::function<void()> slot); | ||||
void OnStopped(std::function<void()> slot); | void OnStopped(std::function<void()> slot); | ||||
void OnPreCommand(std::function<void(const ContextFreeRPCCommand &)> slot); | |||||
} // namespace RPCServerSignals | } // namespace RPCServerSignals | ||||
class CBlockIndex; | class CBlockIndex; | ||||
class Config; | class Config; | ||||
class CNetAddr; | class CNetAddr; | ||||
/** | /** | ||||
* Wrapper for UniValue::VType, which includes typeAny: used to denote don't | * Wrapper for UniValue::VType, which includes typeAny: used to denote don't | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | typedef UniValue (*rpcfn_type)(Config &config, | ||||
const JSONRPCRequest &jsonRequest); | const JSONRPCRequest &jsonRequest); | ||||
typedef UniValue (*const_rpcfn_type)(const Config &config, | typedef UniValue (*const_rpcfn_type)(const Config &config, | ||||
const JSONRPCRequest &jsonRequest); | const JSONRPCRequest &jsonRequest); | ||||
class ContextFreeRPCCommand { | class ContextFreeRPCCommand { | ||||
public: | public: | ||||
std::string category; | std::string category; | ||||
std::string name; | std::string name; | ||||
bool okSafeMode; | |||||
private: | private: | ||||
union { | union { | ||||
rpcfn_type fn; | rpcfn_type fn; | ||||
const_rpcfn_type cfn; | const_rpcfn_type cfn; | ||||
} actor; | } actor; | ||||
bool useConstConfig; | bool useConstConfig; | ||||
public: | public: | ||||
std::vector<std::string> argNames; | std::vector<std::string> argNames; | ||||
ContextFreeRPCCommand(std::string _category, std::string _name, | ContextFreeRPCCommand(std::string _category, std::string _name, | ||||
rpcfn_type _actor, bool _okSafeMode, | rpcfn_type _actor, std::vector<std::string> _argNames) | ||||
std::vector<std::string> _argNames) | |||||
: category{std::move(_category)}, name{std::move(_name)}, | : category{std::move(_category)}, name{std::move(_name)}, | ||||
okSafeMode{_okSafeMode}, useConstConfig{false}, argNames{std::move( | useConstConfig{false}, argNames{std::move(_argNames)} { | ||||
_argNames)} { | |||||
actor.fn = _actor; | actor.fn = _actor; | ||||
} | } | ||||
/** | /** | ||||
* There are 2 constructors depending Config is const or not, so we | * There are 2 constructors depending Config is const or not, so we | ||||
* can call the command through the proper pointer. Casting constness | * can call the command through the proper pointer. Casting constness | ||||
* on parameters of function is undefined behavior. | * on parameters of function is undefined behavior. | ||||
*/ | */ | ||||
ContextFreeRPCCommand(std::string _category, std::string _name, | ContextFreeRPCCommand(std::string _category, std::string _name, | ||||
const_rpcfn_type _actor, bool _okSafeMode, | const_rpcfn_type _actor, | ||||
std::vector<std::string> _argNames) | std::vector<std::string> _argNames) | ||||
: category{std::move(_category)}, name{std::move(_name)}, | : category{std::move(_category)}, name{std::move(_name)}, | ||||
okSafeMode{_okSafeMode}, useConstConfig{true}, argNames{std::move( | useConstConfig{true}, argNames{std::move(_argNames)} { | ||||
_argNames)} { | |||||
actor.cfn = _actor; | actor.cfn = _actor; | ||||
} | } | ||||
UniValue call(Config &config, const JSONRPCRequest &jsonRequest) const { | UniValue call(Config &config, const JSONRPCRequest &jsonRequest) const { | ||||
return useConstConfig ? (*actor.cfn)(config, jsonRequest) | return useConstConfig ? (*actor.cfn)(config, jsonRequest) | ||||
: (*actor.fn)(config, jsonRequest); | : (*actor.fn)(config, jsonRequest); | ||||
}; | }; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |