VLink  2.0.0
A high-performance communication middleware
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 Transport-neutral base class for every field-model setter (latest-value writer).
27  *
28  * @details
29  * This is an internal implementation header used by the public @c Setter
30  * template; applications should depend on @c setter.h. @c SetterImpl extends
31  * @c NodeImpl with the field-model write semantics: writing overwrites the
32  * topic's single tracked value and the backend may notify the setter via a
33  * sync callback when a late getter needs the cached value resent.
34  *
35  * @par ImplType
36  * The constructor stamps @c impl_type with @c kSetter so the discovery and
37  * recording layers correctly identify outgoing field updates.
38  *
39  * @par Lifecycle
40  * - Constructed by the matching @c Conf::create_setter().
41  * - @c init() / @c deinit() inherited from @c NodeImpl bring the transport up.
42  * - @c sync() is invoked by the public @c Setter once the user wires a
43  * late-getter sync callback.
44  * - @c write() pushes the serialised value to all matched getters.
45  *
46  * @par Role table
47  * | Capability | Provider |
48  * | --------------------------- | ----------------------------------------- |
49  * | Wire write | Subclass override of @c write() |
50  * | Late-getter resend | Subclass override of @c sync() |
51  *
52  * @par Internal API contract
53  * | Method | Default | Subclass duty |
54  * | ------------------------------- | -------------- | ------------------------ |
55  * | @c write(const Bytes&) | Pure virtual | Push frame to transport |
56  * | @c sync(SyncCallback&&) | Pure virtual | Bind late-join callback |
57  */
58 
59 #pragma once
60 
61 #include "./node_impl.h"
62 
63 namespace vlink {
64 
65 /**
66  * @class SetterImpl
67  * @brief Field-model writer base shared by every transport-specific setter.
68  *
69  * @details
70  * Backends override @c write() to dispatch the serialised value onto the
71  * transport and @c sync() to receive the transport-specific late-join
72  * notification so the public @c Setter can resend its cached value.
73  */
75  public:
76  /**
77  * @brief Releases backend resources.
78  */
79  ~SetterImpl() override;
80 
81  /**
82  * @brief Writes a new value to every reachable getter.
83  *
84  * @details
85  * Pure virtual. @p msg_data is produced by @c Serializer::serialize() in the
86  * public layer; the call overwrites any previously stored value on the topic.
87  *
88  * @param msg_data Serialised value bytes.
89  */
90  virtual void write(const Bytes& msg_data) = 0;
91 
92  /**
93  * @brief Installs the transport-specific late-getter sync callback.
94  *
95  * @details
96  * Pure virtual. Backends that detect a freshly attached getter invoke
97  * @p callback so the public @c Setter can resend the cached latest value;
98  * transports without such a signal may simply discard the callback.
99  *
100  * @param callback Callable invoked when a late-getter sync is requested.
101  */
102  virtual void sync(SyncCallback&& callback) = 0;
103 
104  protected:
105  /**
106  * @brief Stamps the node as @c kSetter.
107  */
109 
110  private:
112 };
113 
114 } // namespace vlink
#define VLINK_EXPORT
Definition: macros.h:81
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition: macros.h:174
Foundational base classes shared by every transport-backed VLink node.