VLink  2.0.0
A high-performance communication middleware
vlink::Publisher< MsgT, SecT > 模板类 参考

Type-safe topic emitter 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 > >
 Owning unique-pointer alias. 更多...
 
using SharedPtr = std::shared_ptr< Publisher< MsgT, SecT > >
 Owning shared-pointer alias. 更多...
 
using ConnectCallback = NodeImpl::ConnectCallback
 Callback type for subscriber presence transitions. 更多...
 

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 whenever subscriber presence transitions. 更多...
 
bool wait_for_subscribers (std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
 Blocks until at least one subscriber is detected or timeout expires. 更多...
 
bool has_subscribers () const
 Non-blocking query of subscriber presence. 更多...
 
bool publish (const MsgT &msg, bool force=false)
 Serialises and emits msg to every connected subscriber. 更多...
 
bool publish_fbb (const void *fbb, bool force=false)
 Publishes the raw payload of a pre-finished flatbuffers::FlatBufferBuilder. 更多...
 
void mark_as_setter ()
 Promotes this publisher to behave as a Setter (field-writer) at the transport layer. 更多...
 

静态 Public 成员函数

static UniquePtr create_unique (const std::string &url_str, InitType type=InitType::kWithInit)
 Heap-allocates a Publisher and wraps it in a std::unique_ptr. 更多...
 
static SharedPtr create_shared (const std::string &url_str, InitType type=InitType::kWithInit)
 Heap-allocates a Publisher and wraps it in a std::shared_ptr. 更多...
 

静态 Public 属性

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

额外继承的成员函数

详细描述

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

Type-safe topic emitter for the VLink event communication model.

Inherits the full Node API (lifecycle, loans, properties, profiler) and adds publish-specific operations: subscriber detection, blocking wait, and the publish() entry point itself. The transport implementation (PublisherImpl) is selected by the URL scheme or by the typed configuration object supplied at construction time.

模板参数
MsgTC++ message type. Must satisfy Serializer::is_supported().
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.

成员类型定义说明

◆ ConnectCallback

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

Callback type for subscriber presence transitions.

◆ SharedPtr

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

Owning shared-pointer alias.

◆ UniquePtr

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

Owning unique-pointer alias.

构造及析构函数说明

◆ 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 (DdsConf, ShmConf, ZenohConf, etc.). A compile-time check enforces that the chosen configuration permits the publisher role. Invalid configuration or a nullptr factory result triggers a fatal log.

模板参数
ConfTConcrete configuration type derived from Conf.
参数
confPopulated configuration aggregate.
typeWhether to call init() inline; default is InitType::kWithInit.

◆ 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 URL scheme selects the transport (e.g. "shm://" maps to the Iceoryx back-end, "dds://" maps to FastDDS). Internally the string is parsed into a Url and dispatched to the matching ConfT.

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

成员函数说明

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

Heap-allocates a Publisher and wraps it in a std::shared_ptr.

参数
url_strTopic URL string.
typeWhether to call init() inline; default is InitType::kWithInit.
返回
Owning SharedPtr to the newly constructed publisher.

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

Heap-allocates a Publisher and wraps it in a std::unique_ptr.

参数
url_strTopic URL string, e.g. "dds://vehicle/speed".
typeWhether to call init() inline; default is InitType::kWithInit.
返回
Owning UniquePtr to the newly constructed publisher.

◆ detect_subscribers()

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

Registers a callback invoked whenever subscriber presence transitions.

The callback fires synchronously immediately if a subscriber is already present at registration time, then asynchronously each time the matching subscriber set transitions between empty and non-empty. The boolean is true when at least one peer is present.

参数
callbackvoid(bool) callable – true means at least one subscriber.

◆ has_subscribers()

template<typename MsgT , SecurityType SecT>
bool vlink::Publisher< MsgT, SecT >::has_subscribers
inline

Non-blocking query of subscriber presence.

返回
true when the transport currently knows of at least one matching subscriber.

◆ mark_as_setter()

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

Promotes this publisher to behave as a Setter (field-writer) at the transport layer.

Switches the underlying impl_type from kPublisher to kSetter so that field-mode semantics (late-joiner sync, latest-value retention) are activated. When called post-init(), the transport extension is reinitialised automatically. 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 emits msg to every connected subscriber.

Serialisation is dispatched to the codec selected by kMsgType. On loan-capable transports the output buffer is a loaned segment in transport-managed memory; the loan is returned automatically once the publish completes. Loans are skipped when SecT == kWithSecurity because the ciphertext size is unknown ahead of encryption.

When force is false (the default) the call is skipped and returns false if no subscribers are present. Pass force=true to write unconditionally, e.g. for bag recording or field-style semantics.

Over intra:// with a message whose element_type derives from IntraDataType (declared via VLINK_INTRA_DATA_DECLARE) the shared pointer is forwarded zero-copy and no serialisation occurs.

参数
msgMessage to publish.
forcetrue to publish even when no subscribers are connected.
返回
true if the transport accepted the message.
函数调用图:

◆ publish_fbb()

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

Publishes the raw payload of a pre-finished flatbuffers::FlatBufferBuilder.

Useful in pipelines where the FlatBuffer is constructed externally and the bytes can be shallow-borrowed without re-serialisation. The pointer must reference a builder on which Finish() has been called.

参数
fbbPointer to a finished flatbuffers::FlatBufferBuilder.
forcetrue to publish even when no subscribers are connected.
返回
true on success.

◆ 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 detected or timeout expires.

A timeout of 0 is interpreted as infinite (with a warning log). A negative value also waits indefinitely. Calling interrupt() causes the wait to abort and 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>
constexpr ImplType vlink::Publisher< MsgT, SecT >::kImplType = kPublisher
staticconstexpr

Node role tag (kPublisher).

◆ kMsgType

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

Codec resolved from MsgT.


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