VLink  2.0.0
A high-performance communication middleware
vlink::Subscriber< MsgT, SecT > 模板类 参考

Type-safe topic listener for the VLink event communication model. 更多...

#include <subscriber.h>

类 vlink::Subscriber< MsgT, SecT > 继承关系图:
vlink::Subscriber< MsgT, SecT > 的协作图:

Public 类型

using UniquePtr = std::unique_ptr< Subscriber< MsgT, SecT > >
 Owning unique-pointer alias. 更多...
 
using SharedPtr = std::shared_ptr< Subscriber< MsgT, SecT > >
 Owning shared-pointer alias. 更多...
 
using MsgCallback = Function< void(const MsgT &)>
 User callback signature for received messages. 更多...
 

Public 成员函数

template<typename ConfT , typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
 Subscriber (const ConfT &conf, InitType type=InitType::kWithInit)
 Constructs a subscriber from a typed transport configuration object. 更多...
 
 Subscriber (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a subscriber from a URL string. 更多...
 
bool listen (MsgCallback &&callback)
 Installs the receive callback that runs for every inbound message. 更多...
 
void set_manual_unloan (bool manual_unloan) override
 Enables or disables manual-unloan mode for zero-copy receives. 更多...
 
void set_latency_and_lost_enabled (bool enable)
 Toggles per-message latency and sample-loss measurement. 更多...
 
bool is_latency_and_lost_enabled () const
 Reports whether latency and sample-loss tracking is currently active. 更多...
 
int64_t get_latency () const
 Returns the most recent end-to-end latency measurement. 更多...
 
SampleLostInfo get_lost () const
 Returns cumulative sample-delivery statistics. 更多...
 
void mark_as_getter ()
 Promotes this subscriber to behave as a Getter (field-reader) at the transport layer. 更多...
 

静态 Public 成员函数

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

静态 Public 属性

static constexpr ImplType kImplType = kSubscriber
 Node role tag (kSubscriber). 更多...
 
static constexpr Serializer::Type kMsgType = Serializer::get_type_of<MsgT>()
 Codec resolved from MsgT. 更多...
 

额外继承的成员函数

详细描述

template<typename MsgT, SecurityType SecT = SecurityType::kWithoutSecurity>
class vlink::Subscriber< MsgT, SecT >

Type-safe topic listener for the VLink event communication model.

Inherits the full Node API and adds receive-specific operations: listen() to register the user callback, manual-unloan control for zero-copy back-ends, and latency / sample-loss tracking. The transport implementation (SubscriberImpl) is selected by the URL scheme or by the typed configuration object supplied at construction time.

模板参数
MsgTC++ message type. Must satisfy Serializer::is_supported().
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.

成员类型定义说明

◆ MsgCallback

template<typename MsgT , SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Subscriber< MsgT, SecT >::MsgCallback = Function<void(const MsgT&)>

User callback signature for received messages.

◆ SharedPtr

template<typename MsgT , SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Subscriber< MsgT, SecT >::SharedPtr = std::shared_ptr<Subscriber<MsgT, SecT> >

Owning shared-pointer alias.

◆ UniquePtr

template<typename MsgT , SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Subscriber< MsgT, SecT >::UniquePtr = std::unique_ptr<Subscriber<MsgT, SecT> >

Owning unique-pointer alias.

构造及析构函数说明

◆ Subscriber() [1/2]

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

Constructs a subscriber from a typed transport configuration object.

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

模板参数
ConfTConcrete configuration type derived from Conf.
参数
confPopulated configuration aggregate.
typeWhether to call init() inline; default is InitType::kWithInit.

◆ Subscriber() [2/2]

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

Constructs a subscriber from a URL string.

参数
url_strTopic URL such as "shm://vehicle/speed".
typeWhether to call init() inline; default is InitType::kWithInit.

成员函数说明

◆ create_shared()

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

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

参数
url_strTopic URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
返回
Owning SharedPtr to the new subscriber.

◆ create_unique()

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

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

参数
url_strTopic URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
返回
Owning UniquePtr to the new subscriber.

◆ get_latency()

template<typename MsgT , SecurityType SecT>
int64_t vlink::Subscriber< MsgT, SecT >::get_latency
inline

Returns the most recent end-to-end latency measurement.

Computed as receive-timestamp minus source-timestamp on the last delivered message. Returns 0 when tracking is not enabled.

返回
Latency in nanoseconds; 0 if disabled.

◆ get_lost()

template<typename MsgT , SecurityType SecT>
SampleLostInfo vlink::Subscriber< MsgT, SecT >::get_lost
inline

Returns cumulative sample-delivery statistics.

返回
SampleLostInfo with total expected and total lost counts.

◆ is_latency_and_lost_enabled()

template<typename MsgT , SecurityType SecT>
bool vlink::Subscriber< MsgT, SecT >::is_latency_and_lost_enabled
inline

Reports whether latency and sample-loss tracking is currently active.

返回
true if set_latency_and_lost_enabled(true) was invoked.

◆ listen()

template<typename MsgT , SecurityType SecT>
bool vlink::Subscriber< MsgT, SecT >::listen ( MsgCallback &&  callback)
inline

Installs the receive callback that runs for every inbound message.

The callback is invoked on the transport delivery thread by default; if the subscriber is attach()ed to a MessageLoop the callback is posted onto that loop instead. For intra:// transports carrying an IntraDataType shared pointer the value is forwarded zero-copy and no deserialisation occurs.

警告
The argument reference points at thread_local scratch memory that is reused across invocations. Copy the data before stashing it outside the callback. This restriction does not apply to Bytes or IntraData payloads.
注解
Calling listen() more than once is fatal. The subscriber must be initialised before the first call to listen().
参数
callbackvoid(const MsgT&) invoked for each received message.
返回
true if the callback was installed successfully.

◆ mark_as_getter()

template<typename MsgT , SecurityType SecT>
void vlink::Subscriber< MsgT, SecT >::mark_as_getter
inline

Promotes this subscriber to behave as a Getter (field-reader) at the transport layer.

Switches impl_type from kSubscriber to kGetter so that latest-value delivery semantics are activated. Reinitialises the transport extension if called post-init(). Used internally by Getter.

◆ set_latency_and_lost_enabled()

template<typename MsgT , SecurityType SecT>
void vlink::Subscriber< MsgT, SecT >::set_latency_and_lost_enabled ( bool  enable)
inline

Toggles per-message latency and sample-loss measurement.

参数
enabletrue to begin tracking; false to stop.

◆ set_manual_unloan()

template<typename MsgT , SecurityType SecT>
void vlink::Subscriber< MsgT, SecT >::set_manual_unloan ( bool  manual_unloan)
inlineoverridevirtual

Enables or disables manual-unloan mode for zero-copy receives.

In manual-unloan mode the user must call return_loan() after consuming each delivered buffer. Only relevant on loan-capable transports (shm://, Zenoh with SHM, etc.).

参数
manual_unloantrue to enable manual return; false for auto-return.

重载 vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity > .

类成员变量说明

◆ kImplType

template<typename MsgT , SecurityType SecT = SecurityType::kWithoutSecurity>
constexpr ImplType vlink::Subscriber< MsgT, SecT >::kImplType = kSubscriber
staticconstexpr

Node role tag (kSubscriber).

◆ kMsgType

template<typename MsgT , SecurityType SecT = SecurityType::kWithoutSecurity>
constexpr Serializer::Type vlink::Subscriber< MsgT, SecT >::kMsgType = Serializer::get_type_of<MsgT>()
staticconstexpr

Codec resolved from MsgT.


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