VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::Getter< ValueT, SecT > Class Template Reference

Type-safe field reader for the VLink field communication model. More...

#include <getter.h>

Inheritance diagram for vlink::Getter< ValueT, SecT >:
Collaboration diagram for vlink::Getter< ValueT, SecT >:

Public Types

using UniquePtr = std::unique_ptr<Getter<ValueT, SecT>>
 Unique-pointer alias.
using SharedPtr = std::shared_ptr<Getter<ValueT, SecT>>
 Shared-pointer alias.
using MsgCallback = std::function<void(const ValueT&)>
 User-facing callback type for value-change notifications.

Public Member Functions

template<typename ConfT, typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
 Getter (const ConfT &conf, InitType type=InitType::kWithInit)
 Constructs a getter from a typed transport configuration object.
 Getter (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a getter from a URL string.
std::optional< ValueT > get () const
 Returns the latest cached value, if one has been received.
bool wait_for_value (std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Blocks until a value is received or the timeout expires.
bool listen (MsgCallback &&callback)
 Registers a callback invoked whenever a new value arrives.
void set_change_reporting (bool enable)
 Enables or disables change-reporting (suppress duplicate values).
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-value 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 value latency.
SampleLostInfo get_lost () const
 Returns cumulative sample delivery statistics.
bool get_change_reporting () const
 Returns true if change-reporting mode is currently active.
bool init () override
 Initialises the getter and registers the internal delivery callback.
void interrupt () override
 Interrupts any blocking wait_for_value() call.
void mark_as_subscriber ()
 Changes this getter's role to kSubscriber (event-receiver).

Static Public Member Functions

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

Static Public Attributes

static constexpr ImplType kImplType = kGetter
 Node role identifier (kGetter).
static constexpr Serializer::Type kValueType = Serializer::get_type_of<ValueT>()
 Serializer type resolved at compile time from ValueT.

Additional Inherited Members

Detailed Description

template<typename ValueT, SecurityType SecT = SecurityType::kWithoutSecurity>
class vlink::Getter< ValueT, SecT >

Type-safe field reader for the VLink field communication model.

Template Parameters
ValueTValue type to read.
SecTSecurity mode.

Member Typedef Documentation

◆ MsgCallback

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

User-facing callback type for value-change notifications.

◆ SharedPtr

template<typename ValueT, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Getter< ValueT, SecT >::SharedPtr = std::shared_ptr<Getter<ValueT, SecT>>

Shared-pointer alias.

◆ UniquePtr

template<typename ValueT, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Getter< ValueT, SecT >::UniquePtr = std::unique_ptr<Getter<ValueT, SecT>>

Unique-pointer alias.

Constructor & Destructor Documentation

◆ Getter() [1/2]

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

Constructs a getter from a typed transport configuration object.

Template Parameters
ConfTConf-derived configuration type.
Parameters
confPopulated configuration object.
typekWithInit to call init() immediately (default).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Getter() [2/2]

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

Constructs a getter from a URL string.

Parameters
url_strField URL (e.g. "shm://vehicle/gear").
typekWithInit to call init() immediately (default).
Here is the call graph for this function:

Member Function Documentation

◆ create_shared()

template<typename ValueT, SecurityType SecT>
Getter< ValueT, SecT >::SharedPtr vlink::Getter< ValueT, SecT >::create_shared ( const std::string & url_str,
InitType type = InitType::kWithInit )
inlinestaticnodiscard

Creates a Getter on the heap wrapped in a shared_ptr.

Parameters
url_strField URL string.
typekWithInit to call init() immediately (default).
Returns
SharedPtr owning the new getter.

◆ create_unique()

template<typename ValueT, SecurityType SecT>
Getter< ValueT, SecT >::UniquePtr vlink::Getter< ValueT, SecT >::create_unique ( const std::string & url_str,
InitType type = InitType::kWithInit )
inlinestaticnodiscard

Creates a Getter on the heap wrapped in a unique_ptr.

Parameters
url_strField URL string (e.g. "shm://vehicle/gear").
typekWithInit to call init() immediately (default).
Returns
UniquePtr owning the new getter.

◆ get()

template<typename ValueT, SecurityType SecT>
std::optional< ValueT > vlink::Getter< ValueT, SecT >::get ( ) const
inlinenodiscard

Returns the latest cached value, if one has been received.

Thread-safe. Returns std::nullopt if no Setter has written a value yet since this getter was initialised.

Returns
std::optional<ValueT> – holds the latest value, or empty.

◆ get_change_reporting()

template<typename ValueT, SecurityType SecT>
bool vlink::Getter< ValueT, SecT >::get_change_reporting ( ) const
inlinenodiscard

Returns true if change-reporting mode is currently active.

Returns
true if duplicate suppression is enabled.

◆ get_latency()

template<typename ValueT, SecurityType SecT>
int64_t vlink::Getter< ValueT, SecT >::get_latency ( ) const
inlinenodiscard

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

Returns
Latency in microseconds; 0 if tracking is disabled.

◆ get_lost()

template<typename ValueT, SecurityType SecT>
SampleLostInfo vlink::Getter< ValueT, SecT >::get_lost ( ) const
inlinenodiscard

Returns cumulative sample delivery statistics.

Returns
SampleLostInfo with total expected and lost value counts.

◆ init()

template<typename ValueT, SecurityType SecT>
bool vlink::Getter< ValueT, SecT >::init ( )
inlineoverridevirtual

Initialises the getter and registers the internal delivery callback.

Overrides Node::init() to also set up the internal listen_bytes() callback that receives raw bytes, deserialises them into ValueT, stores the result in value_, and fires the user listen() callback.

Returns
true on success; false if already initialised.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interrupt()

template<typename ValueT, SecurityType SecT>
void vlink::Getter< ValueT, SecT >::interrupt ( )
inlineoverridevirtual

Interrupts any blocking wait_for_value() call.

Overrides Node::interrupt() to additionally notify the getter's own condition variable, causing wait_for_value() to return false.

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

Here is the call graph for this function:

◆ is_latency_and_lost_enabled()

template<typename ValueT, SecurityType SecT>
bool vlink::Getter< ValueT, SecT >::is_latency_and_lost_enabled ( ) const
inlinenodiscard

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

Returns
true if set_latency_and_lost_enabled(true) was called.

◆ listen()

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

Registers a callback invoked whenever a new value arrives.

The callback receives a pre-deserialized ValueT reference. It is invoked on every setter write unless set_change_reporting(true) is active, in which case duplicate values (same raw bytes as the last) are suppressed before the callback is called.

Internally, Getter also maintains value_ and notifies wait_for_value(). The listen callback is stored once; calling listen() more than once is a fatal error.

Parameters
callbackvoid(const ValueT&) invoked on each new value.
Returns
true always (registration is deferred to init()).

◆ mark_as_subscriber()

template<typename ValueT, SecurityType SecT>
void vlink::Getter< ValueT, SecT >::mark_as_subscriber ( )
inline

Changes this getter's role to kSubscriber (event-receiver).

Updates impl_->impl_type from kGetter to kSubscriber so that transport-specific event semantics are applied. If called after init(), the extension is automatically reinitialised. Used internally when routing a Getter through an event-capable transport.

◆ set_change_reporting()

template<typename ValueT, SecurityType SecT>
void vlink::Getter< ValueT, SecT >::set_change_reporting ( bool enable)
inline

Enables or disables change-reporting (suppress duplicate values).

When true, incoming values whose raw serialized bytes are identical to the previous delivery are silently dropped – neither the callback nor wait_for_value() is notified. Useful for reducing CPU load when a Setter writes the same value repeatedly.

Parameters
enabletrue to enable change-only reporting; false to disable.

◆ set_latency_and_lost_enabled()

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

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

Parameters
enabletrue to start tracking; false to stop.

◆ set_manual_unloan()

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

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

Parameters
manual_unloantrue to enable; false for automatic (default).

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

◆ wait_for_value()

template<typename ValueT, SecurityType SecT>
bool vlink::Getter< ValueT, SecT >::wait_for_value ( std::chrono::milliseconds timeout = Timeout::kDefaultInterval)
inline

Blocks until a value is received or the timeout expires.

Returns immediately if a value is already available. A timeout of 0 is treated as infinite (a warning is logged). Can be interrupted by interrupt(), which causes this method to return false.

After returning true, call get() to retrieve the value.

Parameters
timeoutMaximum wait duration. Default: Timeout::kDefaultInterval.
Returns
true if a value was received; false on timeout or interrupt.

Member Data Documentation

◆ kImplType

template<typename ValueT, SecurityType SecT = SecurityType::kWithoutSecurity>
ImplType vlink::Getter< ValueT, SecT >::kImplType = kGetter
staticconstexpr

Node role identifier (kGetter).

◆ kValueType

template<typename ValueT, SecurityType SecT = SecurityType::kWithoutSecurity>
Serializer::Type vlink::Getter< ValueT, SecT >::kValueType = Serializer::get_type_of<ValueT>()
staticconstexpr

Serializer type resolved at compile time from ValueT.


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