JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
|
A JSON-RPC client for sending requests and receiving responses. More...
#include <client.hpp>
Public Member Functions | |
Client (std::unique_ptr< transport::Transport > transport) | |
Constructs a JSON-RPC client with a specified transport layer. | |
~Client ()=default | |
Destructor. | |
Client (const Client &)=delete | |
auto | operator= (const Client &) -> Client &=delete |
Client (Client &&) noexcept=delete | |
auto | operator= (Client &&) noexcept -> Client &=delete |
void | Start () |
Starts the JSON-RPC client listener thread. | |
void | Stop () |
Stops the JSON-RPC client listener thread. | |
auto | IsRunning () const -> bool |
Checks if the client listener is running. | |
auto | SendMethodCall (const std::string &method, std::optional< nlohmann::json > params=std::nullopt) -> nlohmann::json |
Sends a JSON-RPC method call and waits for the response. | |
auto | SendMethodCallAsync (const std::string &method, std::optional< nlohmann::json > params=std::nullopt) -> std::future< nlohmann::json > |
Sends a JSON-RPC method call asynchronously. | |
void | SendNotification (const std::string &method, std::optional< nlohmann::json > params=std::nullopt) |
Sends a JSON-RPC notification. | |
auto | HasPendingRequests () const -> bool |
Checks if there are any pending requests. | |
A JSON-RPC client for sending requests and receiving responses.
This client allows for synchronous and asynchronous method calls as well as notifications.
Definition at line 25 of file client.hpp.
|
explicit |
Constructs a JSON-RPC client with a specified transport layer.
transport | A unique pointer to a transport layer used for communication. |
Definition at line 7 of file client.cpp.
|
default |
Destructor.
|
delete |
|
deletenoexcept |
auto jsonrpc::client::Client::HasPendingRequests | ( | ) | const -> bool |
Checks if there are any pending requests.
Definition at line 30 of file client.cpp.
auto jsonrpc::client::Client::IsRunning | ( | ) | const -> bool |
Checks if the client listener is running.
Definition at line 26 of file client.cpp.
auto jsonrpc::client::Client::SendMethodCall | ( | const std::string & | method, |
std::optional< nlohmann::json > | params = std::nullopt ) -> nlohmann::json |
Sends a JSON-RPC method call and waits for the response.
This is a blocking call that sends a method request to the server and waits for the corresponding response.
method | The name of the method to call. |
params | Optional parameters to pass to the method. |
Definition at line 46 of file client.cpp.
auto jsonrpc::client::Client::SendMethodCallAsync | ( | const std::string & | method, |
std::optional< nlohmann::json > | params = std::nullopt ) -> std::future<nlohmann::json> |
Sends a JSON-RPC method call asynchronously.
This method sends a request to the server without blocking the calling thread.
method | The name of the method to call. |
params | Optional parameters to pass to the method. |
Definition at line 55 of file client.cpp.
void jsonrpc::client::Client::SendNotification | ( | const std::string & | method, |
std::optional< nlohmann::json > | params = std::nullopt ) |
Sends a JSON-RPC notification.
Notifications do not expect a response from the server.
method | The name of the method to notify. |
params | Optional parameters to pass to the method. |
Definition at line 64 of file client.cpp.
void jsonrpc::client::Client::Start | ( | ) |
Starts the JSON-RPC client listener thread.
Initializes and starts a background thread that listens for responses from the server. This must be called before sending any requests.
Definition at line 12 of file client.cpp.
void jsonrpc::client::Client::Stop | ( | ) |
Stops the JSON-RPC client listener thread.
Stops the background listener thread and waits for it to join. This should be called before the client is destroyed or when the client no longer needs to listen for responses.
Definition at line 18 of file client.cpp.