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

Type-safe subscriber 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>>
 Unique-pointer alias for heap allocation.
using SharedPtr = std::shared_ptr<Subscriber<MsgT, SecT>>
 Shared-pointer alias for heap allocation.
using MsgCallback = std::function<void(const MsgT&)>
 User-facing callback type 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)
 Registers the receive callback for incoming messages.
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)
 Enables or disables per-message latency and sample-loss tracking.
bool is_latency_and_lost_enabled () const
 Returns true if latency and sample-loss tracking is active.
int64_t get_latency () const
 Returns the most recently measured end-to-end message latency.
SampleLostInfo get_lost () const
 Returns cumulative sample delivery statistics.
void mark_as_getter ()
 Changes this subscriber's role to kGetter (field-reader).

静态 Public 成员函数

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

静态 Public 属性

static constexpr ImplType kImplType = kSubscriber
 Node role identifier (kSubscriber).
static constexpr Serializer::Type kMsgType = Serializer::get_type_of<MsgT>()
 Serializer type resolved at compile time from MsgT.

额外继承的成员函数

详细描述

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

Type-safe subscriber for the VLink event communication model.

模板参数
MsgTMessage type.
SecTSecurity mode.

成员类型定义说明

◆ MsgCallback

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

User-facing callback type for received messages.

◆ SharedPtr

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

Shared-pointer alias for heap allocation.

◆ UniquePtr

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

Unique-pointer alias for heap allocation.

构造及析构函数说明

◆ 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 (e.g. DdsConf, ShmConf). A compile-time static_assert verifies the configuration supports the subscriber role.

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

◆ 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 (e.g. "shm://vehicle/speed").
typekWithInit to call init() immediately (default).
函数调用图:

成员函数说明

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

Creates a Subscriber on the heap wrapped in a shared_ptr.

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

Creates a Subscriber on the heap wrapped in a unique_ptr.

参数
url_strTopic URL string (e.g. "dds://vehicle/speed").
typekWithInit to call init() immediately (default).
返回
UniquePtr owning the new subscriber.

◆ get_latency()

template<typename MsgT, SecurityType SecT>
int64_t vlink::Subscriber< MsgT, SecT >::get_latency ( ) const
inlinenodiscard

Returns the most recently measured end-to-end message latency.

Only meaningful when tracking is enabled. Measured from publication timestamp to receive timestamp.

返回
Latency in microseconds; 0 if tracking is disabled.

◆ get_lost()

template<typename MsgT, SecurityType SecT>
SampleLostInfo vlink::Subscriber< MsgT, SecT >::get_lost ( ) const
inlinenodiscard

Returns cumulative sample delivery statistics.

Only meaningful when tracking is enabled.

返回
SampleLostInfo with total expected and lost sample counts.

◆ is_latency_and_lost_enabled()

template<typename MsgT, SecurityType SecT>
bool vlink::Subscriber< MsgT, SecT >::is_latency_and_lost_enabled ( ) const
inlinenodiscard

Returns true if latency and sample-loss tracking is active.

返回
true if set_latency_and_lost_enabled(true) was called.

◆ listen()

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

Registers the receive callback for incoming messages.

The callback is invoked on every delivery, already deserialized into MsgT. For intra:// with an IntraDataType-derived shared pointer type (generated via VLINK_INTRA_DATA_DECLARE) the pointer is forwarded zero-copy. The callback runs on the transport thread unless the node is attach()ed to a MessageLoop.

Calling listen() more than once is a fatal error.

警告
The deserialized message object is thread_local and reused across invocations. Do not store references or pointers to the callback argument beyond the callback scope; copy the data if you need to retain it. This does not apply to Bytes or IntraData message types, which are passed by value/shared pointer.
注解
The subscriber must be initialised (either via kWithInit in the constructor or by calling init() explicitly) before listen() is called. Calling listen() on an uninitialised subscriber triggers a fatal error.
参数
callbackvoid(const MsgT&) invoked for each received message.
返回
true if registered successfully; false on error.
函数调用图:

◆ mark_as_getter()

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

Changes this subscriber's role to kGetter (field-reader).

Updates impl_->impl_type from kSubscriber to kGetter so that transport-specific field semantics (latest-value delivery) are applied. If called after init(), the extension is automatically reinitialised. 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

Enables or disables per-message latency and sample-loss tracking.

参数
enabletrue to start 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.

When enabled, the user must call return_loan() after consuming a received loaned buffer. Only meaningful on loan-capable transports (e.g. shm://).

参数
manual_unloantrue to enable; false for automatic (default).

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

类成员变量说明

◆ kImplType

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

Node role identifier (kSubscriber).

◆ kMsgType

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

Serializer type resolved at compile time from MsgT.


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