|
VLink 2.0.0
A high-performance communication middleware
|
Transport-agnostic base for publisher node implementations. More...
#include <publisher_impl.h>
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. | |
| Public Member Functions inherited from vlink::NodeImpl | |
| virtual void | init ()=0 |
| Initialises the underlying transport channel. | |
| virtual void | deinit ()=0 |
| Tears down the underlying transport channel. | |
| virtual bool | suspend () |
| Temporarily suspends message delivery without tearing down the channel. | |
| virtual bool | resume () |
Resumes message delivery after a suspend() call. | |
| virtual bool | is_suspend () const |
Returns true when the node is currently suspended. | |
| virtual bool | is_support_loan () const |
Returns true if the transport supports zero-copy loaning. | |
| virtual Bytes | loan (int64_t size) |
Borrows a write buffer of size bytes from the transport. | |
| virtual bool | return_loan (const Bytes &bytes) |
| Returns a previously loaned buffer to the transport. | |
| virtual void | set_manual_unloan (bool manual_unloan) |
| Configures manual unloan mode for zero-copy transports. | |
| virtual const struct Conf * | get_conf () const |
Returns a pointer to the associated Conf configuration object. | |
| virtual const AbstractNode * | get_abstract_node () const |
Returns a pointer to the AbstractNode peer (if any). | |
| virtual Status::BasePtr | get_status (Status::Type type) const |
| Retrieves a transport-specific status object. | |
| virtual bool | check_version (const Version &version) |
Checks whether version matches the runtime VLink library version. | |
| virtual bool | attach (class MessageLoop *message_loop) |
Attaches the node to a MessageLoop for callback dispatch. | |
| virtual bool | detach () |
Detaches the node from its MessageLoop. | |
| class MessageLoop * | get_message_loop () const |
Returns the MessageLoop this node is attached to. | |
| template<typename T> | |
| const T * | get_target_conf () const |
Returns a typed pointer to the conf by downcasting to T. | |
| void | register_status_handler (StatusCallback &&callback) |
| Registers a callback for DDS status events. | |
| bool | has_register_status () const |
Returns true if a status handler has been registered. | |
| void | call_status (Status::BasePtr ptr) |
| Dispatches a status event to the registered status handler. | |
| void | set_property (const std::string &prop, const std::string &value) |
| Sets a named transport property on this node. | |
| std::string | get_property (const std::string &prop) const |
| Retrieves a named transport property. | |
| Conf::PropertiesMap | get_all_properties () const |
| Returns a snapshot of all properties set on this node. | |
| void | set_discovery_enabled (bool enable) |
| Enables or disables discovery reporting for this node. | |
| bool | get_discovery_enabled () const |
Returns true if discovery reporting is enabled for this node. | |
| void | set_record_path (const std::string &path) |
| Sets the file path for per-node message recording. | |
| void | set_ssl_options (const SslOptions &options) |
| Merges SSL/TLS options into the node property map. | |
| void | try_record (ActionType action_type, const Bytes &data) |
| Records a message to the global and/or per-node bag writers. | |
| void | reset_interrupted () |
Clears the interrupted flag set by interrupt(). | |
| bool | is_interrupted () const |
Returns true if interrupt() has been called and not yet reset. | |
| void | init_ext () |
Registers the node with the global DiscoveryReporter. | |
| void | deinit_ext () |
Deregisters the node from the global DiscoveryReporter. | |
Protected Member Functions | |
| PublisherImpl () | |
Protected constructor; initialises the publisher with kPublisher role. | |
| Protected Member Functions inherited from vlink::NodeImpl | |
| NodeImpl (ImplType type) | |
| virtual | ~NodeImpl () |
Additional Inherited Members | |
| Public Types inherited from vlink::NodeImpl | |
| using | ConnectCallback = std::function<void(bool)> |
| Callback invoked when the peer connection state changes. | |
| using | StatusCallback = std::function<void(const Status::BasePtr& ptr)> |
| Callback invoked on DDS status events (e.g. deadline missed). | |
| using | SyncCallback = std::function<void()> |
Callback invoked when a SetterImpl sync completes. | |
| using | ReqRespCallback = std::function<void(uint64_t, const Bytes&, Bytes*)> |
Callback for ServerImpl request/response processing. | |
| using | MsgCallback = std::function<void(const Bytes&)> |
Callback delivering a raw serialised message to a SubscriberImpl or GetterImpl. | |
| using | IntraMsgCallback = std::function<void(const IntraData&)> |
Callback delivering an in-process IntraData message. | |
| Static Public Member Functions inherited from vlink::NodeImpl | |
| static void | global_init () |
| Initialises process-wide VLink singletons. | |
| Public Attributes inherited from vlink::NodeImpl | |
| std::atomic_bool | has_suspend {false} |
| Atomic suspend state flag (currently unused by default impls). | |
| std::string | url |
Full URL string of this node (e.g. "dds://my/topic"). | |
| std::string | ser_type |
Serialisation type string (e.g. "demo.proto.PointCloud"). | |
| ImplType | impl_type {kUnknownImplType} |
| Role of this implementation node. | |
| SchemaType | schema_type {SchemaType::kUnknown} |
| Coarse schema family reported to discovery and bag/proxy paths. | |
| TransportType | transport_type {TransportType::kUnknown} |
| Transport backend of this implementation node. | |
| bool | is_cdr_type {false} |
true when using DDS native CDR serialisation. | |
| bool | is_security_type {false} |
true when security-authenticated transport is enabled. | |
| bool | is_discovery_enabled {true} |
| Whether this node is reported to the discovery layer. | |
| std::unique_ptr< class CpuProfiler > | profiler |
| Optional per-node CPU profiler (only when global profiling is on). | |
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.
|
override |
Destructor.
|
protected |
Protected constructor; initialises the publisher with kPublisher role.
|
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.
| callback | Callable void(bool) to invoke on subscriber change. |
|
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.
|
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.
| 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.
|
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.| timeout | Maximum time to wait; negative value means wait forever. |
true if a subscriber was detected; false on timeout or interruption.
|
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_data | Serialised message bytes to transmit. |
true if the message was delivered (or queued) successfully; false on error.
|
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_data | Shared pointer to the in-process message payload. |
true if the message was delivered; false if this transport does not support IntraData.