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>
110 return impl_->suspend();
113 template <
typename ImplT, SecurityType SecT>
115 return impl_->resume();
118 template <
typename ImplT, SecurityType SecT>
120 return impl_->is_suspend();
123 template <
typename ImplT, SecurityType SecT>
125 return impl_->attach(message_loop);
128 template <
typename ImplT, SecurityType SecT>
130 return impl_->detach();
133 template <
typename ImplT, SecurityType SecT>
135 return impl_->get_message_loop();
138 template <
typename ImplT, SecurityType SecT>
140 return impl_->interrupt();
143 template <
typename ImplT, SecurityType SecT>
145 return impl_->get_abstract_node();
148 template <
typename ImplT, SecurityType SecT>
150 return impl_->get_status(type);
153 template <
typename ImplT, SecurityType SecT>
155 impl_->register_status_handler(std::move(callback));
158 template <
typename ImplT, SecurityType SecT>
160 impl_->set_property(prop, value);
163 template <
typename ImplT, SecurityType SecT>
165 return impl_->get_property(prop);
168 template <
typename ImplT, SecurityType SecT>
170 return impl_->transport_type;
173 template <
typename ImplT, SecurityType SecT>
178 template <
typename ImplT, SecurityType SecT>
181 VLOG_F(
"Node: Intra type does not support record.");
185 impl_->set_record_path(path);
188 template <
typename ImplT, SecurityType SecT>
190 auto next_schema_type = impl_->schema_type;
192 if (ser_type.empty()) {
195 next_schema_type = schema_type;
200 next_schema_type = inferred_schema_type;
206 const bool ser_changed = impl_->ser_type != ser_type;
207 const bool schema_changed = impl_->schema_type != next_schema_type;
210 if VLIKELY (!ser_changed && !schema_changed) {
214 const bool has_inited = has_inited_.load(std::memory_order_acquire);
216 (impl_->is_cdr_type != next_is_cdr_type || (impl_->is_cdr_type && ser_changed))) {
218 "Node: DDS raw/CDR mode and CDR type name cannot be changed while initialised; call "
219 "deinit() before changing serialization metadata.");
222 if VUNLIKELY (ser_changed && !impl_->ser_type.empty() && !ser_type.empty()) {
223 CLOG_W(
"Node: Enforce serialization type [%s] => [%s].", impl_->ser_type.c_str(), ser_type.c_str());
228 CLOG_W(
"Node: Enforce schema type [%d] => [%d].",
static_cast<int>(impl_->schema_type),
229 static_cast<int>(next_schema_type));
236 impl_->ser_type = ser_type;
237 impl_->schema_type = next_schema_type;
240 impl_->is_cdr_type = next_is_cdr_type;
242 if (impl_->is_resp_type) {
243 impl_->is_resp_cdr_type = next_is_cdr_type;
253 template <
typename ImplT, SecurityType SecT>
255 return impl_->ser_type;
258 template <
typename ImplT, SecurityType SecT>
260 return impl_->schema_type;
263 template <
typename ImplT, SecurityType SecT>
265 if VUNLIKELY (has_inited_.load(std::memory_order_acquire)) {
267 impl_->set_discovery_enabled(enable);
270 impl_->set_discovery_enabled(enable);
274 template <
typename ImplT, SecurityType SecT>
276 return impl_->get_discovery_enabled();
279 template <
typename ImplT, SecurityType SecT>
281 proto_arena_ = proto_arena;
284 template <
typename ImplT, SecurityType SecT>
287 return impl_->profiler->get();
293 template <
typename ImplT, SecurityType SecT>
295 return quit_mtx_.has_value();
298 template <
typename ImplT, SecurityType SecT>
301 if (!quit_mtx_.has_value()) {
305 if (quit_mtx_.has_value()) {
311 template <
typename ImplT, SecurityType SecT>
313 impl_->set_ssl_options(options);
316 template <
typename ImplT, SecurityType SecT>
318 static_assert(std::is_base_of_v<NodeImpl, ImplT>,
"ImplT must be derived from NodeImpl.");
321 template <
typename ImplT, SecurityType SecT>
326 template <
typename ImplT, SecurityType SecT>
330 return enable_security(std::move(sec_cfg));
333 template <
typename ImplT, SecurityType SecT>
341 if VUNLIKELY (has_inited_.load(std::memory_order_acquire)) {
342 VLOG_W(
"Node::enable_security(): must run before init(); rejected to avoid live-traffic race.");
346 return impl_->enable_security(std::move(cfg));
349 template <
typename ImplT, SecurityType SecT>
350 template <
typename CallbackT,
typename... ArgsT>
353 std::lock_guard quit_lock(quit_mtx_.value());
354 std::invoke(callback, std::forward<ArgsT>(args)...);
356 std::invoke(callback, std::forward<ArgsT>(args)...);
360 template <
typename ImplT, SecurityType SecT>
361 template <
typename TypeT>
364 return std::make_shared<typename TypeT::element_type>();
365 #ifdef VLINK_HAS_PROTOBUF
366 }
else if constexpr (Serializer::is_proto_ptr_type<TypeT>()) {
368 return google::protobuf::Arena::Create<std::remove_pointer_t<TypeT>>(
369 static_cast<google::protobuf::Arena*
>(this->proto_arena_));
372 VLOG_F(
"Node: Proto arena is not bound, url: ", this->impl_->url,
".");
376 }
else if constexpr (std::is_default_constructible_v<TypeT>) {
379 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:132
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:159
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:189
bool attach(class MessageLoop *message_loop)
Attaches the node to a MessageLoop for callback dispatch.
Definition: node-inl.h:124
SchemaType get_schema_type() const
Returns the current coarse schema family.
Definition: node-inl.h:259
virtual void interrupt()
Aborts any blocking wait on this node.
Definition: node-inl.h:139
bool enable_security(const Security::Config &cfg)
Installs a Security configuration before transport initialisation.
Definition: node-inl.h:327
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:114
const std::string & get_ser_type() const
Returns the current concrete runtime type identifier.
Definition: node-inl.h:254
void invoke_callback(const CallbackT &callback, ArgsT &&... args)
Definition: node-inl.h:351
void set_safety_quit(bool safety_quit)
Enables or disables safe-quit mode.
Definition: node-inl.h:299
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:275
bool suspend()
Suspends message delivery on this node.
Definition: node-inl.h:109
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:179
void register_status_handler(StatusCallback &&callback)
Registers a handler invoked whenever the node's status changes.
Definition: node-inl.h:154
bool is_suspend() const
Reports whether the node is currently suspended.
Definition: node-inl.h:119
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:174
virtual ~Node()
Definition: node-inl.h:322
void bind_proto_arena(void *proto_arena)
Binds a Protobuf Arena for arena-allocated message objects.
Definition: node-inl.h:280
bool get_safety_quit() const
Reports whether safe-quit mode is currently active.
Definition: node-inl.h:294
TypeT get_default_value()
Definition: node-inl.h:362
class MessageLoop * get_message_loop() const
Returns the MessageLoop this node is currently attached to.
Definition: node-inl.h:134
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:144
double get_cpu_usage() const
Returns the cumulative CPU-usage ratio sampled by the profiler.
Definition: node-inl.h:285
bool detach()
Detaches the node from its current MessageLoop.
Definition: node-inl.h:129
std::string get_property(const std::string &prop) const
Retrieves a previously set transport-specific property value.
Definition: node-inl.h:164
Status::BasePtr get_status(Status::Type type) const
Retrieves the current status object for the requested category.
Definition: node-inl.h:149
TransportType get_transport_type() const
Returns the TransportType this node is bound to.
Definition: node-inl.h:169
void set_discovery_enabled(bool enable)
Toggles peer-discovery on this node.
Definition: node-inl.h:264
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:317
void set_ssl_options(const SslOptions &options)
Configures transport-layer SSL/TLS encryption for this node.
Definition: node-inl.h:312
#define VLOG_F(...)
Definition: logger.h:843
#define VLOG_W(...)
Definition: logger.h:839
#define CLOG_W(...)
Definition: logger.h:851
#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:203
@ kUnknown
Decoding family unknown.
@ kZeroCopy
Decode through the VLink zero-copy structs.
@ kRaw
Treat the payload as opaque bytes.
@ kCdr
Native DDS CDR payload including its encapsulation header.
TransportType
Enumeration of every transport backend recognised by VLink.
Definition: types.h:126
@ kDds
Fast-DDS RTPS (dds://).
@ kIntra
In-process queue (intra://).
@ kWithSecurity
Encrypted and authenticated transport.
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:452
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:381
#define VLINK_HAS_MEMBER(T, member)
Macro Definitions.
Definition: traits.h:316
#define VLINK_VERSION_PATCH
Definition: version.h:94
#define VLINK_VERSION_MAJOR
Definition: version.h:92
#define VLINK_VERSION_MINOR
Definition: version.h:93