10#include <unordered_map>
12#include <nlohmann/json_fwd.hpp>
33 explicit Client(std::unique_ptr<transport::Transport> transport);
81 const std::
string &method,
82 std::optional<nlohmann::json> params = std::nullopt) -> nlohmann::json;
95 const std::
string &method,
96 std::optional<nlohmann::json> params = std::nullopt)
97 -> std::future<nlohmann::json>;
108 const std::
string &method,
109 std::optional<nlohmann::json> params = std::nullopt);
133 auto SendRequest(const
Request &request) -> nlohmann::json;
143 auto SendRequestAsync(const
Request &request) -> std::future<nlohmann::json>;
150 auto GetNextRequestId() ->
int;
160 void HandleResponse(const std::
string &response);
170 static auto ValidateResponse(const nlohmann::json &response) ->
bool;
173 std::unique_ptr<transport::Transport> transport_;
176 std::atomic<
int> req_id_counter_{0};
179 std::atomic<int> expected_count_{0};
182 std::unordered_map<int, std::promise<nlohmann::json>> requests_map_;
185 mutable std::mutex requests_mutex_;
188 std::thread listener_;
191 std::atomic<bool> is_running_{
false};
A JSON-RPC client for sending requests and receiving responses.
~Client()=default
Destructor.
auto operator=(const Client &) -> Client &=delete
void SendNotification(const std::string &method, std::optional< nlohmann::json > params=std::nullopt)
Sends a JSON-RPC notification.
void Start()
Starts the JSON-RPC client listener thread.
Client(std::unique_ptr< transport::Transport > transport)
Constructs a JSON-RPC client with a specified transport layer.
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 Stop()
Stops the JSON-RPC client listener thread.
auto HasPendingRequests() const -> bool
Checks if there are any pending requests.
Client(const Client &)=delete
Client(Client &&) noexcept=delete
Represents a JSON-RPC request.