31 #include "../base/logger.h"
32 #include "../impl/types.h"
34 #include "../version.h"
38 template <
typename ImplT, SecurityType SecT>
42 VLOG_F(
"Node::init(): security node has no usable Security; check Security::Config. url: ", impl_->url);
46 bool expected =
false;
48 if VUNLIKELY (!has_inited_.compare_exchange_strong(expected,
true, std::memory_order_acq_rel,
49 std::memory_order_relaxed)) {
58 is_support_loan_ = impl_->is_support_loan();
63 template <
typename ImplT, SecurityType SecT>
67 if VUNLIKELY (!has_inited_.compare_exchange_strong(expected,
false, std::memory_order_acq_rel,
68 std::memory_order_relaxed)) {
74 if (quit_mtx_.has_value()) {
75 std::lock_guard quit_lock(quit_mtx_.value());
86 template <
typename ImplT, SecurityType SecT>
88 return has_inited_.load(std::memory_order_acquire);
91 template <
typename ImplT, SecurityType SecT>
93 return impl_->is_support_loan();
96 template <
typename ImplT, SecurityType SecT>
98 Bytes bytes = impl_->loan(size);
103 template <
typename ImplT, SecurityType SecT>
105 return impl_->return_loan(bytes);
108 template <
typename ImplT, SecurityType SecT>
111 VLOG_W(
"Node: Function [set_manual_unloan] is not supported.");
114 template <
typename ImplT, SecurityType SecT>
116 return is_manual_unloan_;
119 template <
typename ImplT, SecurityType SecT>
121 return impl_->suspend();
124 template <
typename ImplT, SecurityType SecT>
126 return impl_->resume();
129 template <
typename ImplT, SecurityType SecT>
131 return impl_->is_suspend();
134 template <
typename ImplT, SecurityType SecT>
136 return impl_->attach(message_loop);
139 template <
typename ImplT, SecurityType SecT>
141 return impl_->detach();
144 template <
typename ImplT, SecurityType SecT>
146 return impl_->get_message_loop();
149 template <
typename ImplT, SecurityType SecT>
151 return impl_->interrupt();
154 template <
typename ImplT, SecurityType SecT>
156 return impl_->get_abstract_node();
159 template <
typename ImplT, SecurityType SecT>
161 return impl_->get_status(type);
164 template <
typename ImplT, SecurityType SecT>
166 impl_->register_status_handler(std::move(callback));
169 template <
typename ImplT, SecurityType SecT>
171 impl_->set_property(prop, value);
174 template <
typename ImplT, SecurityType SecT>
176 return impl_->get_property(prop);
179 template <
typename ImplT, SecurityType SecT>
181 return impl_->transport_type;
184 template <
typename ImplT, SecurityType SecT>
189 template <
typename ImplT, SecurityType SecT>
193 VLOG_F(
"Node: Intra or Dds(cdr) type does not support record.");
197 impl_->set_record_path(path);
200 template <
typename ImplT, SecurityType SecT>
202 auto next_schema_type = impl_->schema_type;
204 if (ser_type.empty()) {
207 next_schema_type = schema_type;
212 next_schema_type = inferred_schema_type;
218 const bool ser_changed = impl_->ser_type != ser_type;
219 const bool schema_changed = impl_->schema_type != next_schema_type;
221 if VLIKELY (!ser_changed && !schema_changed) {
225 if VUNLIKELY (ser_changed && !impl_->ser_type.empty() && !ser_type.empty()) {
226 CLOG_W(
"Node: Enforce serialization type [%s] => [%s].", impl_->ser_type.c_str(), ser_type.c_str());
231 CLOG_W(
"Node: Enforce schema type [%d] => [%d].",
static_cast<int>(impl_->schema_type),
232 static_cast<int>(next_schema_type));
235 if VUNLIKELY (has_inited_.load(std::memory_order_acquire)) {
239 impl_->ser_type = ser_type;
240 impl_->schema_type = next_schema_type;
242 if VUNLIKELY (has_inited_.load(std::memory_order_acquire)) {
247 template <
typename ImplT, SecurityType SecT>
249 return impl_->ser_type;
252 template <
typename ImplT, SecurityType SecT>
254 return impl_->schema_type;
257 template <
typename ImplT, SecurityType SecT>
259 if VUNLIKELY (has_inited_.load(std::memory_order_acquire)) {
261 impl_->set_discovery_enabled(enable);
264 impl_->set_discovery_enabled(enable);
268 template <
typename ImplT, SecurityType SecT>
270 return impl_->get_discovery_enabled();
273 template <
typename ImplT, SecurityType SecT>
275 proto_arena_ = proto_arena;
278 template <
typename ImplT, SecurityType SecT>
281 return impl_->profiler->get();
287 template <
typename ImplT, SecurityType SecT>
289 return quit_mtx_.has_value();
292 template <
typename ImplT, SecurityType SecT>
295 if (!quit_mtx_.has_value()) {
299 if (quit_mtx_.has_value()) {
305 template <
typename ImplT, SecurityType SecT>
307 impl_->set_ssl_options(options);
310 template <
typename ImplT, SecurityType SecT>
312 static_assert(std::is_base_of_v<NodeImpl, ImplT>,
"ImplT must be derived from NodeImpl.");
315 template <
typename ImplT, SecurityType SecT>
320 template <
typename ImplT, SecurityType SecT>
324 return enable_security(std::move(sec_cfg));
327 template <
typename ImplT, SecurityType SecT>
335 if VUNLIKELY (has_inited_.load(std::memory_order_acquire)) {
336 VLOG_W(
"Node::enable_security(): must run before init(); rejected to avoid live-traffic race.");
340 return impl_->enable_security(std::move(cfg));
343 template <
typename ImplT, SecurityType SecT>
344 template <
typename CallbackT,
typename... ArgsT>
347 std::lock_guard quit_lock(quit_mtx_.value());
348 std::invoke(callback, std::forward<ArgsT>(args)...);
350 std::invoke(callback, std::forward<ArgsT>(args)...);
354 template <
typename ImplT, SecurityType SecT>
355 template <
typename TypeT>
358 return std::make_shared<typename TypeT::element_type>();
359 }
else if constexpr (Serializer::is_proto_ptr_type<TypeT>()) {
360 if VLIKELY (this->proto_arena_) {
361 return google::protobuf::Arena::Create<std::remove_pointer_t<TypeT>>(
365 VLOG_F(
"Node: Proto arena is not bound, url: ", this->impl_->url,
".");
368 }
else if constexpr (std::is_default_constructible_v<TypeT>) {
371 static_assert(Traits::ExpectFalse<TypeT>(),
"TypeT is not default constructible.");
Tiny mix-in that exposes the backend-native handle behind a node.
Definition: node_impl.h:123
Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs.
Definition: bytes.h:120
Copyable type-erased callable analogue of std::function with a tunable SBO and pool spill.
Definition: functional.h:131
Serial task dispatcher with selectable queue backend and bounded timer registry.
Definition: message_loop.h:126
void set_property(const std::string &prop, const std::string &value)
Sets a transport-specific string-keyed property.
Definition: node-inl.h:170
void set_ser_type(const std::string &ser_type, SchemaType schema_type=SchemaType::kUnknown)
Overrides the runtime wire-metadata identifiers for this node.
Definition: node-inl.h:201
bool attach(class MessageLoop *message_loop)
Attaches the node to a MessageLoop for callback dispatch.
Definition: node-inl.h:135
SchemaType get_schema_type() const
Returns the current coarse schema family.
Definition: node-inl.h:253
virtual void interrupt()
Aborts any blocking wait on this node.
Definition: node-inl.h:150
bool enable_security(const Security::Config &cfg)
Installs a Security configuration before transport initialisation.
Definition: node-inl.h:321
bool has_inited() const
Reports whether init() has been successfully called.
Definition: node-inl.h:87
bool resume()
Resumes message delivery after a prior suspend().
Definition: node-inl.h:125
const std::string & get_ser_type() const
Returns the current concrete runtime type identifier.
Definition: node-inl.h:248
void invoke_callback(const CallbackT &callback, ArgsT &&... args)
Definition: node-inl.h:345
void set_safety_quit(bool safety_quit)
Enables or disables safe-quit mode.
Definition: node-inl.h:293
bool is_support_loan() const
Reports whether the transport supports zero-copy loaned buffers.
Definition: node-inl.h:92
bool get_discovery_enabled() const
Reports whether peer-discovery is currently enabled.
Definition: node-inl.h:269
bool suspend()
Suspends message delivery on this node.
Definition: node-inl.h:120
virtual bool init()
Initialises the node and its transport back-end.
Definition: node-inl.h:39
void set_record_path(const std::string &path)
Enables recording of inbound or outbound messages to a bag file.
Definition: node-inl.h:190
void register_status_handler(StatusCallback &&callback)
Registers a handler invoked whenever the node's status changes.
Definition: node-inl.h:165
bool is_suspend() const
Reports whether the node is currently suspended.
Definition: node-inl.h:130
virtual void set_manual_unloan(bool manual_unloan)
Toggles manual-unloan mode for zero-copy receives.
Definition: node-inl.h:109
virtual bool deinit()
Tears the node down and releases all transport resources.
Definition: node-inl.h:64
const std::string & get_url() const
Returns the URL string used to construct this node.
Definition: node-inl.h:185
virtual ~Node()
Definition: node-inl.h:316
void bind_proto_arena(void *proto_arena)
Binds a Protobuf Arena for arena-allocated message objects.
Definition: node-inl.h:274
bool get_safety_quit() const
Reports whether safe-quit mode is currently active.
Definition: node-inl.h:288
TypeT get_default_value()
Definition: node-inl.h:356
virtual bool is_manual_unloan() const
Reports whether manual-unloan mode is currently active.
Definition: node-inl.h:115
class MessageLoop * get_message_loop() const
Returns the MessageLoop this node is currently attached to.
Definition: node-inl.h:145
Bytes loan(int64_t size)
Allocates a loaned buffer from the transport memory pool.
Definition: node-inl.h:97
const AbstractNode * get_abstract_node() const
Returns the abstract-graph handle for runtime topology inspection.
Definition: node-inl.h:155
double get_cpu_usage() const
Returns the cumulative CPU-usage ratio sampled by the profiler.
Definition: node-inl.h:279
bool detach()
Detaches the node from its current MessageLoop.
Definition: node-inl.h:140
std::string get_property(const std::string &prop) const
Retrieves a previously set transport-specific property value.
Definition: node-inl.h:175
Status::BasePtr get_status(Status::Type type) const
Retrieves the current status object for the requested category.
Definition: node-inl.h:160
TransportType get_transport_type() const
Returns the TransportType this node is bound to.
Definition: node-inl.h:180
void set_discovery_enabled(bool enable)
Toggles peer-discovery on this node.
Definition: node-inl.h:258
bool return_loan(const Bytes &bytes)
Returns a previously loaned buffer to the transport pool.
Definition: node-inl.h:104
Node()
Definition: node-inl.h:311
void set_ssl_options(const SslOptions &options)
Configures transport-layer SSL/TLS encryption for this node.
Definition: node-inl.h:306
#define VLOG_F(...)
Definition: logger.h:791
#define VLOG_W(...)
Definition: logger.h:787
#define CLOG_W(...)
Definition: logger.h:799
#define VUNLIKELY(...)
Short alias for VLINK_UNLIKELY.
Definition: macros.h:289
#define VLIKELY(...)
Short alias for VLINK_LIKELY.
Definition: macros.h:284
Type
Discriminator that identifies the concrete Base subclass carried by an event.
Definition: status.h:118
std::shared_ptr< Status::Base > BasePtr
Shared-pointer alias used as the parameter type of every status callback.
Definition: status.h:251
SchemaType
Coarse runtime schema family used by discovery, bag metadata and proxy routing.
Definition: types.h:207
@ kUnknown
Decoding family unknown.
@ kZeroCopy
Decode through the VLink zero-copy structs.
@ kRaw
Treat the payload as opaque bytes.
TransportType
Enumeration of every transport backend recognised by VLink.
Definition: types.h:128
@ kDds
Fast-DDS RTPS (dds://).
@ kIntra
In-process queue (intra://).
@ kWithSecurity
Encrypted and authenticated transport.
Definition: serializer-inl.h:101
static constexpr SchemaType infer_ser_type(std::string_view ser_type) noexcept
Infers a coarse schema family from a concrete ser_type string.
Definition: types.h:456
static bool is_real_type(SchemaType schema_type) noexcept
Returns whether schema_type carries concrete schema metadata.
static bool is_valid_type(SchemaType schema_type) noexcept
Returns whether schema_type is within the supported enum range.
Aggregate of every parameter accepted by the Security constructor.
Definition: security.h:164
Aggregate of SSL / TLS settings for transport-layer encryption.
Definition: ssl_options.h:119
Detects whether T is (or derives from) a std::shared_ptr specialisation.
Definition: traits.h:193
Semantic version number with comparison and string-conversion helpers.
Definition: types.h:385
#define VLINK_VERSION_PATCH
Definition: version.h:94
#define VLINK_VERSION_MAJOR
Definition: version.h:92
#define VLINK_VERSION_MINOR
Definition: version.h:93