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

Type-safe publisher for the VLink event communication model. More...

#include <publisher.h>

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

Public Types

using UniquePtr = std::unique_ptr<Publisher<MsgT, SecT>>
 Unique-pointer alias for heap allocation.
using SharedPtr = std::shared_ptr<Publisher<MsgT, SecT>>
 Shared-pointer alias for heap allocation.
using ConnectCallback = NodeImpl::ConnectCallback
 Callback type fired when subscriber presence changes.

Public Member Functions

template<typename ConfT, typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
 Publisher (const ConfT &conf, InitType type=InitType::kWithInit)
 Constructs a publisher from a typed transport configuration object.
 Publisher (const std::string &url_str, InitType type=InitType::kWithInit)
 Constructs a publisher from a URL string.
void detect_subscribers (ConnectCallback &&callback)
 Registers a callback invoked when subscriber presence changes.
bool wait_for_subscribers (std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Blocks until at least one subscriber is present or the timeout expires.
bool has_subscribers () const
 Returns true if at least one subscriber is currently present.
bool publish (const MsgT &msg, bool force=false)
 Serialises and publishes msg to all current subscribers.
bool publish_fbb (const void *fbb, bool force=false)
 Publishes a pre-finished FlatBufferBuilder buffer directly.
void mark_as_setter ()
 Changes this publisher's role to kSetter (field-writer).

Static Public Member Functions

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

Static Public Attributes

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

Additional Inherited Members

Detailed Description

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

Type-safe publisher for the VLink event communication model.

Template Parameters
MsgTMessage type.
SecTSecurity mode.

Member Typedef Documentation

◆ ConnectCallback

template<typename MsgT, SecurityType SecT = SecurityType::kWithoutSecurity>
using vlink::Publisher< MsgT, SecT >::ConnectCallback = NodeImpl::ConnectCallback

Callback type fired when subscriber presence changes.

◆ SharedPtr

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

Shared-pointer alias for heap allocation.

◆ UniquePtr

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

Unique-pointer alias for heap allocation.

Constructor & Destructor Documentation

◆ Publisher() [1/2]

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

Constructs a publisher from a typed transport configuration object.

Accepts any Conf-derived configuration (e.g. DdsConf, ShmConf). A compile-time static_assert checks that the Conf supports the publisher role. Parses and validates the conf; logs a fatal error if the conf is invalid or if the transport factory returns nullptr.

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:

◆ Publisher() [2/2]

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

Constructs a publisher from a URL string.

The transport prefix in the URL selects the transport back-end automatically (e.g. "shm://" => Iceoryx, "dds://" => FastDDS). Internally wraps the string in a Url object and delegates to the ConfT constructor.

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

Member Function Documentation

◆ create_shared()

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

Creates a Publisher on the heap wrapped in a shared_ptr.

Parameters
url_strTopic URL string.
typekWithInit to call init() immediately (default).
Returns
SharedPtr owning the new publisher instance.

◆ create_unique()

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

Creates a Publisher on the heap wrapped in a unique_ptr.

Parameters
url_strTopic URL string (e.g. "dds://vehicle/speed").
typekWithInit to call init() immediately (default).
Returns
UniquePtr owning the new publisher instance.

◆ detect_subscribers()

template<typename MsgT, SecurityType SecT>
void vlink::Publisher< MsgT, SecT >::detect_subscribers ( ConnectCallback && callback)
inline

Registers a callback invoked when subscriber presence changes.

Fires immediately (synchronously) if a subscriber is already present at registration time. Otherwise fires asynchronously the first time a subscriber appears. The callback receives true when at least one subscriber is present and false when the last subscriber disconnects.

Parameters
callbackvoid(bool) callable – true = subscriber(s) present.

◆ has_subscribers()

template<typename MsgT, SecurityType SecT>
bool vlink::Publisher< MsgT, SecT >::has_subscribers ( ) const
inlinenodiscard

Returns true if at least one subscriber is currently present.

Non-blocking poll; reflects the transport's last known peer state.

Returns
true when one or more subscribers are known to exist.

◆ mark_as_setter()

template<typename MsgT, SecurityType SecT>
void vlink::Publisher< MsgT, SecT >::mark_as_setter ( )
inline

Changes this publisher's role to kSetter (field-writer).

Updates impl_->impl_type from kPublisher to kSetter so that transport-specific field semantics are applied (e.g. last-value retention for late-joining getters). If called after init() the extension is automatically reinitialised. Used internally by Setter.

◆ publish()

template<typename MsgT, SecurityType SecT>
bool vlink::Publisher< MsgT, SecT >::publish ( const MsgT & msg,
bool force = false )
inline

Serialises and publishes msg to all current subscribers.

Serialization is performed according to kMsgType. On loan-capable transports (e.g. shm://) the output buffer is a loaned segment to avoid an extra copy. Loaned buffers are not used when security is enabled (kWithSecurity) because the encrypted payload size differs from the serialized size.

By default (force = false) the call is a no-op when no subscribers are present; pass true to force-write regardless (useful for field-mode or recording-only scenarios).

For intra:// with a message type whose element_type derives from IntraDataType (generated via VLINK_INTRA_DATA_DECLARE), the pointer is forwarded zero-copy and no serialization occurs.

Parameters
msgMessage value to publish.
forcetrue to publish even with no subscribers.
Returns
true if the transport accepted the message; false on error.

◆ publish_fbb()

template<typename MsgT, SecurityType SecT>
bool vlink::Publisher< MsgT, SecT >::publish_fbb ( const void * fbb,
bool force = false )

Publishes a pre-finished FlatBufferBuilder buffer directly.

Accepts a pointer to a flatbuffers::FlatBufferBuilder whose Finish() has already been called. The raw bytes are shallow-copied and sent without re-serialisation. Useful in pipeline scenarios where the FlatBuffers object is constructed externally.

Parameters
fbbPointer to a finished flatbuffers::FlatBufferBuilder.
forcetrue to publish even with no subscribers.
Returns
true on success; false on error.

◆ wait_for_subscribers()

template<typename MsgT, SecurityType SecT>
bool vlink::Publisher< MsgT, SecT >::wait_for_subscribers ( std::chrono::milliseconds timeout = Timeout::kDefaultInterval)
inline

Blocks until at least one subscriber is present 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 calling interrupt(), which causes this method to return false.

Parameters
timeoutMaximum wait duration. Default: Timeout::kDefaultInterval.
Returns
true if a subscriber appeared; false on timeout or interrupt.

Member Data Documentation

◆ kImplType

template<typename MsgT, SecurityType SecT = SecurityType::kWithoutSecurity>
ImplType vlink::Publisher< MsgT, SecT >::kImplType = kPublisher
staticconstexpr

Node role identifier (kPublisher).

◆ kMsgType

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

Serializer type resolved at compile time from MsgT.


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