VLink  2.0.0
A high-performance communication middleware
vlink::Node< ImplT, SecT > 模板类 参考

Transport-agnostic CRTP base for all VLink communication primitives. 更多...

#include <node.h>

类 vlink::Node< ImplT, SecT > 继承关系图:
vlink::Node< ImplT, SecT > 的协作图:

Public 类型

using StatusCallback = NodeImpl::StatusCallback
 Handler signature for status-change notifications. 更多...
 

Public 成员函数

virtual bool init ()
 Initialises the node and its transport back-end. 更多...
 
virtual bool deinit ()
 Tears the node down and releases all transport resources. 更多...
 
virtual void interrupt ()
 Aborts any blocking wait on this node. 更多...
 
bool has_inited () const
 Reports whether init() has been successfully called. 更多...
 
bool is_support_loan () const
 Reports whether the transport supports zero-copy loaned buffers. 更多...
 
Bytes loan (int64_t size)
 Allocates a loaned buffer from the transport memory pool. 更多...
 
bool return_loan (const Bytes &bytes)
 Returns a previously loaned buffer to the transport pool. 更多...
 
virtual void set_manual_unloan (bool manual_unloan)
 Toggles manual-unloan mode for zero-copy receives. 更多...
 
virtual bool is_manual_unloan () const
 Reports whether manual-unloan mode is currently active. 更多...
 
bool suspend ()
 Suspends message delivery on this node. 更多...
 
bool resume ()
 Resumes message delivery after a prior suspend(). 更多...
 
bool is_suspend () const
 Reports whether the node is currently suspended. 更多...
 
bool attach (class MessageLoop *message_loop)
 Attaches the node to a MessageLoop for callback dispatch. 更多...
 
bool detach ()
 Detaches the node from its current MessageLoop. 更多...
 
class MessageLoopget_message_loop () const
 Returns the MessageLoop this node is currently attached to. 更多...
 
const AbstractNodeget_abstract_node () const
 Returns the abstract-graph handle for runtime topology inspection. 更多...
 
Status::BasePtr get_status (Status::Type type) const
 Retrieves the current status object for the requested category. 更多...
 
void register_status_handler (StatusCallback &&callback)
 Registers a handler invoked whenever the node's status changes. 更多...
 
void set_property (const std::string &prop, const std::string &value)
 Sets a transport-specific string-keyed property. 更多...
 
std::string get_property (const std::string &prop) const
 Retrieves a previously set transport-specific property value. 更多...
 
TransportType get_transport_type () const
 Returns the TransportType this node is bound to. 更多...
 
const std::string & get_url () const
 Returns the URL string used to construct this node. 更多...
 
void set_record_path (const std::string &path)
 Enables recording of inbound or outbound messages to a bag file. 更多...
 
void set_ser_type (const std::string &ser_type, SchemaType schema_type=SchemaType::kUnknown)
 Overrides the runtime wire-metadata identifiers for this node. 更多...
 
const std::string & get_ser_type () const
 Returns the current concrete runtime type identifier. 更多...
 
SchemaType get_schema_type () const
 Returns the current coarse schema family. 更多...
 
void set_discovery_enabled (bool enable)
 Toggles peer-discovery on this node. 更多...
 
bool get_discovery_enabled () const
 Reports whether peer-discovery is currently enabled. 更多...
 
void bind_proto_arena (void *proto_arena)
 Binds a Protobuf Arena for arena-allocated message objects. 更多...
 
double get_cpu_usage () const
 Returns the cumulative CPU-usage ratio sampled by the profiler. 更多...
 
bool get_safety_quit () const
 Reports whether safe-quit mode is currently active. 更多...
 
void set_safety_quit (bool safety_quit)
 Enables or disables safe-quit mode. 更多...
 
void set_ssl_options (const SslOptions &options)
 Configures transport-layer SSL/TLS encryption for this node. 更多...
 

Protected 成员函数

 Node ()
 
virtual ~Node ()
 
bool enable_security (const Security::Config &cfg)
 Installs a Security configuration before transport initialisation. 更多...
 
bool enable_security (Security::Config &&cfg)
 Move overload for construction-time security installation. 更多...
 
template<typename CallbackT , typename... ArgsT>
void invoke_callback (const CallbackT &callback, ArgsT &&... args)
 
template<typename TypeT >
TypeT get_default_value ()
 

Protected 属性

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_
 

详细描述

template<typename ImplT, SecurityType SecT>
class vlink::Node< ImplT, SecT >

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

