Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | UniValue RPCServer::ExecuteCommand(Config &config, | ||||
// Check if context-free RPC method is valid and execute it | // Check if context-free RPC method is valid and execute it | ||||
return tableRPC.execute(config, request); | return tableRPC.execute(config, request); | ||||
} | } | ||||
static struct CRPCSignals { | static struct CRPCSignals { | ||||
boost::signals2::signal<void()> Started; | boost::signals2::signal<void()> Started; | ||||
boost::signals2::signal<void()> Stopped; | boost::signals2::signal<void()> Stopped; | ||||
boost::signals2::signal<void(const ContextFreeRPCCommand &)> PreCommand; | boost::signals2::signal<void(const ContextFreeRPCCommand &)> PreCommand; | ||||
boost::signals2::signal<void(const ContextFreeRPCCommand &)> PostCommand; | |||||
} g_rpcSignals; | } g_rpcSignals; | ||||
void RPCServerSignals::OnStarted(std::function<void()> slot) { | void RPCServerSignals::OnStarted(std::function<void()> slot) { | ||||
g_rpcSignals.Started.connect(slot); | g_rpcSignals.Started.connect(slot); | ||||
} | } | ||||
void RPCServerSignals::OnStopped(std::function<void()> slot) { | void RPCServerSignals::OnStopped(std::function<void()> slot) { | ||||
g_rpcSignals.Stopped.connect(slot); | g_rpcSignals.Stopped.connect(slot); | ||||
} | } | ||||
void RPCServerSignals::OnPreCommand( | void RPCServerSignals::OnPreCommand( | ||||
std::function<void(const ContextFreeRPCCommand &)> slot) { | std::function<void(const ContextFreeRPCCommand &)> slot) { | ||||
g_rpcSignals.PreCommand.connect(boost::bind(slot, _1)); | g_rpcSignals.PreCommand.connect(boost::bind(slot, _1)); | ||||
} | } | ||||
void RPCServerSignals::OnPostCommand( | |||||
std::function<void(const ContextFreeRPCCommand &)> slot) { | |||||
g_rpcSignals.PostCommand.connect(boost::bind(slot, _1)); | |||||
} | |||||
void RPCTypeCheck(const UniValue ¶ms, | void RPCTypeCheck(const UniValue ¶ms, | ||||
const std::list<UniValue::VType> &typesExpected, | const std::list<UniValue::VType> &typesExpected, | ||||
bool fAllowNull) { | bool fAllowNull) { | ||||
unsigned int i = 0; | unsigned int i = 0; | ||||
for (UniValue::VType t : typesExpected) { | for (UniValue::VType t : typesExpected) { | ||||
if (params.size() <= i) { | if (params.size() <= i) { | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 427 Lines • ▼ Show 20 Lines | try { | ||||
return pcmd->call(config, | return pcmd->call(config, | ||||
transformNamedArguments(request, pcmd->argNames)); | transformNamedArguments(request, pcmd->argNames)); | ||||
} else { | } else { | ||||
return pcmd->call(config, request); | return pcmd->call(config, request); | ||||
} | } | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
throw JSONRPCError(RPC_MISC_ERROR, e.what()); | throw JSONRPCError(RPC_MISC_ERROR, e.what()); | ||||
} | } | ||||
g_rpcSignals.PostCommand(*pcmd); | |||||
} | } | ||||
std::vector<std::string> CRPCTable::listCommands() const { | std::vector<std::string> CRPCTable::listCommands() const { | ||||
std::vector<std::string> commandList; | std::vector<std::string> commandList; | ||||
typedef std::map<std::string, const ContextFreeRPCCommand *> commandMap; | typedef std::map<std::string, const ContextFreeRPCCommand *> commandMap; | ||||
std::transform(mapCommands.begin(), mapCommands.end(), | std::transform(mapCommands.begin(), mapCommands.end(), | ||||
std::back_inserter(commandList), | std::back_inserter(commandList), | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |