VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
getter_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 getter_impl.h
26 * @brief Abstract base class for all transport-specific getter (field reader) implementations.
27 *
28 * @details
29 * @c GetterImpl is the intermediate layer between the generic @c Getter<T> template
30 * and a concrete transport backend. It inherits from @c NodeImpl and adds
31 * field-getter semantics:
32 *
33 * - Change notification via @c listen() -- the callback is invoked whenever a new
34 * value is written by the corresponding @c Setter on the same topic.
35 * - Optional latency and sample-loss tracking, identical in interface to
36 * @c SubscriberImpl.
37 *
38 * @par Field Model Overview
39 * Unlike the event model, the field model maintains a single "latest value" per
40 * topic. A @c Getter receives the most recent value; it does not buffer a queue
41 * of historic messages.
42 *
43 * @note Concrete subclasses must implement @c listen(MsgCallback&&).
44 */
45
46#pragma once
47
48#include "./node_impl.h"
49
50namespace vlink {
51
52/**
53 * @class GetterImpl
54 * @brief Transport-agnostic base for getter (field reader) node implementations.
55 *
56 * @details
57 * Provides default (no-op) implementations for the optional latency/loss tracking
58 * interface. Concrete transport backends override @c listen(MsgCallback&&) to
59 * register their value-change callback.
60 */
62 public:
63 /**
64 * @brief Destructor.
65 */
66 ~GetterImpl() override;
67
68 /**
69 * @brief Registers the value-change callback for field updates.
70 *
71 * @details
72 * Must be implemented by each concrete transport backend. The callback is
73 * invoked with a @c Bytes buffer containing the serialised latest value each
74 * time the corresponding @c Setter writes a new value. After registration
75 * @c is_listened is set to @c true by the @c Getter<T> layer.
76 *
77 * @param callback Callable @c void(const Bytes&) invoked on each value update.
78 * @return @c true if registration succeeded; @c false on error.
79 */
80 virtual bool listen(MsgCallback&& callback) = 0;
81
82 /**
83 * @brief Enables or disables per-update latency and sample-loss tracking.
84 *
85 * @details
86 * When enabled, the transport backend tracks value timestamps (for latency) and
87 * sequence numbers (for loss detection). The default implementation is a no-op;
88 * transports that support tracking override this method.
89 *
90 * @param enable @c true to enable tracking; @c false to disable.
91 */
92 virtual void set_latency_and_lost_enabled(bool enable);
93
94 /**
95 * @brief Returns whether latency and sample-loss tracking is currently enabled.
96 *
97 * @details
98 * The default implementation always returns @c false. Transports that support
99 * tracking override this to reflect the current enabled state.
100 *
101 * @return @c true if tracking is active; @c false otherwise.
102 */
103 [[nodiscard]] virtual bool is_latency_and_lost_enabled() const;
104
105 /**
106 * @brief Returns the most recently measured end-to-end field update latency in microseconds.
107 *
108 * @details
109 * Only meaningful when @c is_latency_and_lost_enabled() returns @c true. The
110 * default implementation returns @c 0.
111 *
112 * @return Latency in microseconds, or @c 0 if tracking is disabled or unsupported.
113 */
114 [[nodiscard]] virtual int64_t get_latency() const;
115
116 /**
117 * @brief Returns cumulative sample delivery statistics for field updates.
118 *
119 * @details
120 * Returns the total number of expected updates and the number that were lost.
121 * Only meaningful when @c is_latency_and_lost_enabled() returns @c true. The
122 * default implementation returns a zero-initialised @c SampleLostInfo.
123 *
124 * @return @c SampleLostInfo containing @c total and @c lost counts.
125 */
126 [[nodiscard]] virtual SampleLostInfo get_lost() const;
127
128 bool is_listened{false}; ///< @c true after @c listen() has been successfully called.
129
130 protected:
131 /**
132 * @brief Protected constructor; initialises the getter with @c kGetter role.
133 */
135
136 private:
138};
139
140} // 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.