ADTF  3.18.2
json_rpc.h
Go to the documentation of this file.
1 
15 #ifndef PKG_RPC_JSON_RPC_H_INCLUDED
16 #define PKG_RPC_JSON_RPC_H_INCLUDED
17 
18 #include <rpc/rpc_server.h>
19 
20 #include <jsonrpccpp/client/iclientconnector.h>
21 #include <jsonrpccpp/server/abstractserverconnector.h>
22 
23 namespace rpc {
24 
29 public:
36 #ifndef PKGRPC_NO_TOSTRING
42  static std::string to_string(uint64_t nValue);
48  static std::string to_string(int64_t nValue);
49 #endif // PKGRPC_NO_TOSTRING
55  static a_util::result::Result json_to_result(const Json::Value& oValue);
61  static uint64_t stoull(const std::string& strValue);
67  static int64_t stoll(const std::string& strValue);
68 };
69 
76 template <typename Stub, typename Connector, typename ConnectorInitializer>
77 class jsonrpc_remote_object : private Connector, public Stub {
78 public:
84  jsonrpc_remote_object(const ConnectorInitializer& oInitializer);
85 
86 protected:
91  Stub& GetStub() const;
92 };
93 
101 template <typename Stub, typename Interface, typename Connector, typename ConnectorInitializer>
103  : private jsonrpc_remote_object<Stub, Connector, ConnectorInitializer>,
104  protected cJSONConversions,
105  public Interface {
106 public:
112  jsonrpc_remote_interface(const ConnectorInitializer& oInitializer);
113 
114 protected:
119  Stub& GetStub() const;
120 };
121 
126 public:
143  bool SendResponse(const std::string& response, void* addInfo);
150  bool OnRequest(const std::string& request, IResponse* response);
151 };
152 
158 template <typename ServerStub, typename Connector = cServerConnector>
159 class jsonrpc_object_server : protected Connector,
160  protected ServerStub,
161  public IRPCObject,
162  protected cJSONConversions {
163 public:
166 
167 public:
174  virtual a_util::result::Result HandleCall(const char* strRequest,
175  size_t nRequestSize,
176  IResponse& oResponse);
177 };
178 
179 } // namespace rpc
180 
181 #endif // PKG_RPC_HTTP_RPC_PROTOCOL_H_INCLUDED
182 
Represents a JSON value.
Definition: value.h:177
A common result class usable as return value throughout.
Interface of an object that support remote calls.
Definition: rpc_server.h:47
Interface for returning a response to a remote call.
Definition: rpc_server.h:34
Utility base class to facilitate JSON conversions.
Definition: json_rpc.h:28
static std::string to_string(uint64_t nValue)
Convert an unsigned integer to a string.
static Json::Value result_to_json(a_util::result::Result nResult)
Get the Json::Value representation of an object of type a_util::result::Result.
static int64_t stoll(const std::string &strValue)
Convert a string to a signed integer.
static std::string to_string(int64_t nValue)
Convert a signed integer to a string.
static uint64_t stoull(const std::string &strValue)
Convert a string to an unsigned integer.
Connector that sends responses via IResponse.
Definition: json_rpc.h:125
bool StopListening()
Currently not implemented, returns always true.
bool OnRequest(const std::string &request, IResponse *response)
Called on request.
bool SendResponse(const std::string &response, void *addInfo)
Sets the response to addInfo which must be of type IResponse.
bool StartListening()
Currently not implemented, returns always true.
Template to implement an RPC object.
Definition: json_rpc.h:162
virtual a_util::result::Result HandleCall(const char *strRequest, size_t nRequestSize, IResponse &oResponse)
Handles an RPC call.
Definition: json_rpc_impl.h:56
Template for mapping interfaces to a client stub.
Definition: json_rpc.h:105
Stub & GetStub() const
Access the rpc stub.
Definition: json_rpc_impl.h:43
jsonrpc_remote_interface(const ConnectorInitializer &oInitializer)
Constructor.
Definition: json_rpc_impl.h:37
Template for direct usage of the stub methods.
Definition: json_rpc.h:77
Stub & GetStub() const
Access the rpc stub.
Definition: json_rpc_impl.h:30
jsonrpc_remote_object(const ConnectorInitializer &oInitializer)
Constructor.
Definition: json_rpc_impl.h:23
RPC Protocol declaration.
RPC Protocol declaration.