VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::Client< ReqT, RespT, SecT > Class Template Reference

Type-safe client for the VLink method (RPC) communication model. More...

#include <client.h>

Inheritance diagram for vlink::Client< ReqT, RespT, SecT >:
Collaboration diagram for vlink::Client< ReqT, RespT, SecT >:

Public Types

using UniquePtr = std::unique_ptr<Client<ReqT, RespT, SecT>>
 Unique-pointer alias.
using SharedPtr = std::shared_ptr<Client<ReqT, RespT, SecT>>
 Shared-pointer alias.
using ConnectCallback = NodeImpl::ConnectCallback
 Callback type fired when server connection state changes.
using RespCallback = std::function<void(const RespT&)>
 Callback type for async response delivery.

Public Member Functions

template<typename ConfT, typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
 Client (const ConfT &conf, InitType type=InitType::kWithInit)
 Constructs a client from a typed transport configuration object.
 Client (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a client from a URL string.
 ~Client () override
void detect_connected (ConnectCallback &&callback)
 Registers a callback invoked when the server connection state changes.
bool wait_for_connected (std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Blocks until a server is available or the timeout expires.
bool is_connected () const
 Returns true if a server is currently available.
bool invoke (const ReqT &req, RespT &resp, std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Sends a request and blocks until the response is received.
std::optional< RespT > invoke (const ReqT &req, std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Sends a request and returns the response as std::optional.
bool invoke (const ReqT &req, RespCallback &&callback)
 Sends a request and invokes callback asynchronously on the response.
std::future< RespT > async_invoke (const ReqT &req)
 Sends a request and returns a std::future for the response.
bool send (const ReqT &req)
 Sends a fire-and-forget request with no response.

Static Public Member Functions

static UniquePtr create_unique (const std::string &url_str, InitType type=InitType::kWithInit)
 Creates a Client on the heap wrapped in a unique_ptr.
static SharedPtr create_shared (const std::string &url_str, InitType type=InitType::kWithInit)
 Creates a Client on the heap wrapped in a shared_ptr.

Static Public Attributes

static constexpr ImplType kImplType = kClient
 Node role identifier (kClient).
static constexpr bool kHasResp = !std::is_same_v<RespT, Traits::EmptyType>
 true when RespT is not EmptyType (client expects a response).
static constexpr Serializer::Type kReqType = Serializer::get_type_of<ReqT>()
 Serializer type for ReqT.
static constexpr Serializer::Type kRespType = Serializer::get_type_of<RespT>()
 Serializer type for RespT.

Additional Inherited Members

Detailed Description

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
class vlink::Client< ReqT, RespT, SecT >

Type-safe client for the VLink method (RPC) communication model.

Template Parameters
ReqTRequest type.
RespTResponse type (defaults to Traits::EmptyType – fire-and-forget).
SecTSecurity mode.

Member Typedef Documentation

◆ ConnectCallback

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Client< ReqT, RespT, SecT >::ConnectCallback = NodeImpl::ConnectCallback

Callback type fired when server connection state changes.

◆ RespCallback

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Client< ReqT, RespT, SecT >::RespCallback = std::function<void(const RespT&)>

Callback type for async response delivery.

◆ SharedPtr

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Client< ReqT, RespT, SecT >::SharedPtr = std::shared_ptr<Client<ReqT, RespT, SecT>>

Shared-pointer alias.

◆ UniquePtr

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Client< ReqT, RespT, SecT >::UniquePtr = std::unique_ptr<Client<ReqT, RespT, SecT>>

Unique-pointer alias.

Constructor & Destructor Documentation

◆ Client() [1/2]

template<typename ReqT, typename RespT, SecurityType SecT>
template<typename ConfT, typename>
vlink::Client< ReqT, RespT, SecT >::Client ( const ConfT & conf,
InitType type = InitType::kWithInit )
inlineexplicit

Constructs a client from a typed transport configuration object.

Accepts any Conf-derived configuration. A compile-time static_assert verifies the configuration supports the client role.

Template Parameters
ConfTConf-derived configuration type.
Parameters
confPopulated configuration object.
typekWithInit to call init() immediately (default).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Client() [2/2]

template<typename ReqT, typename RespT, SecurityType SecT>
vlink::Client< ReqT, RespT, SecT >::Client ( const std::string & url_str,
InitType type = InitType::kWithInit )
inlineexplicit

Constructs a client from a URL string.

Parameters
url_strService URL (e.g. "someip://30490/0x1/my_method").
typekWithInit to call init() immediately (default).
Here is the call graph for this function:

◆ ~Client()

template<typename ReqT, typename RespT, SecurityType SecT>
vlink::Client< ReqT, RespT, SecT >::~Client ( )
inlineoverride
Here is the call graph for this function:

Member Function Documentation

◆ async_invoke()

template<typename ReqT, typename RespT, SecurityType SecT>
std::future< RespT > vlink::Client< ReqT, RespT, SecT >::async_invoke ( const ReqT & req)
inlinenodiscard

Sends a request and returns a std::future for the response.

Only valid when kHasResp is true (enforced by static_assert). The future is set when the response arrives. If the call fails (serialisation error, transport error, or deserialisation failure) the future's exception is set with an Exception::RuntimeError.

Parameters
reqRequest value to send.
Returns
std::future<RespT> resolved when the response arrives.

◆ create_shared()

template<typename ReqT, typename RespT, SecurityType SecT>
Client< ReqT, RespT, SecT >::SharedPtr vlink::Client< ReqT, RespT, SecT >::create_shared ( const std::string & url_str,
InitType type = InitType::kWithInit )
inlinestaticnodiscard

Creates a Client on the heap wrapped in a shared_ptr.

Parameters
url_strService URL string.
typekWithInit to call init() immediately (default).
Returns
SharedPtr owning the new client.

◆ create_unique()

template<typename ReqT, typename RespT, SecurityType SecT>
Client< ReqT, RespT, SecT >::UniquePtr vlink::Client< ReqT, RespT, SecT >::create_unique ( const std::string & url_str,
InitType type = InitType::kWithInit )
inlinestaticnodiscard

Creates a Client on the heap wrapped in a unique_ptr.

Parameters
url_strService URL string.
typekWithInit to call init() immediately (default).
Returns
UniquePtr owning the new client.

◆ detect_connected()

template<typename ReqT, typename RespT, SecurityType SecT>
void vlink::Client< ReqT, RespT, SecT >::detect_connected ( ConnectCallback && callback)
inline

Registers a callback invoked when the server connection state changes.

Fires immediately (synchronously) if the server is already connected. Otherwise fires asynchronously when the server first becomes available.

Parameters
callbackvoid(bool)true when connected to a server.

◆ invoke() [1/3]

template<typename ReqT, typename RespT, SecurityType SecT>
bool vlink::Client< ReqT, RespT, SecT >::invoke ( const ReqT & req,
RespCallback && callback )
inline

Sends a request and invokes callback asynchronously on the response.

Only valid when kHasResp is true. The call returns immediately; the callback is invoked on the transport thread (or on the attached MessageLoop thread) when the response arrives.

Parameters
reqRequest value to send.
callbackvoid(const RespT&) invoked with the response.
Returns
true if the request was accepted by the transport; false on error.

◆ invoke() [2/3]

template<typename ReqT, typename RespT, SecurityType SecT>
bool vlink::Client< ReqT, RespT, SecT >::invoke ( const ReqT & req,
RespT & resp,
std::chrono::milliseconds timeout = Timeout::kDefaultInterval )
inlinenodiscard

Sends a request and blocks until the response is received.

Only valid when kHasResp is true (enforced by static_assert). Serialises req, sends it to the server, blocks for up to timeout, and deserialises the response into resp. A timeout of 0 is treated as infinite.

Parameters
reqRequest value to send.
respOutput parameter filled with the deserialised response.
timeoutMaximum wait for the response.
Returns
true if the response was received in time; false otherwise.

◆ invoke() [3/3]

template<typename ReqT, typename RespT, SecurityType SecT>
std::optional< RespT > vlink::Client< ReqT, RespT, SecT >::invoke ( const ReqT & req,
std::chrono::milliseconds timeout = Timeout::kDefaultInterval )
inlinenodiscard

Sends a request and returns the response as std::optional.

Convenience overload that returns std::nullopt on timeout or error instead of requiring an output parameter. Only valid when kHasResp is true. A timeout of 0 is treated as infinite.

Parameters
reqRequest value to send.
timeoutMaximum wait for the response.
Returns
std::optional<RespT>nullopt on timeout/error.

◆ is_connected()

template<typename ReqT, typename RespT, SecurityType SecT>
bool vlink::Client< ReqT, RespT, SecT >::is_connected ( ) const
inlinenodiscard

Returns true if a server is currently available.

Non-blocking poll; reflects the transport's last known server state.

Returns
true when connected to a server.

◆ send()

template<typename ReqT, typename RespT, SecurityType SecT>
bool vlink::Client< ReqT, RespT, SecT >::send ( const ReqT & req)
inline

Sends a fire-and-forget request with no response.

Only valid when RespT == EmptyType (enforced by static_assert). The call returns immediately after the transport has accepted the request; no response is expected or awaited.

Parameters
reqRequest value to send.
Returns
true if the transport accepted the request; false on error.
Here is the call graph for this function:

◆ wait_for_connected()

template<typename ReqT, typename RespT, SecurityType SecT>
bool vlink::Client< ReqT, RespT, SecT >::wait_for_connected ( std::chrono::milliseconds timeout = Timeout::kDefaultInterval)
inline

Blocks until a server is available or the timeout expires.

A timeout of 0 is treated as infinite (a warning is logged). A negative timeout also waits indefinitely. Can be interrupted by interrupt(), which causes this method to return false.

Parameters
timeoutMaximum wait duration. Default: Timeout::kDefaultInterval.
Returns
true if a server appeared; false on timeout or interrupt.

Member Data Documentation

◆ kHasResp

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
bool vlink::Client< ReqT, RespT, SecT >::kHasResp = !std::is_same_v<RespT, Traits::EmptyType>
staticconstexpr

true when RespT is not EmptyType (client expects a response).

◆ kImplType

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
ImplType vlink::Client< ReqT, RespT, SecT >::kImplType = kClient
staticconstexpr

Node role identifier (kClient).

◆ kReqType

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
Serializer::Type vlink::Client< ReqT, RespT, SecT >::kReqType = Serializer::get_type_of<ReqT>()
staticconstexpr

Serializer type for ReqT.

◆ kRespType

template<typename ReqT, typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
Serializer::Type vlink::Client< ReqT, RespT, SecT >::kRespType = Serializer::get_type_of<RespT>()
staticconstexpr

Serializer type for RespT.


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