|
VLink
2.0.0
A high-performance communication middleware
|
Type-safe topic listener for the VLink event communication model. 更多...
#include <subscriber.h>
Public 类型 | |
| using | UniquePtr = std::unique_ptr< Subscriber< MsgT, SecT > > |
| Owning unique-pointer alias. 更多... | |
| using | SharedPtr = std::shared_ptr< Subscriber< MsgT, SecT > > |
| Owning shared-pointer alias. 更多... | |
| using | MsgCallback = Function< void(const MsgT &)> |
| User callback signature for received messages. 更多... | |
Public 类型 继承自 vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity > | |
| using | StatusCallback = NodeImpl::StatusCallback |
| Handler signature for status-change notifications. 更多... | |
Public 成员函数 | |
| template<typename ConfT , typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>> | |
| Subscriber (const ConfT &conf, InitType type=InitType::kWithInit) | |
| Constructs a subscriber from a typed transport configuration object. 更多... | |
| Subscriber (const std::string &url_str, InitType type=InitType::kWithInit) | |
| Constructs a subscriber from a URL string. 更多... | |
| bool | listen (MsgCallback &&callback) |
| Installs the receive callback that runs for every inbound message. 更多... | |
| void | set_manual_unloan (bool manual_unloan) override |
| Enables or disables manual-unloan mode for zero-copy receives. 更多... | |
| void | set_latency_and_lost_enabled (bool enable) |
| Toggles per-message latency and sample-loss measurement. 更多... | |
| bool | is_latency_and_lost_enabled () const |
| Reports whether latency and sample-loss tracking is currently active. 更多... | |
| int64_t | get_latency () const |
| Returns the most recent end-to-end latency measurement. 更多... | |
| SampleLostInfo | get_lost () const |
| Returns cumulative sample-delivery statistics. 更多... | |
| void | mark_as_getter () |
Promotes this subscriber to behave as a Getter (field-reader) at the transport layer. 更多... | |
Public 成员函数 继承自 vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity > | |
| 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 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 MessageLoop * | get_message_loop () const |
Returns the MessageLoop this node is currently attached to. 更多... | |
| const AbstractNode * | get_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. 更多... | |
静态 Public 成员函数 | |
| static UniquePtr | create_unique (const std::string &url_str, InitType type=InitType::kWithInit) |
Heap-allocates a Subscriber and wraps it in a std::unique_ptr. 更多... | |
| static SharedPtr | create_shared (const std::string &url_str, InitType type=InitType::kWithInit) |
Heap-allocates a Subscriber and wraps it in a std::shared_ptr. 更多... | |
静态 Public 属性 | |
| static constexpr ImplType | kImplType = kSubscriber |
Node role tag (kSubscriber). 更多... | |
| static constexpr Serializer::Type | kMsgType = Serializer::get_type_of<MsgT>() |
Codec resolved from MsgT. 更多... | |
额外继承的成员函数 | |
Protected 成员函数 继承自 vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity > | |
| 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. 更多... | |
| void | invoke_callback (const CallbackT &callback, ArgsT &&... args) |
| TypeT | get_default_value () |
Protected 属性 继承自 vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity > | |
| void * | proto_arena_ |
| bool | is_support_loan_ |
| bool | is_manual_unloan_ |
| std::atomic_bool | has_inited_ |
| std::optional< std::mutex > | quit_mtx_ |
| std::unique_ptr< SubscriberImpl > | impl_ |
Type-safe topic listener for the VLink event communication model.
Inherits the full Node API and adds receive-specific operations: listen() to register the user callback, manual-unloan control for zero-copy back-ends, and latency / sample-loss tracking. The transport implementation (SubscriberImpl) is selected by the URL scheme or by the typed configuration object supplied at construction time.
| MsgT | C++ message type. Must satisfy Serializer::is_supported(). |
| SecT | Security mode; defaults to SecurityType::kWithoutSecurity. |
| using vlink::Subscriber< MsgT, SecT >::MsgCallback = Function<void(const MsgT&)> |
User callback signature for received messages.
| using vlink::Subscriber< MsgT, SecT >::SharedPtr = std::shared_ptr<Subscriber<MsgT, SecT> > |
Owning shared-pointer alias.
| using vlink::Subscriber< MsgT, SecT >::UniquePtr = std::unique_ptr<Subscriber<MsgT, SecT> > |
Owning unique-pointer alias.
|
inlineexplicit |
Constructs a subscriber from a typed transport configuration object.
Accepts any Conf-derived configuration. A compile-time check enforces that the configuration permits the subscriber role.
| ConfT | Concrete configuration type derived from Conf. |
| conf | Populated configuration aggregate. |
| type | Whether to call init() inline; default is InitType::kWithInit. |
|
inlineexplicit |
Constructs a subscriber from a URL string.
| url_str | Topic URL such as "shm://vehicle/speed". |
| type | Whether to call init() inline; default is InitType::kWithInit. |
|
inlinestatic |
Heap-allocates a Subscriber and wraps it in a std::shared_ptr.
| url_str | Topic URL string. |
| type | Whether to call init() inline; default is InitType::kWithInit. |
SharedPtr to the new subscriber.
|
inlinestatic |
Heap-allocates a Subscriber and wraps it in a std::unique_ptr.
| url_str | Topic URL string. |
| type | Whether to call init() inline; default is InitType::kWithInit. |
UniquePtr to the new subscriber.
|
inline |
Returns the most recent end-to-end latency measurement.
Computed as receive-timestamp minus source-timestamp on the last delivered message. Returns 0 when tracking is not enabled.
0 if disabled.
|
inline |
Returns cumulative sample-delivery statistics.
SampleLostInfo with total expected and total lost counts.
|
inline |
Reports whether latency and sample-loss tracking is currently active.
true if set_latency_and_lost_enabled(true) was invoked.
|
inline |
Installs the receive callback that runs for every inbound message.
The callback is invoked on the transport delivery thread by default; if the subscriber is attach()ed to a MessageLoop the callback is posted onto that loop instead. For intra:// transports carrying an IntraDataType shared pointer the value is forwarded zero-copy and no deserialisation occurs.
thread_local scratch memory that is reused across invocations. Copy the data before stashing it outside the callback. This restriction does not apply to Bytes or IntraData payloads.listen() more than once is fatal. The subscriber must be initialised before the first call to listen().| callback | void(const MsgT&) invoked for each received message. |
true if the callback was installed successfully.
|
inline |
|
inline |
Toggles per-message latency and sample-loss measurement.
| enable | true to begin tracking; false to stop. |
|
inlineoverridevirtual |
Enables or disables manual-unloan mode for zero-copy receives.
In manual-unloan mode the user must call return_loan() after consuming each delivered buffer. Only relevant on loan-capable transports (shm://, Zenoh with SHM, etc.).
| manual_unloan | true to enable manual return; false for auto-return. |
重载 vlink::Node< SubscriberImpl, SecurityType::kWithoutSecurity > .
|
staticconstexpr |
Node role tag (kSubscriber).
|
staticconstexpr |
Codec resolved from MsgT.