Open
Description
First of all this is really a great and useful framework.
I would like to raise the question or rather a discussion weather the interfaces are transport agnostic yes or no. If i am right in my conclusion they are not. Why?
- The http client
client.hpp
andiclientconnector.hpp
are implemented in a synchronous request/response pattern, therefore offering a Send method with return typestd::string
- A tcp client is preferably implemented in asynchronous send/receive pattern, therefore
client.hpp
andiclientconnector.hpp
cannot be used 'agnostically' out of the box - For using json-rpc-cxx with a tcp client/server, the
iclientconnector.hpp
andclient.hpp
have to be extended by offering, e.g. a Post method without a return value and a MessageHandler, e.g.
iclientconnector.hpp
using MessageHandler = std::function<void(const std::string)>;
virtual void Post(const std::string &request) = 0;
MessageHandler OnMessage;
client.hpp
using MessageHandler = std::function<void(const JsonRpcResponse)>;
JsonRpcClient(IClientConnector &connector, version v) : connector(connector), v(v)
{
connector.OnMessage = [this](const std::string &message)
{
json response = json::parse(message);
JsonRpcResponse rpc_response{};
...
OnMessage(rpc_response);
}
}
...
MessageHandler OnMessage;
client.cpp
std::future<JsonRpcResponse> future;
std::promise<JsonRpcResponse> promise;
JsonRpcResponse response;
client.OnMessage = [&] (const JsonRpcResponse &response) mutable
{
promise.set_value(response);
};
future = promise.get_future();
client.CallMethod(1, "GetProduct", {"0xff"});
response = future.get();
std::cout << response.result.dump() << std::endl;
Metadata
Metadata
Assignees
Labels
No labels