VLink  2.0.0
A high-performance communication middleware
vlink::Subscriber< MsgT, SecT > Class Template Reference

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

#include <subscriber.h>

Inheritance diagram for vlink::Subscriber< MsgT, SecT >:
Collaboration diagram for vlink::Subscriber< MsgT, SecT >:

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

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

Additional Inherited Members

Detailed Description

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.

Template Parameters
MsgTC++ message type. Must satisfy Serializer::is_supported().
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.

Member Typedef Documentation

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

Constructor & Destructor Documentation

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

Template Parameters
ConfTConcrete configuration type derived from Conf.
Parameters
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.

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

Member Function Documentation

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

Parameters
url_strTopic URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
Returns
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.

Parameters
url_strTopic URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
Returns
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.

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

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

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

Warning
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.
Note
Calling listen() more than once is fatal. The subscriber must be initialised before the first call to listen().
Parameters
callbackvoid(const MsgT&) invoked for each received message.
Returns
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.

Parameters
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.).

Parameters
manual_unloantrue to enable manual return; false for auto-return.

Reimplemented from vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity >.

Member Data Documentation

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


The documentation for this class was generated from the following files: