37template <
typename ValueT, SecurityType SecT>
40 return std::make_unique<Setter<ValueT, SecT>>(url_str, type);
43template <
typename ValueT, SecurityType SecT>
46 return std::make_shared<Setter<ValueT, SecT>>(url_str, type);
49template <
typename ValueT, SecurityType SecT>
50template <
typename ConfT,
typename>
52 static_assert(ConfT::get_allow_impl_type() &
kImplType,
"Conf does not support setter mode.");
55 VLOG_F(conf,
" setter configuration is invalid or could not be parsed.");
59 this->
impl_ = conf.create_setter();
62 VLOG_F(conf,
" setter implementation not available for this transport.");
66 this->
impl_->transport_type = conf.get_transport_type();
68 this->
impl_->schema_type = Serializer::get_schema_type<kValueType, ValueT>();
71 if constexpr (std::is_same_v<ConfT, Url>) {
72 this->
impl_->url = conf.get_str();
76 this->
impl_->is_security_type =
true;
85template <
typename ValueT, SecurityType SecT>
87 :
Setter<ValueT, SecT>(
Url(url_str), type) {}
89template <
typename ValueT, SecurityType SecT>
95 this->
impl_->sync([
this]() {
96 if VLIKELY (value_.has_value()) {
97 write(value_.value());
104template <
typename ValueT, SecurityType SecT>
109template <
typename ValueT, SecurityType SecT>
111#ifndef VLINK_DISABLE_PROFILER
116 std::lock_guard lock(mtx_);
117 value_.emplace(value);
123template <
typename ValueT, SecurityType SecT>
126 this->
impl_->deinit_ext();
128 this->
impl_->init_ext();
134template <
typename ValueT, SecurityType SecT>
135inline void Setter<ValueT, SecT>::write(
const ValueT& value) {
136 if constexpr (std::is_same_v<ValueT, Bytes>) {
145 msg_data = this->
impl_->loan(ser_size);
154 VLOG_T(
"Setter serialize failed, url: ", this->impl_->url,
".");
157 if (this->is_support_loan_) {
158 this->impl_->return_loan(msg_data);
165 write_bytes(msg_data);
169template <
typename ValueT, SecurityType SecT>
170inline void Setter<ValueT, SecT>::write_bytes(
const Bytes& data) {
175 VLOG_T(
"Setter encrypt failed, url: ", this->
impl_->url,
".");
179 this->
impl_->write(sec_data);
183 this->impl_->write(data);
Versatile 128-byte byte buffer with SBO, five ownership modes and compression helpers.
Definition bytes.h:113
bool empty() const noexcept
Returns true if the buffer is empty (no data pointer and size == 0).
Definition bytes.h:880
RAII scope guard that brackets a CpuProfiler active interval.
Definition cpu_profiler_guard.h:67
std::unique_ptr< SetterImpl > impl_
Definition node.h:558
virtual bool init()
Initialises the node and its transport back-end.
Definition node-inl.h:39
bool is_support_loan_
Definition node.h:562
virtual bool deinit()
Shuts down the node and releases all transport resources.
Definition node-inl.h:57
std::optional< Security > security_
Definition node.h:559
std::atomic_bool has_inited_
Definition node.h:556
void enable_security()
Definition node-inl.h:332
static SharedPtr create_shared(const std::string &url_str, InitType type=InitType::kWithInit)
Creates a Setter on the heap wrapped in a shared_ptr.
Definition setter-inl.h:44
void set(const ValueT &value)
Writes a new field value and notifies all connected Getter nodes.
Definition setter-inl.h:110
bool init() override
Initializes the setter transport and registers the late-getter sync callback.
Definition setter-inl.h:90
void mark_as_publisher()
Changes this setter's role to kPublisher (event-emitter).
Definition setter-inl.h:124
bool deinit() override
Deinitializes the setter and releases the underlying transport resources.
Definition setter-inl.h:105
std::shared_ptr< Setter< ValueT, SecT > > SharedPtr
Shared-pointer alias.
Definition setter.h:97
static constexpr ImplType kImplType
Node role identifier (kSetter).
Definition setter.h:100
static UniquePtr create_unique(const std::string &url_str, InitType type=InitType::kWithInit)
Creates a Setter on the heap wrapped in a unique_ptr.
Definition setter-inl.h:38
Setter(const ConfT &conf, InitType type=InitType::kWithInit)
Constructs a setter from a typed transport configuration object.
Definition setter-inl.h:51
std::unique_ptr< Setter< ValueT, SecT > > UniquePtr
Unique-pointer alias.
Definition setter.h:94
RAII guard that automatically calls CpuProfiler::begin() and CpuProfiler::end().
Global singleton logger with three output styles and pluggable backends.
#define VLOG_F(...)
Definition logger.h:856
#define VLOG_T(...)
Definition logger.h:846
#define VUNLIKELY(...)
Shorthand alias for VLINK_UNLIKELY. Hints that the expression is unlikely true.
Definition macros.h:302
#define VLIKELY(...)
Shorthand alias for VLINK_LIKELY. Hints that the expression is likely true.
Definition macros.h:297
size_t get_serialized_size(const T &src) noexcept
Returns the exact serialised byte size for a given src value.
Definition serializer-inl.h:295
constexpr bool is_cdr_type() noexcept
Returns true if T is a FastDDS CDR-serialisable type.
Definition serializer-inl.h:648
std::string get_serialized_type() noexcept
Returns the serialisation type name string for T with explicit TypeT.
Definition serializer-inl.h:229
bool serialize(const T &src, Bytes &des, TransportType transport, uint8_t offset)
Serializes src into des with explicit type and transport hints.
Definition serializer-inl.h:355
InitType
Controls whether a node is initialised immediately at construction.
Definition types.h:132
@ kWithInit
Initialise immediately in the constructor.
Definition types.h:134
@ kSet
Field value written by a Setter node.
Definition types.h:170
@ kPublisher
Event publisher (N-to-N broadcast).
Definition types.h:93
@ kWithSecurity
Encrypted and authenticated transport.
Definition types.h:150
Compile-time type-detection and serialisation utilities for VLink messages.
Type-safe field-model writer for VLink topics.
URL-based Conf dispatcher that routes to the correct transport backend.
Definition url.h:161
URL-based transport configuration dispatcher for VLink nodes.