OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::rpc::client< Request, Response > Class Template Referenceabstract

Generic RPC client. More...

#include <client.hpp>

Inheritance diagram for cbdc::rpc::client< Request, Response >:

Public Types

using request_type = request<Request>
 
using response_type = response<Response>
 
using response_callback_type = std::function<void(std::optional<Response>)>
 User-provided response callback function type for asynchronous requests.
 

Public Member Functions

 client ()=default
 
 client (client &&) noexcept=default
 
auto operator= (client &&) noexcept -> client &=default
 
 client (const client &)=delete
 
auto operator= (const client &) -> client &=delete
 
virtual ~client ()=default
 
auto call (Request request_payload, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero()) -> std::optional< Response >
 Issues the given request with an optional timeout, then waits for and returns the response.
 
auto call (Request request_payload, response_callback_type response_callback) -> bool
 Issues an asynchronous request and registers the given callback to handle the response.
 

Protected Types

using raw_callback_type = std::function<void(std::optional<response_type>)>
 Response callback function type for handling an RPC response.
 

Protected Member Functions

auto deserialize_response (cbdc::buffer &response_buf) -> std::optional< response_type >
 Deserializes a response object from the given buffer.
 

Detailed Description

template<typename Request, typename Response>
class cbdc::rpc::client< Request, Response >

Generic RPC client.

Handles serialization of requests and responses combined with a message header. Subclass to define actual remote communication logic.

Template Parameters
Requesttype for requests.
Responsetype for responses.

Definition at line 26 of file util/rpc/client.hpp.

Member Typedef Documentation

◆ raw_callback_type

template<typename Request , typename Response >
using cbdc::rpc::client< Request, Response >::raw_callback_type = std::function<void(std::optional<response_type>)>
protected

Response callback function type for handling an RPC response.

Definition at line 99 of file util/rpc/client.hpp.

◆ request_type

template<typename Request , typename Response >
using cbdc::rpc::client< Request, Response >::request_type = request<Request>

Definition at line 36 of file util/rpc/client.hpp.

◆ response_callback_type

template<typename Request , typename Response >
using cbdc::rpc::client< Request, Response >::response_callback_type = std::function<void(std::optional<Response>)>

User-provided response callback function type for asynchronous requests.

Definition at line 41 of file util/rpc/client.hpp.

◆ response_type

template<typename Request , typename Response >
using cbdc::rpc::client< Request, Response >::response_type = response<Response>

Definition at line 37 of file util/rpc/client.hpp.

Constructor & Destructor Documentation

◆ client() [1/3]

template<typename Request , typename Response >
cbdc::rpc::client< Request, Response >::client ( )
default

◆ client() [2/3]

template<typename Request , typename Response >
cbdc::rpc::client< Request, Response >::client ( client< Request, Response > && )
defaultnoexcept

◆ client() [3/3]

template<typename Request , typename Response >
cbdc::rpc::client< Request, Response >::client ( const client< Request, Response > & )
delete

◆ ~client()

template<typename Request , typename Response >
virtual cbdc::rpc::client< Request, Response >::~client ( )
virtualdefault

Member Function Documentation

◆ call() [1/2]

template<typename Request , typename Response >
auto cbdc::rpc::client< Request, Response >::call ( Request request_payload,
response_callback_type response_callback ) -> bool
inline

Issues an asynchronous request and registers the given callback to handle the response.

Serializes the request data, then transmits it with call_raw(). Thread safe.

Parameters
request_payloadpayload for the RPC.
response_callbackfunction for the request handler to call when the response is available.
Returns
true if the request was sent successfully.

Definition at line 73 of file util/rpc/client.hpp.

◆ call() [2/2]

template<typename Request , typename Response >
auto cbdc::rpc::client< Request, Response >::call ( Request request_payload,
std::chrono::milliseconds timeout = std::chrono::milliseconds::zero() ) -> std::optional<Response>
inlinenodiscard

Issues the given request with an optional timeout, then waits for and returns the response.

Serializes the request data, calls call_raw() to transmit the data and get a response, and returns the deserialized response. Thread safe.

Parameters
request_payloadpayload for the RPC.
timeoutoptional timeout in milliseconds. Zero indicates the call should not timeout.
Returns
response from the RPC, or std::nullopt if the call timed out or produced an error.

Definition at line 52 of file util/rpc/client.hpp.

◆ deserialize_response()

template<typename Request , typename Response >
auto cbdc::rpc::client< Request, Response >::deserialize_response ( cbdc::buffer & response_buf) -> std::optional<response_type>
inlineprotected

Deserializes a response object from the given buffer.

Parameters
response_bufbuffer containing an RPC response.
Returns
response object or std::nullopt if deserialization failed.

Definition at line 93 of file util/rpc/client.hpp.

◆ operator=() [1/2]

template<typename Request , typename Response >
auto cbdc::rpc::client< Request, Response >::operator= ( client< Request, Response > && ) -> client &=default
defaultnoexcept

◆ operator=() [2/2]

template<typename Request , typename Response >
auto cbdc::rpc::client< Request, Response >::operator= ( const client< Request, Response > & ) -> client &=delete
delete

The documentation for this class was generated from the following file: