| 1 | /************************************************************************* |
| 2 | * libjson-rpc-cpp |
| 3 | ************************************************************************* |
| 4 | * @file rpcprotocolserverv2.h |
| 5 | * @date 31.12.2012 |
| 6 | * @author Peter Spiess-Knafl <dev@spiessknafl.at> |
| 7 | * @license See attached LICENSE.txt |
| 8 | ************************************************************************/ |
| 9 | |
| 10 | #ifndef JSONRPC_CPP_RPCPROTOCOLSERVERV2_H_ |
| 11 | #define JSONRPC_CPP_RPCPROTOCOLSERVERV2_H_ |
| 12 | |
| 13 | #include <map> |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "abstractprotocolhandler.h" |
| 18 | #include <jsonrpccpp/common/exception.h> |
| 19 | |
| 20 | #define KEY_REQUEST_VERSION "jsonrpc" |
| 21 | #define JSON_RPC_VERSION2 "2.0" |
| 22 | |
| 23 | namespace jsonrpc { |
| 24 | class RpcProtocolServerV2 : public AbstractProtocolHandler { |
| 25 | public: |
| 26 | RpcProtocolServerV2(IProcedureInvokationHandler &handler); |
| 27 | |
| 28 | void HandleJsonRequest(const Json::Value &request, Json::Value &response); |
| 29 | bool ValidateRequestFields(const Json::Value &val); |
| 30 | void WrapResult(const Json::Value &request, Json::Value &response, Json::Value &retValue); |
| 31 | void WrapError(const Json::Value &request, int code, const std::string &message, Json::Value &result); |
| 32 | void WrapException(const Json::Value &request, const JsonRpcException &exception, Json::Value &result); |
| 33 | procedure_t GetRequestType(const Json::Value &request); |
| 34 | |
| 35 | private: |
| 36 | void HandleSingleRequest(const Json::Value &request, Json::Value &response); |
| 37 | void HandleBatchRequest(const Json::Value &requests, Json::Value &response); |
| 38 | }; |
| 39 | |
| 40 | } /* namespace jsonrpc */ |
| 41 | #endif /* JSONRPC_CPP_RPCPROTOCOLSERVERV2_H_ */ |
| 42 | |