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

Type-safe RPC handler for the VLink method communication model. More...

#include <server.h>

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

Public Types

using UniquePtr = std::unique_ptr< Server< ReqT, RespT, SecT > >
 Owning unique-pointer alias. More...
 
using SharedPtr = std::shared_ptr< Server< ReqT, RespT, SecT > >
 Owning shared-pointer alias. More...
 
using ReqCallback = Function< void(const ReqT &)>
 Fire-and-forget handler signature. More...
 
using ReqRespCallback = Function< void(const ReqT &, RespT &)>
 Synchronous fill-response handler. More...
 
using ReqAsyncRespCallback = Function< void(uint64_t, const ReqT &)>
 Handler signature for deferred asynchronous replies. More...
 

Public Member Functions

template<typename ConfT , typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
 Server (const ConfT &conf, InitType type=InitType::kWithInit)
 Constructs a server from a typed transport configuration object. More...
 
 Server (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a server from a URL string. More...
 
bool listen (ReqCallback &&callback)
 Installs a fire-and-forget request handler. More...
 
bool listen (ReqRespCallback &&callback)
 Installs a synchronous request/response handler. More...
 
bool listen_for_reply (ReqAsyncRespCallback &&callback)
 Installs a handler that defers the reply via reply(). More...
 
bool reply (uint64_t req_id, const RespT &resp)
 Emits the asynchronous response for a previously received request. More...
 
template<bool HasPtrT>
bool reply_bytes (uint64_t req_id, const Bytes &resp_data, bool is_sync, [[maybe_unused]] Bytes *resp_data_ptr)
 

Static Public Member Functions

static UniquePtr create_unique (const std::string &url_str, InitType type=InitType::kWithInit)
 Heap-allocates a Server 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 Server and wraps it in a std::shared_ptr. More...
 

Static Public Attributes

static constexpr ImplType kImplType = kServer
 Node role tag (kServer). More...
 
static constexpr bool kHasResp = !std::is_same_v<RespT, Traits::EmptyType>
 true when response produced. 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::Server< ReqT, RespT, SecT >

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

Inherits the full Node API and adds handler-side operations: three listen() variants and the deferred reply() entry point. The transport implementation (ServerImpl) 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 (no response).
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.

Member Typedef Documentation

◆ ReqAsyncRespCallback

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

Handler signature for deferred asynchronous replies.

Receives the opaque req_id assigned by the framework alongside the incoming request. The handler must eventually call reply(req_id, resp) from any thread to deliver the response.

◆ ReqCallback

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

Fire-and-forget handler signature.

◆ ReqRespCallback

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

Synchronous fill-response handler.

◆ SharedPtr

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

Owning shared-pointer alias.

◆ UniquePtr

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

Owning unique-pointer alias.

Constructor & Destructor Documentation

◆ Server() [1/2]

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

Constructs a server from a typed transport configuration object.

Accepts any Conf-derived configuration. A compile-time check enforces that the configuration permits the server role.

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

◆ Server() [2/2]

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

Constructs a server from a URL string.

Parameters
url_strService URL such as "someip://30490/0x1/my_method".
typeWhether to call init() inline; default is InitType::kWithInit.

Member Function Documentation

◆ create_shared()

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

Heap-allocates a Server 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 server.

◆ create_unique()

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

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

Parameters
url_strService URL such as "dds://my_service".
typeWhether to call init() inline; default is InitType::kWithInit.
Returns
Owning UniquePtr to the new server.

◆ listen() [1/2]

template<typename ReqT , typename RespT , SecurityType SecT>
bool vlink::Server< ReqT, RespT, SecT >::listen ( ReqCallback &&  callback)
inline

Installs a fire-and-forget request handler.

Only available when RespT == EmptyType (enforced by static_assert). The handler is invoked for every received request and no response is produced.

Parameters
callbackvoid(const ReqT&) handler.
Returns
true if registration succeeded.

◆ listen() [2/2]

template<typename ReqT , typename RespT , SecurityType SecT>
bool vlink::Server< ReqT, RespT, SecT >::listen ( ReqRespCallback &&  callback)
inline

Installs a synchronous request/response handler.

Only available when kHasResp is true. The handler must populate resp before returning; the framework serialises resp immediately and emits the reply on the underlying transport.

Parameters
callbackvoid(const ReqT&, RespT&) handler that fills resp.
Returns
true if registration succeeded.

◆ listen_for_reply()

template<typename ReqT , typename RespT , SecurityType SecT>
bool vlink::Server< ReqT, RespT, SecT >::listen_for_reply ( ReqAsyncRespCallback &&  callback)
inline

Installs a handler that defers the reply via reply().

Only available when kHasResp is true. The handler receives an opaque req_id and the deserialised request. The handler must eventually invoke reply(req_id, resp) – from any thread – to send the response back to the waiting client.

Parameters
callbackvoid(uint64_t, const ReqT&) handler.
Returns
true if registration succeeded.

◆ reply()

template<typename ReqT , typename RespT , SecurityType SecT>
bool vlink::Server< ReqT, RespT, SecT >::reply ( uint64_t  req_id,
const RespT &  resp 
)
inline

Emits the asynchronous response for a previously received request.

Must be paired with listen_for_reply(); calling reply() after a synchronous listen() triggers a fatal log. The req_id must match the value passed to the async handler. Unknown IDs may be silently rejected by the active transport.

Parameters
req_idOpaque identifier received in the async handler.
respResponse value to serialise and emit.
Returns
true if the transport accepted the response.

◆ reply_bytes()

template<typename ReqT , typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
template<bool HasPtrT>
bool vlink::Server< ReqT, RespT, SecT >::reply_bytes ( uint64_t  req_id,
const Bytes resp_data,
bool  is_sync,
[[maybe_unused] ] Bytes resp_data_ptr 
)
inline

Member Data Documentation

◆ kHasResp

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

true when response produced.

◆ kImplType

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

Node role tag (kServer).

◆ kReqType

template<typename ReqT , typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
constexpr Serializer::Type vlink::Server< 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::Server< 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: