VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
setter_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 by Thun Lu. All rights reserved.
3 * Author: Thun Lu <thun.lu@zohomail.cn>
4 * Repo: https://github.com/thun-res/vlink
5 * _ __ __ _ __
6 * | | / / / / (_) ____ / /__
7 * | | / / / / / / / __ \ / //_/
8 * | |/ / / /___ / / / / / / / ,<
9 * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/**
25 * @file setter_impl.h
26 * @brief Abstract base class for all transport-specific setter (field writer) implementations.
27 *
28 * @details
29 * @c SetterImpl is the intermediate layer between the generic @c Setter<T> template
30 * and a concrete transport backend. It inherits from @c NodeImpl and adds
31 * field-setter semantics:
32 *
33 * - Value write via @c write() -- sends the serialised latest value to all registered
34 * getters on the same topic.
35 * - Synchronous notification via @c sync() -- waits for the written value to be
36 * acknowledged or propagated, then fires a completion callback.
37 *
38 * @par Field Model Overview
39 * Unlike the event model (publish/subscribe), the field model maintains a single
40 * "latest value" per topic. A @c Setter always overwrites the previous value; a
41 * @c Getter can retrieve the most recent value at any time or be notified when it
42 * changes.
43 *
44 * @note Concrete subclasses must implement @c write(const Bytes&) and
45 * @c sync(SyncCallback&&).
46 */
47
48#pragma once
49
50#include "./node_impl.h"
51
52namespace vlink {
53
54/**
55 * @class SetterImpl
56 * @brief Transport-agnostic base for setter (field writer) node implementations.
57 *
58 * @details
59 * Concrete backends override @c write() to push the serialised value onto the
60 * transport and @c sync() to provide a completion notification after the value
61 * has been accepted by the underlying transport.
62 */
64 public:
65 /**
66 * @brief Destructor.
67 */
68 ~SetterImpl() override;
69
70 /**
71 * @brief Writes a new field value to all connected getter nodes.
72 *
73 * @details
74 * Must be implemented by each concrete transport backend. @p msg_data contains
75 * the fully serialised latest value produced by @c Serializer::serialize().
76 * The write overwrites any previously stored value on the topic.
77 *
78 * @param msg_data Serialised field value bytes to transmit.
79 */
80 virtual void write(const Bytes& msg_data) = 0;
81
82 /**
83 * @brief Waits for the most recently written value to be propagated, then fires
84 * the completion callback.
85 *
86 * @details
87 * Must be implemented by each concrete transport backend. The exact semantics
88 * depend on the transport: some backends fire the callback immediately after the
89 * write is queued; others wait until the value has been acknowledged by all
90 * connected getters.
91 *
92 * @param callback Callable invoked once the synchronisation is complete.
93 */
94 virtual void sync(SyncCallback&& callback) = 0;
95
96 protected:
97 /**
98 * @brief Protected constructor; initialises the setter with @c kSetter role.
99 */
101
102 private:
104};
105
106} // namespace vlink
#define VLINK_EXPORT
Definition macros.h:85
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition macros.h:184
Abstract transport node base classes used by all VLink node implementations.