VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::Server< ReqT, RespT, SecT > 模板类 参考

Type-safe server for the VLink method (RPC) 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>>
 Unique-pointer alias.
using SharedPtr = std::shared_ptr<Server<ReqT, RespT, SecT>>
 Shared-pointer alias.
using ReqCallback = std::function<void(const ReqT&)>
 Fire-and-forget callback – no response (RespT must be EmptyType).
using ReqRespCallback = std::function<void(const ReqT&, RespT&)>
 Synchronous callback – response filled in-place inside the callback.
using ReqAsyncRespCallback = std::function<void(uint64_t, const ReqT&)>
 Asynchronous callback – response sent later via reply(req_id, resp).

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)
 Registers a fire-and-forget request callback (no response).
bool listen (ReqRespCallback &&callback)
 Registers a synchronous request/response callback.
bool listen_for_reply (ReqAsyncRespCallback &&callback)
 Registers an asynchronous request callback (reply sent later).
bool reply (uint64_t req_id, const RespT &resp)
 Sends an asynchronous response for a previously received request.

静态 Public 成员函数

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

静态 Public 属性

static constexpr ImplType kImplType = kServer
 Node role identifier (kServer).
static constexpr bool kHasResp = !std::is_same_v<RespT, Traits::EmptyType>
 true when RespT is not EmptyType (server has 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.

额外继承的成员函数

详细描述

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

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

模板参数
ReqTRequest type.
RespTResponse type (defaults to Traits::EmptyType – no response).
SecTSecurity mode.

成员类型定义说明

◆ ReqAsyncRespCallback

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

Asynchronous callback – response sent later via reply(req_id, resp).

The first parameter is the opaque request ID that must be passed to reply() to deliver the response to the waiting client.

◆ ReqCallback

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

Fire-and-forget callback – no response (RespT must be EmptyType).

◆ ReqRespCallback

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

Synchronous callback – response filled in-place inside the callback.

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

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

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 static_assert verifies the configuration supports the server role.

模板参数
ConfTConf-derived configuration type.
参数
confPopulated configuration object.
typekWithInit to call init() immediately (default).
函数调用图:
这是这个函数的调用关系图:

◆ 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 (e.g. "someip://30490/0x1/my_method").
typekWithInit to call init() immediately (default).
函数调用图:

成员函数说明

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

Creates a Server on the heap wrapped in a shared_ptr.

参数
url_strService URL string.
typekWithInit to call init() immediately (default).
返回
SharedPtr owning 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 )
inlinestaticnodiscard

Creates a Server on the heap wrapped in a unique_ptr.

参数
url_strService URL string (e.g. "dds://my_service").
typekWithInit to call init() immediately (default).
返回
UniquePtr owning the new server.

◆ listen() [1/2]

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

Registers a fire-and-forget request callback (no response).

Only valid when RespT == EmptyType (enforced by static_assert). The callback is invoked for every incoming request; no reply is sent. Calling listen() more than once is a fatal error.

参数
callbackvoid(const ReqT&) invoked for each request.
返回
true if registration succeeded; false on error.
函数调用图:

◆ listen() [2/2]

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

Registers a synchronous request/response callback.

Only valid when kHasResp is true (enforced by static_assert). The callback must fill resp before returning. The framework serialises and sends the response immediately after the callback returns.

参数
callbackvoid(const ReqT&, RespT&) – fills resp in-place.
返回
true if registration succeeded; false on error.

◆ listen_for_reply()

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

Registers an asynchronous request callback (reply sent later).

Only valid when kHasResp is true (enforced by static_assert). The callback receives an opaque req_id. The handler must eventually call reply(req_id, resp) from any thread to send the response.

参数
callbackvoid(uint64_t req_id, const ReqT&) – stores req_id for later.
返回
true if registration succeeded; false on error.
函数调用图:

◆ reply()

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

Sends an asynchronous response for a previously received request.

Must only be called after listen_for_reply() (calling after a synchronous listen() triggers a fatal log). The req_id must match the value passed to the async callback; an unrecognised ID is silently ignored by the transport.

参数
req_idOpaque request identifier received in the async callback.
respResponse value to serialise and send back to the client.
返回
true if the transport accepted the response; false on error.

类成员变量说明

◆ kHasResp

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

true when RespT is not EmptyType (server has a response).

◆ kImplType

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

Node role identifier (kServer).

◆ kReqType

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

Serializer type for RespT.


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