模板参数
ImplTConcrete implementation class (e.g. PublisherImpl).
SecTSecurity mode (kWithoutSecurity or kWithSecurity).

成员类型定义说明

◆ StatusCallback

template<typename ImplT , SecurityType SecT>
using vlink::Node< ImplT, SecT >::StatusCallback = NodeImpl::StatusCallback

Handler signature for status-change notifications.

构造及析构函数说明

◆ Node()

template<typename ImplT , SecurityType SecT>
vlink::Node< ImplT, SecT >::Node
inlineprotected

◆ ~Node()

template<typename ImplT , SecurityType SecT>
vlink::Node< ImplT, SecT >::~Node
inlineprotectedvirtual

成员函数说明

◆ attach()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::attach ( class MessageLoop message_loop)
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_loopPointer to the target MessageLoop.
返回
true on success; false if a loop is already attached.

◆ bind_proto_arena()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::bind_proto_arena ( void *  proto_arena)
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_arenaPointer to a google::protobuf::Arena instance (typed as void*).

◆ deinit()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::deinit
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.

vlink::Setter< ValueT, SecT > , 以及 vlink::Setter< ValueT, SecurityType::kWithSecurity > 重载.

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

◆ detach()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::detach
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.

◆ enable_security() [1/2]

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::enable_security ( const Security::Config cfg)
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().

参数
cfgSecurity configuration aggregate.
返回
true when cfg (including the default empty case) is usable for this role / transport.
这是这个函数的调用关系图:

◆ enable_security() [2/2]

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::enable_security ( Security::Config &&  cfg)
inlineprotected

Move overload for construction-time security installation.

Used when an internal caller owns the config and can forward it without an extra copy.

参数
cfgSecurity configuration aggregate to consume.
返回
true when cfg (including the default empty case) is usable for this role / transport.

◆ get_abstract_node()

template<typename ImplT , SecurityType SecT>
const AbstractNode * vlink::Node< ImplT, SecT >::get_abstract_node
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.

返回
Non-owning pointer to the AbstractNode, or nullptr if the transport does not expose one.

◆ get_cpu_usage()

template<typename ImplT , SecurityType SecT>
double vlink::Node< ImplT, SecT >::get_cpu_usage
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.

返回
CPU usage percentage (may exceed 100.0 on multi-core systems); -1.0 if unavailable.

◆ get_default_value()

template<typename ImplT , SecurityType SecT>
template<typename TypeT >
TypeT vlink::Node< ImplT, SecT >::get_default_value
inlineprotected

◆ get_discovery_enabled()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::get_discovery_enabled
inline

Reports whether peer-discovery is currently enabled.

返回
true if discovery is active.

◆ get_message_loop()

template<typename ImplT , SecurityType SecT>
class MessageLoop * vlink::Node< ImplT, SecT >::get_message_loop
inline

Returns the MessageLoop this node is currently attached to.

返回
Pointer to the attached MessageLoop, or nullptr.

◆ get_property()

template<typename ImplT , SecurityType SecT>
std::string vlink::Node< ImplT, SecT >::get_property ( const std::string &  prop) const
inline

Retrieves a previously set transport-specific property value.

参数
propProperty key string.
返回
Property value string; empty if the key is unknown.

◆ get_safety_quit()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::get_safety_quit
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.

◆ get_schema_type()

template<typename ImplT , SecurityType SecT>
SchemaType vlink::Node< ImplT, SecT >::get_schema_type
inline

Returns the current coarse schema family.

返回
The SchemaType stored on the implementation.

◆ get_ser_type()

template<typename ImplT , SecurityType SecT>
const std::string & vlink::Node< ImplT, SecT >::get_ser_type
inline

Returns the current concrete runtime type identifier.

返回
Const reference to the type identifier string.

◆ get_status()

template<typename ImplT , SecurityType SecT>
Status::BasePtr vlink::Node< ImplT, SecT >::get_status ( Status::Type  type) const
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.

参数
typeStatus category to retrieve.
返回
Shared pointer to status data, or Status::Unknown when unsupported.

◆ get_transport_type()

template<typename ImplT , SecurityType SecT>
TransportType vlink::Node< ImplT, SecT >::get_transport_type
inline

Returns the TransportType this node is bound to.

返回
Enumerator such as kDds, kShm, kIntra, etc.

◆ get_url()

template<typename ImplT , SecurityType SecT>
const std::string & vlink::Node< ImplT, SecT >::get_url
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.

返回
Const reference to the URL string.

◆ has_inited()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::has_inited
inline

Reports whether init() has been successfully called.

