void startServer () { // // Execute start up rpc commands. // if (getConfig ().RPC_STARTUP.isArray ()) { for (int i = 0; i != getConfig ().RPC_STARTUP.size (); ++i) { const Json::Value& jvCommand = getConfig ().RPC_STARTUP[i]; if (!getConfig ().QUIET) Log::out() << "Startup RPC: " << jvCommand; RPCHandler rhHandler (&getApp().getOPs ()); // VFALCO TODO Clean up this magic number LoadType loadType = LT_RPCReference; Json::Value jvResult = rhHandler.doCommand (jvCommand, RPCHandler::ADMIN, &loadType); if (!getConfig ().QUIET) Log::out() << "Result: " << jvResult; } } getApp().run (); // Blocks till we get a stop RPC. }
void startServer () { // // Execute start up rpc commands. // if (getConfig ().RPC_STARTUP.isArray ()) { for (int i = 0; i != getConfig ().RPC_STARTUP.size (); ++i) { const Json::Value& jvCommand = getConfig ().RPC_STARTUP[i]; if (!getConfig ().QUIET) Log::out() << "Startup RPC: " << jvCommand; RPCHandler rhHandler (&getApp().getOPs ()); Resource::Charge loadType = Resource::feeReferenceRPC; Json::Value jvResult = rhHandler.doCommand (jvCommand, Config::ADMIN, loadType); if (!getConfig ().QUIET) Log::out() << "Result: " << jvResult; } } getApp().run (); // Blocks till we get a stop RPC. }
void startServer () { // // Execute start up rpc commands. // if (theConfig.RPC_STARTUP.isArray ()) { for (int i = 0; i != theConfig.RPC_STARTUP.size (); ++i) { const Json::Value& jvCommand = theConfig.RPC_STARTUP[i]; if (!theConfig.QUIET) std::cerr << "Startup RPC: " << jvCommand << std::endl; RPCHandler rhHandler (&theApp->getOPs ()); // VFALCO TODO Clean up this magic number LoadType loadType = LT_RPCReference; Json::Value jvResult = rhHandler.doCommand (jvCommand, RPCHandler::ADMIN, &loadType); if (!theConfig.QUIET) std::cerr << "Result: " << jvResult << std::endl; } } theApp->run (); // Blocks till we get a stop RPC. }
Json::Value WSConnection::invokeCommand (Json::Value& jvRequest) { if (getConsumer().disconnect ()) { disconnect (); return rpcError (rpcSLOW_DOWN); } // Requests without "command" are invalid. // if (!jvRequest.isMember (jss::command)) { Json::Value jvResult (Json::objectValue); jvResult[jss::type] = jss::response; jvResult[jss::status] = jss::error; jvResult[jss::error] = jss::missingCommand; jvResult[jss::request] = jvRequest; if (jvRequest.isMember (jss::id)) { jvResult[jss::id] = jvRequest[jss::id]; } getConsumer().charge (Resource::feeInvalidRPC); return jvResult; } Resource::Charge loadType = Resource::feeReferenceRPC; RPCHandler mRPCHandler (m_netOPs, std::dynamic_pointer_cast<InfoSub> (this->shared_from_this ())); Json::Value jvResult (Json::objectValue); Config::Role const role = m_isPublic ? Config::GUEST // Don't check on the public interface. : getConfig ().getAdminRole ( jvRequest, m_remoteAddress); if (Config::FORBID == role) { jvResult[jss::result] = rpcError (rpcFORBIDDEN); } else { jvResult[jss::result] = mRPCHandler.doCommand (jvRequest, role, loadType); } getConsumer().charge (loadType); if (getConsumer().warn ()) { jvResult[jss::warning] = jss::load; } // Currently we will simply unwrap errors returned by the RPC // API, in the future maybe we can make the responses // consistent. // // Regularize result. This is duplicate code. if (jvResult[jss::result].isMember (jss::error)) { jvResult = jvResult[jss::result]; jvResult[jss::status] = jss::error; jvResult[jss::request] = jvRequest; } else { jvResult[jss::status] = jss::success; } if (jvRequest.isMember (jss::id)) { jvResult[jss::id] = jvRequest[jss::id]; } jvResult[jss::type] = jss::response; return jvResult; }