VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::ServerImpl Class Referenceabstract

Transport-agnostic base for server (RPC responder) node implementations. More...

#include <server_impl.h>

Inheritance diagram for vlink::ServerImpl:
Collaboration diagram for vlink::ServerImpl:

Public Member Functions

 ~ServerImpl () override
 Destructor.
virtual bool listen (ReqRespCallback &&callback)=0
 Registers the request handler callback.
virtual bool has_clients () const
 Returns true when at least one client is currently connected.
virtual bool reply (uint64_t req_id, const Bytes &resp_data, bool is_sync)
 Sends a response for a previously received request.

Public Attributes

bool is_listened {false}
 true after listen() has been successfully called.
bool is_resp_type {false}
 true when the server sends a response (vs fire-and-forget).
bool is_sync_type {false}
 true when the reply is sent synchronously inside the callback.

Protected Member Functions

 ServerImpl ()
 Protected constructor; initialises the server with kServer role.

Additional Inherited Members

Detailed Description

Transport-agnostic base for server (RPC responder) node implementations.

Concrete backends override listen(ReqRespCallback&&) to register the request handler, and optionally override has_clients() and reply() for client discovery and asynchronous response support respectively.

Constructor & Destructor Documentation

◆ ~ServerImpl()

vlink::ServerImpl::~ServerImpl ( )
override

Destructor.

◆ ServerImpl()

vlink::ServerImpl::ServerImpl ( )
protected

Protected constructor; initialises the server with kServer role.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ has_clients()

virtual bool vlink::ServerImpl::has_clients ( ) const
nodiscardvirtual

Returns true when at least one client is currently connected.

The default implementation returns false. Transports that support client discovery (e.g. DDS matched publications) override this method.

Returns
true if one or more clients are connected; false otherwise.

◆ listen()

virtual bool vlink::ServerImpl::listen ( ReqRespCallback && callback)
pure virtual

Registers the request handler callback.

Must be implemented by each concrete transport backend. The callback is invoked for every incoming RPC request with the request bytes and a unique identifier. After registration is_listened is set to true by the Server<Req,Resp> layer.

Parameters
callbackCallable void(uint64_t req_id, const Bytes& req_data, Bytes* resp_data) invoked for each incoming request. The handler writes its response into *resp_data; nullptr in fire-and-forget mode.
Returns
true if registration succeeded; false on error.

◆ reply()

virtual bool vlink::ServerImpl::reply ( uint64_t req_id,
const Bytes & resp_data,
bool is_sync )
virtual

Sends a response for a previously received request.

Used in asynchronous server mode (is_sync_type = false) to deliver a response after the request callback has returned. req_id must match the identifier provided to the request callback; resp_data contains the serialised response payload.

The default implementation logs a warning when is_sync is false and always returns false. Transports that support asynchronous replies override this method.

Parameters
req_idUnique identifier of the request to respond to.
resp_dataSerialised response payload.
is_synctrue if called synchronously inside the request callback; false for deferred (post-callback) replies.
Returns
true if the response was queued or sent; false on error.

Member Data Documentation

◆ is_listened

bool vlink::ServerImpl::is_listened {false}

true after listen() has been successfully called.

◆ is_resp_type

bool vlink::ServerImpl::is_resp_type {false}

true when the server sends a response (vs fire-and-forget).

◆ is_sync_type

bool vlink::ServerImpl::is_sync_type {false}

true when the reply is sent synchronously inside the callback.


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