VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::PublisherImpl类 参考abstract

Transport-agnostic base for publisher node implementations. 更多...

#include <publisher_impl.h>

类 vlink::PublisherImpl 继承关系图:
vlink::PublisherImpl 的协作图:

Public 成员函数

 ~PublisherImpl () override
 Destructor.
void interrupt () override
 Interrupts the publisher, waking any blocked wait_for_subscribers() call.
virtual void detect_subscribers (ConnectCallback &&callback)
 Registers a callback to be fired when the subscriber presence changes.
virtual bool wait_for_subscribers (std::chrono::milliseconds timeout)
 Blocks until at least one subscriber is present or the timeout elapses.
virtual bool has_subscribers () const =0
 Returns true when at least one subscriber is currently connected.
virtual bool write (const Bytes &msg_data)=0
 Publishes a serialised message to all connected subscribers.
virtual bool write (const IntraData &intra_data)
 Publishes an in-process zero-copy message.
void update_subscribers ()
 Notifies the subscriber-detection subsystem that subscriber presence may have changed.

Protected 成员函数

 PublisherImpl ()
 Protected constructor; initialises the publisher with kPublisher role.

额外继承的成员函数

详细描述

Transport-agnostic base for publisher node implementations.

Provides the subscriber-detection infrastructure (condition variable + callback) used by Publisher<T>::wait_for_subscribers() and Publisher<T>::detect_subscribers(). Concrete backends override has_subscribers() to query the transport layer and call update_subscribers() whenever the subscriber count changes.

构造及析构函数说明

◆ ~PublisherImpl()

vlink::PublisherImpl::~PublisherImpl ( )
override

Destructor.

◆ PublisherImpl()

vlink::PublisherImpl::PublisherImpl ( )
protected

Protected constructor; initialises the publisher with kPublisher role.

函数调用图:
这是这个函数的调用关系图:

成员函数说明

◆ detect_subscribers()

virtual void vlink::PublisherImpl::detect_subscribers ( ConnectCallback && callback)
virtual

Registers a callback to be fired when the subscriber presence changes.

The callback is stored and invoked with true when the first subscriber appears and false when the last one disconnects. If subscribers are already present at registration time the callback is fired immediately with true before this function returns.

参数
callbackCallable void(bool) to invoke on subscriber change.

◆ has_subscribers()

virtual bool vlink::PublisherImpl::has_subscribers ( ) const
nodiscardpure virtual

Returns true when at least one subscriber is currently connected.

Must be implemented by each concrete transport backend. Called by wait_for_subscribers() and update_subscribers() to determine whether the subscriber presence state has changed.

返回
true if one or more subscribers are connected; false otherwise.

◆ interrupt()

void vlink::PublisherImpl::interrupt ( )
overridevirtual

Interrupts the publisher, waking any blocked wait_for_subscribers() call.

Calls NodeImpl::interrupt() to set the interrupted flag, then notify_all() on the internal condition variable so that any thread blocked in wait_for_subscribers() returns immediately with false.

重载 vlink::NodeImpl .

◆ update_subscribers()

void vlink::PublisherImpl::update_subscribers ( )

Notifies the subscriber-detection subsystem that subscriber presence may have changed.

Called by the concrete transport backend whenever a subscriber connects or disconnects. Compares the current has_subscribers() result against the cached state; if it differs, the condition variable is notified and the registered ConnectCallback is fired.

注解
This method is intended to be called from the transport's internal discovery thread, not from user code.

◆ wait_for_subscribers()

virtual bool vlink::PublisherImpl::wait_for_subscribers ( std::chrono::milliseconds timeout)
virtual

Blocks until at least one subscriber is present or the timeout elapses.

Returns immediately if has_subscribers() is already true. Otherwise waits on an internal condition variable that is notified by update_subscribers() and interrupt().

  • timeout < 0 (e.g. Timeout::kInfinite): waits indefinitely.
  • timeout >= 0: returns false if no subscriber arrives within the period.
参数
timeoutMaximum time to wait; negative value means wait forever.
返回
true if a subscriber was detected; false on timeout or interruption.

◆ write() [1/2]

virtual bool vlink::PublisherImpl::write ( const Bytes & msg_data)
pure virtual

Publishes a serialised message to all connected subscribers.

Must be implemented by each concrete transport backend. msg_data contains the fully serialised payload produced by Serializer::serialize().

参数
msg_dataSerialised message bytes to transmit.
返回
true if the message was delivered (or queued) successfully; false on error.

◆ write() [2/2]

virtual bool vlink::PublisherImpl::write ( const IntraData & intra_data)
virtual

Publishes an in-process zero-copy message.

Used exclusively on the intra:// transport to pass IntraData directly to subscribers in the same process without serialisation. The default implementation logs a warning and returns false; only IntraPublisherImpl overrides this method.

参数
intra_dataShared pointer to the in-process message payload.
返回
true if the message was delivered; false if this transport does not support IntraData.

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