返回
true when the node is currently in the initialised state.

◆ init()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::init
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.

vlink::Setter< ValueT, SecT >, vlink::Setter< ValueT, SecurityType::kWithSecurity >, vlink::Getter< ValueT, SecT > , 以及 vlink::Getter< ValueT, SecurityType::kWithSecurity > 重载.

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

◆ interrupt()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::interrupt
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().

vlink::Getter< ValueT, SecT > , 以及 vlink::Getter< ValueT, SecurityType::kWithSecurity > 重载.

◆ invoke_callback()

template<typename ImplT , SecurityType SecT>
template<typename CallbackT , typename... ArgsT>
void vlink::Node< ImplT, SecT >::invoke_callback ( const CallbackT &  callback,
ArgsT &&...  args 
)
inlineprotected

◆ is_manual_unloan()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::is_manual_unloan
inlinevirtual

Reports whether manual-unloan mode is currently active.

返回
true if set_manual_unloan(true) was invoked.

◆ is_support_loan()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::is_support_loan
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.

◆ is_suspend()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::is_suspend
inline

Reports whether the node is currently suspended.

返回
true while suspend() is in effect.

◆ loan()

template<typename ImplT , SecurityType SecT>
Bytes vlink::Node< ImplT, SecT >::loan ( int64_t  size)
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.

参数
sizeRequested byte count; 0 is valid for empty messages.
返回
Loaned Bytes, or an empty Bytes on failure.

◆ register_status_handler()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::register_status_handler ( StatusCallback &&  callback)
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.).

参数
callbackvoid(const Status::BasePtr&) handler.

◆ resume()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::resume
inline

Resumes message delivery after a prior suspend().

返回
true if resumption succeeded.

◆ return_loan()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::return_loan ( const Bytes bytes)
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.

参数
bytesThe loaned Bytes to return.
返回
true on success; false if the buffer is not a valid loan.

◆ set_discovery_enabled()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_discovery_enabled ( bool  enable)
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.

参数
enabletrue (default) to enable discovery; false to disable.

◆ set_manual_unloan()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_manual_unloan ( bool  manual_unloan)
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_unloantrue to enable; false for automatic (default).

vlink::Subscriber< MsgT, SecT >, vlink::Subscriber< MsgT, SecurityType::kWithSecurity >, vlink::Getter< ValueT, SecT > , 以及 vlink::Getter< ValueT, SecurityType::kWithSecurity > 重载.

◆ set_property()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_property ( const std::string &  prop,
const std::string &  value 
)
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.

参数
propProperty key string.
valueProperty value string.

◆ set_record_path()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_record_path ( const std::string &  path)
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.

参数
pathBag file path on disk.

◆ set_safety_quit()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_safety_quit ( bool  safety_quit)
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_quittrue to enable; false to disable (default).

◆ set_ser_type()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_ser_type ( const std::string &  ser_type,
SchemaType  schema_type = SchemaType::kUnknown 
)
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_typeConcrete runtime type identifier, or empty to clear.
schema_typeOptional explicit schema family; default preserves the current family.

◆ set_ssl_options()

template<typename ImplT , SecurityType SecT>
void vlink::Node< ImplT, SecT >::set_ssl_options ( const SslOptions options)
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.

Example
ssl.ca_file = "/etc/certs/ca.pem";
ssl.cert_file = "/etc/certs/client.pem";
ssl.key_file = "/etc/certs/client-key.pem";
pub.set_ssl_options(ssl);
pub.init();
参数
optionsSSL/TLS configuration to apply.
参见
SslOptions, set_property()

◆ suspend()

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::suspend
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.

类成员变量说明

◆ has_inited_

template<typename ImplT , SecurityType SecT>
std::atomic_bool vlink::Node< ImplT, SecT >::has_inited_ {false}
protected

◆ impl_

template<typename ImplT , SecurityType SecT>
std::unique_ptr<ImplT> vlink::Node< ImplT, SecT >::impl_
protected

◆ is_manual_unloan_

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::is_manual_unloan_ {false}
protected

◆ is_support_loan_

template<typename ImplT , SecurityType SecT>
bool vlink::Node< ImplT, SecT >::is_support_loan_ {false}
protected

◆ proto_arena_

template<typename ImplT , SecurityType SecT>
void* vlink::Node< ImplT, SecT >::proto_arena_ {nullptr}
protected

◆ quit_mtx_

template<typename ImplT , SecurityType SecT>
std::optional<std::mutex> vlink::Node< ImplT, SecT >::quit_mtx_
protected

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