30 #include "../base/cpu_profiler_guard.h"
31 #include "../base/logger.h"
32 #include "../impl/url.h"
33 #include "../serializer.h"
34 #include "../setter.h"
38 template <
typename ValueT, SecurityType SecT>
41 return std::make_unique<Setter<ValueT, SecT>>(url_str, type);
44 template <
typename ValueT, SecurityType SecT>
47 return std::make_shared<Setter<ValueT, SecT>>(url_str, type);
50 template <
typename ValueT, SecurityType SecT>
51 template <
typename ConfT,
typename>
53 static_assert(ConfT::get_allow_impl_type() & kImplType,
"Conf does not support setter mode.");
55 if VUNLIKELY (!conf.parse(kImplType) || !conf.is_valid()) {
56 VLOG_F(conf,
" setter configuration is invalid or could not be parsed.");
60 this->impl_ = conf.create_setter();
63 VLOG_F(conf,
" setter implementation not available for this transport.");
67 this->impl_->transport_type = conf.get_transport_type();
68 this->impl_->ser_type = Serializer::get_serialized_type<kValueType, ValueT>();
69 this->impl_->schema_type = Serializer::get_schema_type<kValueType, ValueT>();
70 this->impl_->is_cdr_type = Serializer::is_cdr_type<ValueT>();
72 if constexpr (std::is_same_v<ConfT, Url>) {
73 this->impl_->url = conf.get_str();
77 this->impl_->is_security_type =
true;
85 template <
typename ValueT, SecurityType SecT>
87 :
Setter<ValueT, SecT>(
Url(url_str), type) {}
89 template <
typename ValueT, SecurityType SecT>
95 template <
typename ValueT, SecurityType SecT>
101 this->impl_->sync([
this]() {
102 std::optional<ValueT> snapshot;
104 std::lock_guard lock(mtx_);
108 if VLIKELY (snapshot.has_value()) {
109 write(snapshot.value());
116 template <
typename ValueT, SecurityType SecT>
121 template <
typename ValueT, SecurityType SecT>
123 #ifndef VLINK_DISABLE_PROFILER
128 std::lock_guard lock(mtx_);
129 value_.emplace(value);
132 if VUNLIKELY (!this->has_inited_.load(std::memory_order_acquire)) {
139 template <
typename ValueT, SecurityType SecT>
141 if VUNLIKELY (this->has_inited_.load(std::memory_order_acquire)) {
142 this->impl_->deinit_ext();
144 this->impl_->init_ext();
150 template <
typename ValueT, SecurityType SecT>
152 if constexpr (std::is_same_v<ValueT, Bytes>) {
158 if (this->is_support_loan_) {
159 size_t ser_size = Serializer::get_serialized_size<kValueType>(value);
161 msg_data = this->impl_->loan(ser_size);
169 if VUNLIKELY (!Serializer::serialize<kValueType>(value, msg_data, this->impl_->transport_type)) {
170 VLOG_T(
"Setter serialize failed, url: ", this->impl_->url,
".");
173 if (this->is_support_loan_) {
174 this->impl_->return_loan(msg_data);
181 write_bytes(msg_data);
185 template <
typename ValueT, SecurityType SecT>
190 if VUNLIKELY (!this->impl_->security || !this->impl_->security->encrypt(data, sec_data)) {
191 VLOG_T(
"Setter encrypt failed, url: ", this->impl_->url,
".");
195 this->impl_->write(sec_data);
199 this->impl_->write(data);
203 template <
typename ValueT>
204 template <
typename SecurityConfigT>
206 SecurityConfigT&& sec_cfg,
208 static_assert(std::is_same_v<std::decay_t<SecurityConfigT>,
Security::Config>,
209 "SecurityConfigT must be Security::Config.");
211 return std::make_unique<SecuritySetter<ValueT>>(url_str, std::forward<SecurityConfigT>(sec_cfg), type);
214 template <
typename ValueT>
215 template <
typename SecurityConfigT>
217 SecurityConfigT&& sec_cfg,
219 static_assert(std::is_same_v<std::decay_t<SecurityConfigT>,
Security::Config>,
220 "SecurityConfigT must be Security::Config.");
222 return std::make_shared<SecuritySetter<ValueT>>(url_str, std::forward<SecurityConfigT>(sec_cfg), type);
225 template <
typename ValueT>
226 template <
typename ConfT,
typename SecurityConfigT,
typename>
229 static_assert(std::is_same_v<std::decay_t<SecurityConfigT>,
Security::Config>,
230 "SecurityConfigT must be Security::Config.");
239 template <
typename ValueT>
240 template <
typename SecurityConfigT>
243 static_assert(std::is_same_v<std::decay_t<SecurityConfigT>,
Security::Config>,
244 "SecurityConfigT must be Security::Config.");
Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs.
Definition: bytes.h:120
bool empty() const noexcept
Reports whether the buffer is logically empty.
Definition: bytes.h:861
Scope guard that opens and closes a CpuProfiler active interval.
Definition: cpu_profiler_guard.h:80
Transport-agnostic CRTP base for all VLink communication primitives.
Definition: node.h:164
bool enable_security(const Security::Config &cfg)
Installs a Security configuration before transport initialisation.
Definition: node-inl.h:321
virtual bool deinit()
Tears the node down and releases all transport resources.
Definition: node-inl.h:64
SecuritySetter(const ConfT &conf, SecurityConfigT &&sec_cfg={}, InitType type=InitType::kWithInit)
Constructs a SecuritySetter from a typed configuration object.
Definition: setter-inl.h:227
std::shared_ptr< SecuritySetter< ValueT > > SharedPtr
Owning shared-pointer alias.
Definition: setter.h:247
std::unique_ptr< SecuritySetter< ValueT > > UniquePtr
Owning unique-pointer alias.
Definition: setter.h:246
static SharedPtr create_shared(const std::string &url_str, SecurityConfigT &&sec_cfg={}, InitType type=InitType::kWithInit)
Heap-allocates a SecuritySetter and wraps it in a std::shared_ptr.
Definition: setter-inl.h:216
static UniquePtr create_unique(const std::string &url_str, SecurityConfigT &&sec_cfg={}, InitType type=InitType::kWithInit)
Heap-allocates a SecuritySetter and wraps it in a std::unique_ptr.
Definition: setter-inl.h:205
Type-safe latest-value writer for the VLink field communication model.
Definition: setter.h:113
std::shared_ptr< Setter< ValueT, SecT > > SharedPtr
Owning shared-pointer alias.
Definition: setter.h:116
static SharedPtr create_shared(const std::string &url_str, InitType type=InitType::kWithInit)
Heap-allocates a Setter and wraps it in a std::shared_ptr.
Definition: setter-inl.h:45
void set(const ValueT &value)
Writes a new field value and emits it to every connected Getter.
Definition: setter-inl.h:122
bool init() override
Initialises the setter and registers the late-getter sync() hook.
Definition: setter-inl.h:96
void mark_as_publisher()
Promotes this setter to behave as a Publisher at the transport layer.
Definition: setter-inl.h:140
bool deinit() override
Deinitialises the setter and releases the underlying transport resources.
Definition: setter-inl.h:117
static UniquePtr create_unique(const std::string &url_str, InitType type=InitType::kWithInit)
Heap-allocates a Setter and wraps it in a std::unique_ptr.
Definition: setter-inl.h:39
Setter(const ConfT &conf, InitType type=InitType::kWithInit)
Constructs a setter from a typed transport configuration object.
Definition: setter-inl.h:52
~Setter() override
Destroys the setter and drains in-flight transport callbacks.
Definition: setter-inl.h:90
std::unique_ptr< Setter< ValueT, SecT > > UniquePtr
Owning unique-pointer alias.
Definition: setter.h:115
#define VLOG_F(...)
Definition: logger.h:791
#define VLOG_T(...)
Definition: logger.h:781
#define VUNLIKELY(...)
Short alias for VLINK_UNLIKELY.
Definition: macros.h:289
#define VLIKELY(...)
Short alias for VLINK_LIKELY.
Definition: macros.h:284
InitType
Selects between immediate and deferred node initialisation.
Definition: types.h:154
@ kWithoutInit
Defer initialisation; call init() manually.
@ kWithInit
Initialise immediately in the constructor.
@ kSet
Value written by a Setter node.
@ kPublisher
Event publisher (one-to-many broadcast).
Definition: types.h:114
SecurityType
Compile-time selector for the per-node message security variant.
Definition: types.h:172
@ kWithSecurity
Encrypted and authenticated transport.
Aggregate of every parameter accepted by the Security constructor.
Definition: security.h:164
Conf subclass that routes virtual calls to the transport selected by a URL string.
Definition: url.h:213