VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::PublisherImpl Class Referenceabstract

Transport-agnostic base for publisher node implementations. More...

#include <publisher_impl.h>

Inheritance diagram for vlink::PublisherImpl:
Collaboration diagram for vlink::PublisherImpl:

Public Member Functions

 ~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 Member Functions

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

Additional Inherited Members

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~PublisherImpl()

vlink::PublisherImpl::~PublisherImpl ( )
override

Destructor.

◆ PublisherImpl()

vlink::PublisherImpl::PublisherImpl ( )
protected

Protected constructor; initialises the publisher with kPublisher role.

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

Member Function Documentation

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

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

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

Reimplemented from 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.

Note
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.
Parameters
timeoutMaximum time to wait; negative value means wait forever.
Returns
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().

Parameters
msg_dataSerialised message bytes to transmit.
Returns
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.

Parameters
intra_dataShared pointer to the in-process message payload.
Returns
true if the message was delivered; false if this transport does not support IntraData.

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