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

Transport-agnostic base for client (RPC caller) node implementations. More...

#include <client_impl.h>

Inheritance diagram for vlink::ClientImpl:
Collaboration diagram for vlink::ClientImpl:

Public Member Functions

 ~ClientImpl () override
 Destructor.
void interrupt () override
 Interrupts the client, waking any blocked wait_for_connected() or call() operation.
virtual void detect_connected (ConnectCallback &&callback)
 Registers a callback to be fired when the server connection state changes.
virtual bool wait_for_connected (std::chrono::milliseconds timeout)
 Blocks until the server is reachable or the timeout elapses.
virtual bool is_connected () const =0
 Returns true when the transport is connected to a server.
virtual bool call (const Bytes &req_data, MsgCallback &&callback, std::chrono::milliseconds timeout)=0
 Sends a request and blocks until the response arrives or the timeout elapses.
void update_connected ()
 Notifies the connection-detection subsystem that connectivity may have changed.

Public Attributes

bool is_resp_type {false}
 true when the call expects a response (vs fire-and-forget).

Protected Member Functions

 ClientImpl ()
 Protected constructor; initialises the client with kClient role.

Additional Inherited Members

Detailed Description

Transport-agnostic base for client (RPC caller) node implementations.

Provides the server-connection-detection infrastructure (condition variable + callback) used by Client<Req,Resp>::wait_for_connected() and Client<Req,Resp>::detect_connected(). Concrete backends override is_connected() to query the transport layer and call update_connected() whenever the server connection state changes.

Constructor & Destructor Documentation

◆ ~ClientImpl()

vlink::ClientImpl::~ClientImpl ( )
override

Destructor.

◆ ClientImpl()

vlink::ClientImpl::ClientImpl ( )
protected

Protected constructor; initialises the client with kClient role.

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

Member Function Documentation

◆ call()

virtual bool vlink::ClientImpl::call ( const Bytes & req_data,
MsgCallback && callback,
std::chrono::milliseconds timeout )
pure virtual

Sends a request and blocks until the response arrives or the timeout elapses.

Must be implemented by each concrete transport backend. req_data contains the serialised request payload. The callback is invoked with the response bytes once the round-trip completes.

Parameters
req_dataSerialised request payload.
callbackCallable void(const Bytes&) invoked with the response bytes.
timeoutMaximum time to wait for the response; negative = infinite.
Returns
true if a response was received within the timeout; false on timeout, interruption, or transport error.

◆ detect_connected()

virtual void vlink::ClientImpl::detect_connected ( ConnectCallback && callback)
virtual

Registers a callback to be fired when the server connection state changes.

The callback is stored and invoked with true when the server becomes reachable and false when it disconnects. If the server is already connected at registration time the callback is fired immediately with true before this function returns.

Parameters
callbackCallable void(bool) to invoke on connection state change.

◆ interrupt()

void vlink::ClientImpl::interrupt ( )
overridevirtual

Interrupts the client, waking any blocked wait_for_connected() or call() operation.

Calls NodeImpl::interrupt() to set the interrupted flag, then notify_all() on the internal condition variable so that any thread blocked in wait_for_connected() returns immediately. Concrete backends typically also forward the interrupt to any pending AckManager requests.

Reimplemented from vlink::NodeImpl.

◆ is_connected()

virtual bool vlink::ClientImpl::is_connected ( ) const
nodiscardpure virtual

Returns true when the transport is connected to a server.

Must be implemented by each concrete transport backend. Called by wait_for_connected() and update_connected() to determine whether the connection state has changed.

Returns
true if a server is reachable; false otherwise.

◆ update_connected()

void vlink::ClientImpl::update_connected ( )

Notifies the connection-detection subsystem that connectivity may have changed.

Called by the concrete transport backend whenever a server connects or disconnects. Compares the current is_connected() result against the cached state; if it differs, the condition variable is notified and the registered ConnectCallback is fired.

Note
This method is intended to be called from the transport's internal discovery thread, not from user code.

◆ wait_for_connected()

virtual bool vlink::ClientImpl::wait_for_connected ( std::chrono::milliseconds timeout)
virtual

Blocks until the server is reachable or the timeout elapses.

Returns immediately if is_connected() is already true. Otherwise waits on an internal condition variable that is notified by update_connected() and interrupt().

  • timeout < 0 (e.g. Timeout::kInfinite): waits indefinitely.
  • timeout >= 0: returns false if no server appears within the period.
Parameters
timeoutMaximum time to wait; negative value means wait forever.
Returns
true if the server was detected; false on timeout or interruption.

Member Data Documentation

◆ is_resp_type

bool vlink::ClientImpl::is_resp_type {false}

true when the call expects a response (vs fire-and-forget).


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