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

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

#include <publisher.h>

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

Public 类型

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 成员函数

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

静态 Public 成员函数

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.

静态 Public 属性

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.

额外继承的成员函数

详细描述

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

Type-safe publisher for the VLink event communication model.

模板参数
MsgTMessage type.
SecTSecurity mode.

成员类型定义说明

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

构造及析构函数说明

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

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

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

参数
url_strTopic URL (e.g. "shm://vehicle/speed").
typekWithInit to call init() immediately (default).
函数调用图:

成员函数说明

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

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

参数
url_strTopic URL string (e.g. "dds://vehicle/speed").
typekWithInit to call init() immediately (default).
返回
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.

参数
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.

返回
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.

参数
msgMessage value to publish.
forcetrue to publish even with no subscribers.
返回
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.

参数
fbbPointer to a finished flatbuffers::FlatBufferBuilder.
forcetrue to publish even with no subscribers.
返回
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.

参数
timeoutMaximum wait duration. Default: Timeout::kDefaultInterval.
返回
true if a subscriber appeared; false on timeout or interrupt.

类成员变量说明

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


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