VLink  2.0.0
A high-performance communication middleware
vlink::PublisherImpl Class Referenceabstract

Publish-side base shared by every transport-specific publisher. More...

#include <publisher_impl.h>

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

Public Member Functions

 ~PublisherImpl () override
 Releases the helper state. More...
 
void interrupt () override
 Wakes waiters and forwards the interrupt to NodeImpl. More...
 
virtual void detect_subscribers (ConnectCallback &&callback)
 Registers callback to fire when subscriber presence changes. More...
 
virtual bool wait_for_subscribers (std::chrono::milliseconds timeout)
 Blocks until at least one subscriber is reachable or timeout elapses. More...
 
virtual bool has_subscribers () const =0
 Reports whether at least one subscriber is currently connected. More...
 
virtual bool write (const Bytes &msg_data)=0
 Publishes a serialised payload to every connected subscriber. More...
 
virtual bool write (const IntraData &intra_data)
 Publishes an in-process payload without serialisation. More...
 
void update_subscribers ()
 Notifies the base class that subscriber presence may have changed. More...
 

Protected Member Functions

 PublisherImpl ()
 Stamps the node as kPublisher and primes the helper state. More...
 

Additional Inherited Members

Detailed Description

Publish-side base shared by every transport-specific publisher.

Owns the helper condition variable and connect-callback storage that back Publisher<T>::wait_for_subscribers() and Publisher<T>::detect_subscribers(). Transports invoke update_subscribers() from their discovery threads whenever the subscriber count flips between zero and non-zero.

Constructor & Destructor Documentation

◆ ~PublisherImpl()

vlink::PublisherImpl::~PublisherImpl ( )
override

Releases the helper state.

◆ PublisherImpl()

vlink::PublisherImpl::PublisherImpl ( )
protected

Stamps the node as kPublisher and primes the helper state.

Member Function Documentation

◆ detect_subscribers()

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

Registers callback to fire when subscriber presence changes.

The callback is invoked with true when the first subscriber appears and with false after the last one drops. When subscribers are already known at registration time the callback is primed with true before this function returns.

Parameters
callbackCallable void(bool) describing the new presence.

◆ has_subscribers()

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

Reports whether at least one subscriber is currently connected.

Pure virtual; subclasses query their discovery handle. Used by both wait_for_subscribers() and update_subscribers() to detect state transitions.

Returns
true when a subscriber is reachable.

◆ interrupt()

void vlink::PublisherImpl::interrupt ( )
overridevirtual

Wakes waiters and forwards the interrupt to NodeImpl.

Marks the node interrupted and notifies the helper condition variable so pending wait_for_subscribers() calls return false promptly.

Reimplemented from vlink::NodeImpl.

◆ update_subscribers()

void vlink::PublisherImpl::update_subscribers ( )

Notifies the base class that subscriber presence may have changed.

Compares has_subscribers() against the helper cache; on a transition the condition variable is signalled and the stored ConnectCallback is invoked. Intended for use from transport discovery threads.

◆ wait_for_subscribers()

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

Blocks until at least one subscriber is reachable or timeout elapses.

Returns immediately when has_subscribers() already reports true. Negative timeouts (e.g. Timeout::kInfinite) wait indefinitely.

Parameters
timeoutWait budget; negative disables the deadline.
Returns
true when a subscriber arrived in time; false otherwise.

◆ write() [1/2]

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

Publishes a serialised payload to every connected subscriber.

Pure virtual. msg_data is produced by Serializer::serialize() at the public layer.

Parameters
msg_dataSerialised payload bytes.
Returns
true when the frame was successfully delivered or queued.

◆ write() [2/2]

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

Publishes an in-process payload without serialisation.

Default implementation warns and returns false; only IntraPublisherImpl forwards the shared payload directly to co-located subscribers.

Parameters
intra_dataShared payload pointer.
Returns
true when the message was dispatched; false otherwise.

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