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

Type-safe RPC caller for the VLink method 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 > >
 Owning unique-pointer alias. More...
 
using SharedPtr = std::shared_ptr< Client< ReqT, RespT, SecT > >
 Owning shared-pointer alias. More...
 
using ConnectCallback = NodeImpl::ConnectCallback
 Callback type for server presence transitions. More...
 
using RespCallback = Function< void(const RespT &)>
 Callback signature for asynchronous responses. More...
 

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. More...
 
 Client (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a client from a URL string. More...
 
 ~Client () override
 Destroys the client and tears down outstanding promises. More...
 
void detect_connected (ConnectCallback &&callback)
 Registers a callback invoked when the server-presence state changes. More...
 
bool wait_for_connected (std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Blocks until a server is discovered or timeout expires. More...
 
bool is_connected () const
 Non-blocking query of server presence. More...
 
bool invoke (const ReqT &req, RespT &resp, std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Synchronous request/response invocation with an output parameter. More...
 
std::optional< RespT > invoke (const ReqT &req, std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Synchronous request/response invocation returning a std::optional. More...
 
bool invoke (const ReqT &req, RespCallback &&callback)
 Asynchronous callback-based invocation. More...
 
std::future< RespT > async_invoke (const ReqT &req)
 Asynchronous future-based invocation. More...
 
bool send (const ReqT &req)
 Fire-and-forget request emission. More...
 

Static Public Member Functions

static UniquePtr create_unique (const std::string &url_str, InitType type=InitType::kWithInit)
 Heap-allocates a Client and wraps it in a std::unique_ptr. More...
 
static SharedPtr create_shared (const std::string &url_str, InitType type=InitType::kWithInit)
 Heap-allocates a Client and wraps it in a std::shared_ptr. More...
 

Static Public Attributes

static constexpr ImplType kImplType = kClient
 Node role tag (kClient). More...
 
static constexpr bool kHasResp = !std::is_same_v<RespT, Traits::EmptyType>
 true when response expected. More...
 
static constexpr Serializer::Type kReqType = Serializer::get_type_of<ReqT>()
 Codec for the request. More...
 
static constexpr Serializer::Type kRespType = Serializer::get_type_of<RespT>()
 Codec for the response. More...
 

Additional Inherited Members

Detailed Description

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

Type-safe RPC caller for the VLink method communication model.

Inherits the full Node API and adds method-specific operations: connection detection, blocking and non-blocking invocation, future-based async invocation, and fire-and-forget send(). The transport implementation (ClientImpl) is selected by the URL scheme or by the typed configuration object supplied at construction time.

Template Parameters
ReqTRequest message type. Must satisfy Serializer::is_supported().
RespTResponse message type. Defaults to Traits::EmptyType for fire-and-forget.
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.

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 for server presence transitions.

◆ RespCallback

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

Callback signature for asynchronous responses.

◆ 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> >

Owning 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> >

Owning 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 check enforces that the configuration permits the client role.

Template Parameters
ConfTConcrete configuration type derived from Conf.
Parameters
confPopulated configuration aggregate.
typeWhether to call init() inline; default is InitType::kWithInit.

◆ 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 such as "someip://30490/0x1/my_method".
typeWhether to call init() inline; default is InitType::kWithInit.

◆ ~Client()

template<typename ReqT , typename RespT , SecurityType SecT>
vlink::Client< ReqT, RespT, SecT >::~Client
inlineoverride

Destroys the client and tears down outstanding promises.

Required to drain any in-flight async_invoke() promises before this object's locks and maps are destroyed.

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)
inline

Asynchronous future-based invocation.

Returns a std::future that is set when the response arrives. On serialisation, transport, or deserialisation failure the future's exception state is populated with Exception::RuntimeError. Only available when kHasResp is true.

Parameters
reqRequest value.
Returns
std::future<RespT> resolved when the response is delivered.

◆ 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 
)
inlinestatic

Heap-allocates a Client and wraps it in a std::shared_ptr.

Parameters
url_strService URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
Returns
Owning SharedPtr to 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 
)
inlinestatic

Heap-allocates a Client and wraps it in a std::unique_ptr.

Parameters
url_strService URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
Returns
Owning UniquePtr to 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-presence state changes.

Fires synchronously immediately if a server is already discovered at registration; otherwise fires asynchronously the first time a matching server appears, and again on disconnection.

Parameters
callbackvoid(bool) callable – true means connected.

◆ invoke() [1/3]

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

Asynchronous callback-based invocation.

Only available when kHasResp is true. The method returns immediately; callback runs on the transport delivery thread or on the attached MessageLoop thread when the response arrives.

Parameters
reqRequest value.
callbackvoid(const RespT&) invoked once the response arrives.
Returns
true if the transport accepted the request.

◆ 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 
)
inline

Synchronous request/response invocation with an output parameter.

Only available when kHasResp is true. Serialises req, blocks for up to timeout, and deserialises the reply into resp. A timeout of 0 is treated as infinite.

Parameters
reqRequest value.
respOutput parameter receiving the deserialised response.
timeoutMaximum wait for the response.
Returns
true if the response was received in time.

◆ 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 
)
inline

Synchronous request/response invocation returning a std::optional.

Convenience wrapper that returns std::nullopt on timeout, transport failure, or codec failure. Only available when kHasResp is true.

Parameters
reqRequest value.
timeoutMaximum wait for the response.
Returns
std::optional<RespT>; empty on failure.

◆ is_connected()

template<typename ReqT , typename RespT , SecurityType SecT>
bool vlink::Client< ReqT, RespT, SecT >::is_connected
inline

Non-blocking query of server presence.

Returns
true when the transport currently has a matching server.

◆ send()

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

Fire-and-forget request emission.

Only available when RespT == EmptyType. Serialises req and passes it to the transport without waiting for or expecting a reply.

Parameters
reqRequest value.
Returns
true if the transport accepted the request.
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 discovered or timeout expires.

A timeout of 0 is treated as infinite (with a warning). A negative value also waits indefinitely. interrupt() causes the wait to abort and 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>
constexpr bool vlink::Client< ReqT, RespT, SecT >::kHasResp = !std::is_same_v<RespT, Traits::EmptyType>
staticconstexpr

true when response expected.

◆ kImplType

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

Node role tag (kClient).

◆ kReqType

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

Codec for the request.

◆ kRespType

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

Codec for the response.


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