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

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

#include <client.h>

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

Public 类型

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 成员函数

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.

静态 Public 成员函数

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.

静态 Public 属性

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.

额外继承的成员函数

详细描述

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.

模板参数
ReqTRequest type.
RespTResponse type (defaults to Traits::EmptyType – fire-and-forget).
SecTSecurity mode.

成员类型定义说明

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

构造及析构函数说明

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

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

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

参数
url_strService URL (e.g. "someip://30490/0x1/my_method").
typekWithInit to call init() immediately (default).
函数调用图:

◆ ~Client()

template<typename ReqT, typename RespT, SecurityType SecT>
vlink::Client< ReqT, RespT, SecT >::~Client ( )
inlineoverride
函数调用图:

成员函数说明

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

参数
reqRequest value to send.
返回
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.

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

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

参数
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.

参数
reqRequest value to send.
callbackvoid(const RespT&) invoked with the response.
返回
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.

参数
reqRequest value to send.
respOutput parameter filled with the deserialised response.
timeoutMaximum wait for the response.
返回
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.

参数
reqRequest value to send.
timeoutMaximum wait for the response.
返回
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.

返回
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.

参数
reqRequest value to send.
返回
true if the transport accepted the request; false on error.
函数调用图:

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

参数
timeoutMaximum wait duration. Default: Timeout::kDefaultInterval.
返回
true if a server appeared; false on timeout or interrupt.

类成员变量说明

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


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