|
VLink
2.0.0
A high-performance communication middleware
|
Transport-agnostic CRTP base for all VLink communication primitives. More...
#include <node.h>
Public Types | |
| using | StatusCallback = NodeImpl::StatusCallback |
| Handler signature for status-change notifications. More... | |
Public Member Functions | |
| virtual bool | init () |
| Initialises the node and its transport back-end. More... | |
| virtual bool | deinit () |
| Tears the node down and releases all transport resources. More... | |
| virtual void | interrupt () |
| Aborts any blocking wait on this node. More... | |
| bool | has_inited () const |
Reports whether init() has been successfully called. More... | |
| bool | is_support_loan () const |
| Reports whether the transport supports zero-copy loaned buffers. More... | |
| Bytes | loan (int64_t size) |
| Allocates a loaned buffer from the transport memory pool. More... | |
| bool | return_loan (const Bytes &bytes) |
| Returns a previously loaned buffer to the transport pool. More... | |
| virtual void | set_manual_unloan (bool manual_unloan) |
| Toggles manual-unloan mode for zero-copy receives. More... | |
| virtual bool | is_manual_unloan () const |
| Reports whether manual-unloan mode is currently active. More... | |
| bool | suspend () |
| Suspends message delivery on this node. More... | |
| bool | resume () |
Resumes message delivery after a prior suspend(). More... | |
| bool | is_suspend () const |
| Reports whether the node is currently suspended. More... | |
| bool | attach (class MessageLoop *message_loop) |
Attaches the node to a MessageLoop for callback dispatch. More... | |
| bool | detach () |
Detaches the node from its current MessageLoop. More... | |
| class MessageLoop * | get_message_loop () const |
Returns the MessageLoop this node is currently attached to. More... | |
| const AbstractNode * | get_abstract_node () const |
| Returns the abstract-graph handle for runtime topology inspection. More... | |
| Status::BasePtr | get_status (Status::Type type) const |
| Retrieves the current status object for the requested category. More... | |
| void | register_status_handler (StatusCallback &&callback) |
| Registers a handler invoked whenever the node's status changes. More... | |
| void | set_property (const std::string &prop, const std::string &value) |
| Sets a transport-specific string-keyed property. More... | |
| std::string | get_property (const std::string &prop) const |
| Retrieves a previously set transport-specific property value. More... | |
| TransportType | get_transport_type () const |
Returns the TransportType this node is bound to. More... | |
| const std::string & | get_url () const |
| Returns the URL string used to construct this node. More... | |
| void | set_record_path (const std::string &path) |
| Enables recording of inbound or outbound messages to a bag file. More... | |
| void | set_ser_type (const std::string &ser_type, SchemaType schema_type=SchemaType::kUnknown) |
| Overrides the runtime wire-metadata identifiers for this node. More... | |
| const std::string & | get_ser_type () const |
| Returns the current concrete runtime type identifier. More... | |
| SchemaType | get_schema_type () const |
| Returns the current coarse schema family. More... | |
| void | set_discovery_enabled (bool enable) |
| Toggles peer-discovery on this node. More... | |
| bool | get_discovery_enabled () const |
| Reports whether peer-discovery is currently enabled. More... | |
| void | bind_proto_arena (void *proto_arena) |
| Binds a Protobuf Arena for arena-allocated message objects. More... | |
| double | get_cpu_usage () const |
| Returns the cumulative CPU-usage ratio sampled by the profiler. More... | |
| bool | get_safety_quit () const |
| Reports whether safe-quit mode is currently active. More... | |
| void | set_safety_quit (bool safety_quit) |
| Enables or disables safe-quit mode. More... | |
| void | set_ssl_options (const SslOptions &options) |
| Configures transport-layer SSL/TLS encryption for this node. More... | |
Protected Member Functions | |
| Node () | |
| virtual | ~Node () |
| bool | enable_security (const Security::Config &cfg) |
Installs a Security configuration before transport initialisation. More... | |
| bool | enable_security (Security::Config &&cfg) |
| Move overload for construction-time security installation. More... | |
| template<typename CallbackT , typename... ArgsT> | |
| void | invoke_callback (const CallbackT &callback, ArgsT &&... args) |
| template<typename TypeT > | |
| TypeT | get_default_value () |
Protected Attributes | |
| void * | proto_arena_ {nullptr} |
| bool | is_support_loan_ {false} |
| bool | is_manual_unloan_ {false} |
| std::atomic_bool | has_inited_ {false} |
| std::optional< std::mutex > | quit_mtx_ |
| std::unique_ptr< ImplT > | impl_ |
Transport-agnostic CRTP base for all VLink communication primitives.
Provides the lifecycle, loan, security, property, profiler, message-loop, recording, discovery, and TLS APIs shared by every primitive in the library. Subclasses fill in the role-specific operations (publish, listen, invoke, set, get, etc.).
| ImplT | Concrete implementation class (e.g. PublisherImpl). |
| SecT | Security mode (kWithoutSecurity or kWithSecurity). |
| using vlink::Node< ImplT, SecT >::StatusCallback = NodeImpl::StatusCallback |
Handler signature for status-change notifications.
|
inlineprotected |
|
inlineprotectedvirtual |
|
inline |
Attaches the node to a MessageLoop for callback dispatch.
After attachment, inbound callbacks are posted onto message_loop rather than invoked on the transport delivery thread. This serialises dispatch onto the loop's thread, which is convenient for single-threaded user code.
| message_loop | Pointer to the target MessageLoop. |
true on success; false if a loop is already attached.
|
inline |
Binds a Protobuf Arena for arena-allocated message objects.
Required when MsgT is a raw Protobuf pointer type (e.g. MyProto*). The arena must outlive this node. Forgetting to bind an arena before the first received message triggers a fatal log.
| proto_arena | Pointer to a google::protobuf::Arena instance (typed as void*). |
|
inlinevirtual |
Tears the node down and releases all transport resources.
Atomically guards against double-deinit, then runs interrupt(), impl_->deinit(), and impl_->deinit_ext(). When safe-quit mode is active the sequence runs under the safe-quit mutex. The destructor calls this automatically so explicit calls are only required for early shutdown.
true on first successful deinit; false if not initialised. Reimplemented in vlink::Setter< ValueT, SecT >, and vlink::Setter< ValueT, SecurityType::kWithSecurity >.
|
inline |
Detaches the node from its current MessageLoop.
After detachment the callback returns to running on the transport delivery thread.
true on success; false if no loop was attached.
|
inlineprotected |
Installs a Security configuration before transport initialisation.
Internal helper used by the Security* primitive constructors after impl_ has been created but before init(). Delegates default handling, validation, and storage to NodeImpl::enable_security().
| cfg | Security configuration aggregate. |
true when cfg (including the default empty case) is usable for this role / transport.
|
inlineprotected |
Move overload for construction-time security installation.
Used when an internal caller owns the config and can forward it without an extra copy.
| cfg | Security configuration aggregate to consume. |
true when cfg (including the default empty case) is usable for this role / transport.
|
inline |
Returns the abstract-graph handle for runtime topology inspection.
The AbstractNode pointer is usable with AbstractFactory and the proxy monitoring API to enumerate peer nodes in the same transport graph.
AbstractNode, or nullptr if the transport does not expose one.
|
inline |
Returns the cumulative CPU-usage ratio sampled by the profiler.
Reports the percentage of wall-clock time this node has spent in active publish or receive code since the profiler was started. Available only when the CPU profiler is built in (VLINK_DISABLE_PROFILER not defined) and global profiling is enabled via the VLINK_PROFILER_ENABLE environment variable. Returns -1.0 if no profiler is attached.
100.0 on multi-core systems); -1.0 if unavailable.
|
inlineprotected |
|
inline |
Reports whether peer-discovery is currently enabled.
true if discovery is active.
|
inline |
Returns the MessageLoop this node is currently attached to.
MessageLoop, or nullptr.
|
inline |
Retrieves a previously set transport-specific property value.
| prop | Property key string. |
|
inline |
Reports whether safe-quit mode is currently active.
Safe-quit mode holds a std::mutex around user callbacks and around deinit() to prevent use-after-free races when a node is destroyed while a callback is in flight.
true if the safe-quit mutex is engaged.
|
inline |
Returns the current coarse schema family.
SchemaType stored on the implementation.
|
inline |
Returns the current concrete runtime type identifier.
|
inline |
Retrieves the current status object for the requested category.
Returns a polymorphic shared pointer. The concrete type and set of supported categories depend on the active transport; an unsupported type yields a Status::Unknown instance and logs a warning.
| type | Status category to retrieve. |
Status::Unknown when unsupported.
|
inline |
Returns the TransportType this node is bound to.
kDds, kShm, kIntra, etc.
|
inline |
Returns the URL string used to construct this node.
Non-empty only when the node was constructed via a URL string or Url object; typed ConfT-based construction leaves this empty.
|
inline |
Reports whether init() has been successfully called.
true when the node is currently in the initialised state.
|
inlinevirtual |
Initialises the node and its transport back-end.
Uses an atomic compare-exchange to guard against double-initialisation. On success the method runs impl_->init() then impl_->init_ext() and finally samples the transport's loan capability flag. Calling init() on an already-initialised node is a no-op.
true on first successful initialisation; false otherwise. Reimplemented in vlink::Setter< ValueT, SecT >, vlink::Setter< ValueT, SecurityType::kWithSecurity >, vlink::Getter< ValueT, SecT >, and vlink::Getter< ValueT, SecurityType::kWithSecurity >.
|
inlinevirtual |
Aborts any blocking wait on this node.
Signals the internal interrupted flag and notifies the condition variable so that wait_for_subscribers(), wait_for_connected(), and wait_for_value() return immediately with false. Getter overrides this to additionally wake its own condition variable used by wait_for_value().
Reimplemented in vlink::Getter< ValueT, SecT >, and vlink::Getter< ValueT, SecurityType::kWithSecurity >.
|
inlineprotected |
|
inlinevirtual |
Reports whether manual-unloan mode is currently active.
true if set_manual_unloan(true) was invoked.
|
inline |
Reports whether the transport supports zero-copy loaned buffers.
Delegates to the transport implementation. When loans are supported, publish() / set() / reply() automatically use them to avoid an extra memory copy.
true if loan() / return_loan() are meaningful for this transport.
|
inline |
Reports whether the node is currently suspended.
true while suspend() is in effect.
|
inline |
Allocates a loaned buffer from the transport memory pool.
Returns a Bytes backed by transport-managed memory of size bytes. The caller must either pass it to a publish/write call (which returns the loan automatically) or call return_loan() explicitly. Returns an empty Bytes on failure or when the transport has no loan pool.
| size | Requested byte count; 0 is valid for empty messages. |
|
inline |
Registers a handler invoked whenever the node's status changes.
Only one handler can be registered at a time; subsequent calls replace the previous handler. The handler receives a Status::BasePtr describing the new state (connected, disconnected, error, etc.).
| callback | void(const Status::BasePtr&) handler. |
|
inline |
Resumes message delivery after a prior suspend().
true if resumption succeeded.
|
inline |
Returns a previously loaned buffer to the transport pool.
Must be called whenever a loan obtained via loan() is not consumed by a publish/write call; failing to return loans can exhaust the shared memory pool.
| bytes | The loaned Bytes to return. |
true on success; false if the buffer is not a valid loan.
|
inline |
Toggles peer-discovery on this node.
Disabling discovery reduces CPU and network overhead for nodes that never need to locate peers. Reinitialises the transport extension if invoked post-init() so the change takes effect immediately.
| enable | true (default) to enable discovery; false to disable. |
|
inlinevirtual |
Toggles manual-unloan mode for zero-copy receives.
In manual mode the user must call return_loan() after consuming each received buffer. The base implementation logs a warning; only Subscriber and Getter provide a meaningful override.
| manual_unloan | true to enable; false for automatic (default). |
Reimplemented in vlink::Subscriber< MsgT, SecT >, vlink::Subscriber< MsgT, SecurityType::kWithSecurity >, vlink::Getter< ValueT, SecT >, and vlink::Getter< ValueT, SecurityType::kWithSecurity >.
|
inline |
Sets a transport-specific string-keyed property.
Extensibility mechanism for back-end-specific tuning knobs that do not have a dedicated method. Recognised keys depend on the active transport.
| prop | Property key string. |
| value | Property value string. |
|
inline |
Enables recording of inbound or outbound messages to a bag file.
Not supported on intra:// or dds:// CDR nodes (triggers a fatal log). Supported file suffixes are .vdb, .vdbx, .vcap, and .vcapx; an unknown suffix logs an error and disables recording.
| path | Bag file path on disk. |
|
inline |
Enables or disables safe-quit mode.
When enabled, an internal std::mutex is allocated and locked around every callback invocation and around deinit(). Enable when the node's lifetime is shorter than the callback scope. There is a small synchronisation overhead; avoid enabling it on hot paths.
| safety_quit | true to enable; false to disable (default). |
|
inline |
Overrides the runtime wire-metadata identifiers for this node.
ser_type holds the concrete runtime type identifier; schema_type holds the coarse decoder family used by discovery, proxy, and bag metadata. When schema_type is SchemaType::kUnknown (the default) the family is inferred from ser_type: a "vlink::zerocopy::" prefix implies kZeroCopy, while values such as "raw", "string", "std::string", "text", or "json" imply kRaw. If no family can be inferred, an existing kRaw or kZeroCopy family is reset to kUnknown; any other existing family is preserved. Passing an empty ser_type clears both fields.
If invoked post-init() the transport extension is restarted so that external metadata stays in sync.
| ser_type | Concrete runtime type identifier, or empty to clear. |
| schema_type | Optional explicit schema family; default preserves the current family. |
|
inline |
Configures transport-layer SSL/TLS encryption for this node.
Merges the fields of options into the node's internal property map via SslOptions::parse_to(). The transport reads the resulting ssl.* properties during init() to set up the TLS connection, so this method must be called before init() for the settings to take effect.
SSL is considered enabled when SslOptions::is_valid() returns true (i.e. at least ca_file or cert_file is non-empty). Not all back-ends support TLS; see SslOptions for the per-backend compatibility table. Thread-safe – the property map is updated under a mutex.
| options | SSL/TLS configuration to apply. |
|
inline |
Suspends message delivery on this node.
Transport-dependent behaviour: some back-ends buffer incoming messages while suspended, others drop them. Pair with resume().
true if suspension succeeded.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |