VLink  2.0.0
A high-performance communication middleware
vlink::Server< ReqT, RespT, SecT > 模板类 参考

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

#include <server.h>

类 vlink::Server< ReqT, RespT, SecT > 继承关系图:
vlink::Server< ReqT, RespT, SecT > 的协作图:

Public 类型

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

Public 成员函数

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. 更多...
 
 Server (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a server from a URL string. 更多...
 
bool listen (ReqCallback &&callback)
 Installs a fire-and-forget request handler. 更多...
 
bool listen (ReqRespCallback &&callback)
 Installs a synchronous request/response handler. 更多...
 
bool listen_for_reply (ReqAsyncRespCallback &&callback)
 Installs a handler that defers the reply via reply(). 更多...
 
bool reply (uint64_t req_id, const RespT &resp)
 Emits the asynchronous response for a previously received request. 更多...
 
template<bool HasPtrT>
bool reply_bytes (uint64_t req_id, const Bytes &resp_data, bool is_sync, [[maybe_unused]] Bytes *resp_data_ptr)
 

静态 Public 成员函数

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. 更多...
 
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. 更多...
 

静态 Public 属性

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

额外继承的成员函数

详细描述

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.

模板参数
ReqTRequest message type. Must satisfy Serializer::is_supported().
RespTResponse message type. Defaults to Traits::EmptyType (no response).
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.

成员类型定义说明

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

构造及析构函数说明

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

模板参数
ConfTConcrete configuration type derived from Conf.
参数
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.

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

成员函数说明

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

参数
url_strService URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
返回
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.

参数
url_strService URL such as "dds://my_service".
typeWhether to call init() inline; default is InitType::kWithInit.
返回
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.

参数
callbackvoid(const ReqT&) handler.
返回
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.

参数
callbackvoid(const ReqT&, RespT&) handler that fills resp.
返回
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.

参数
callbackvoid(uint64_t, const ReqT&) handler.
返回
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.

参数
req_idOpaque identifier received in the async handler.
respResponse value to serialise and emit.
返回
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

类成员变量说明

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


该类的文档由以下文件生成: