Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.h
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2018 The Bitcoin developers | // Copyright (c) 2017-2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_RPC_SERVER_H | #ifndef BITCOIN_RPC_SERVER_H | ||||
#define BITCOIN_RPC_SERVER_H | #define BITCOIN_RPC_SERVER_H | ||||
#include "amount.h" | #include "amount.h" | ||||
#include "rpc/command.h" | |||||
#include "rpc/jsonrpcrequest.h" | #include "rpc/jsonrpcrequest.h" | ||||
#include "rpc/protocol.h" | #include "rpc/protocol.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <functional> | #include <functional> | ||||
#include <list> | #include <list> | ||||
Show All 26 Lines | struct UniValueType { | ||||
bool typeAny; | bool typeAny; | ||||
UniValue::VType type; | UniValue::VType type; | ||||
}; | }; | ||||
/** | /** | ||||
* Class for registering and managing all RPC calls. | * Class for registering and managing all RPC calls. | ||||
*/ | */ | ||||
class RPCServer : public boost::noncopyable { | class RPCServer : public boost::noncopyable { | ||||
private: | |||||
std::map<std::string, std::function<RPCCommand *(const JSONRPCRequest &)>> | |||||
commands; | |||||
public: | public: | ||||
RPCServer() {} | RPCServer() {} | ||||
/** | /** | ||||
* Attempts to execute an RPC command from the given request. | * Attempts to execute an RPC command from the given request. | ||||
* If no RPC command exists that matches the request, an error is returned. | * If no RPC command exists that matches the request, an error is returned. | ||||
*/ | */ | ||||
UniValue ExecuteCommand(Config &config, | UniValue ExecuteCommand(Config &config, | ||||
const JSONRPCRequest &request) const; | const JSONRPCRequest &request) const; | ||||
/** | |||||
* Register an RPC command factory function. | |||||
*/ | |||||
void RegisterCommand( | |||||
const std::string &commandName, | |||||
std::function<RPCCommand *(const JSONRPCRequest &)> factory) { | |||||
deadalnix: The function name was kind of an hint that it should take a command as an argument.
What does… | |||||
jasonbcoxAuthorUnsubmitted Done Inline ActionsIt's technically registering a command's factory function. I can rename this function to RegisterCommandFactory to be more clear, as registering commands requires something for dependency injection. This factory is that something. jasonbcox: It's technically registering a command's factory function. I can rename this function to… | |||||
commands[commandName] = factory; | |||||
} | |||||
/** | |||||
* Return an RPCCommand factory if one matches the given command name. | |||||
* Returns an error factory that produces a nullptr RPCCommand* if no | |||||
* command matches. | |||||
*/ | |||||
std::function<RPCCommand *(const JSONRPCRequest &)> | |||||
MatchCommand(std::string name) const; | |||||
}; | }; | ||||
/** | /** | ||||
* Query whether RPC is running | * Query whether RPC is running | ||||
*/ | */ | ||||
bool IsRPCRunning(); | bool IsRPCRunning(); | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 209 Lines • Show Last 20 Lines |
The function name was kind of an hint that it should take a command as an argument.
What does this do ? It register something. What is that something ? It is a command.