VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
status_detail.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 status_detail.h
26 * @brief Concrete DDS-compatible status event structs with counter and handle fields.
27 *
28 * @details
29 * This file defines the ten concrete status structs derived from @c Status::Base.
30 * Each struct carries the specific counter and handle fields reported by the DDS middleware
31 * for that event type.
32 *
33 * Writer-side (Publisher / Server / Setter):
34 * - @c PublicationMatched -- matched subscriber count changed
35 * - @c OfferedDeadlineMissed -- writer missed its offered publication deadline
36 * - @c OfferedIncompatibleQos -- incompatible QoS subscriber detected
37 * - @c LivelinessLost -- writer failed to assert liveliness
38 *
39 * Reader-side (Subscriber / Client / Getter):
40 * - @c SubscriptionMatched -- matched publisher count changed
41 * - @c RequestedDeadlineMissed -- reader did not receive within its requested deadline
42 * - @c LivelinessChanged -- publisher liveliness state changed
43 * - @c SampleRejected -- sample dropped due to resource limit
44 * - @c RequestedIncompatibleQos -- incompatible QoS publisher detected
45 * - @c SampleLost -- sample lost before delivery
46 *
47 * @par Accessing status fields
48 * @code
49 * sub->register_status_callback([](vlink::Status::BasePtr status) {
50 * if (status->get_type() == vlink::Status::kSampleRejected) {
51 * auto rej = status->as<vlink::Status::SampleRejected>();
52 * if (rej->last_reason == vlink::Status::SampleRejected::kRejectedBySamplesLimit) {
53 * VLOG_W("Sample rejected: limit exceeded");
54 * }
55 * }
56 * });
57 * @endcode
58 */
59
60#pragma once
61
62#include <cstdint>
63#include <string>
64
65#include "./status.h"
66
67namespace vlink {
68
69namespace Status {
70
71/* ================== For writer ================== */
72
73/**
74 * @struct PublicationMatched
75 * @brief Status event fired when a DataWriter gains or loses a matching DataReader.
76 *
77 * @details
78 * Delivered to the writer's status callback whenever a subscriber that matches
79 * the topic name and QoS policy appears or disappears.
80 */
81struct VLINK_EXPORT PublicationMatched final : public Base {
82 public:
83 /**
84 * @brief Returns @c kPublicationMatched.
85 *
86 * @return Status type identifier.
87 */
88 [[nodiscard]] Type get_type() const override;
89
90 /**
91 * @brief Returns a human-readable summary of this status.
92 *
93 * @return String describing total and current matched reader counts.
94 */
95 [[nodiscard]] std::string get_string() const override;
96
97 int32_t total_count{0}; ///< Cumulative number of readers ever matched.
98 int32_t total_count_change{0}; ///< Change in total_count since last callback.
99 int32_t current_count{0}; ///< Number of readers currently matched.
100 int32_t current_count_change{0}; ///< Change in current_count since last callback.
101 InstanceHandle last_subscription_handle{nullptr}; ///< Handle of the most recently matched reader.
102
103 /**
104 * @brief Writes the status fields to @p ostream.
105 *
106 * @param ostream Output stream.
107 * @param status This @c PublicationMatched status.
108 * @return Reference to @p ostream.
109 */
110 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const PublicationMatched& status) noexcept;
111};
112
113/**
114 * @struct OfferedDeadlineMissed
115 * @brief Status event fired when a DataWriter fails to publish within its offered deadline period.
116 *
117 * @details
118 * Delivered once per instance that missed the deadline. @c last_instance_handle
119 * identifies the instance that most recently missed its deadline.
120 */
122 public:
123 /**
124 * @brief Returns @c kOfferedDeadlineMissed.
125 *
126 * @return Status type identifier.
127 */
128 [[nodiscard]] Type get_type() const override;
129
130 /**
131 * @brief Returns a human-readable summary of this status.
132 *
133 * @return String describing missed deadline counts.
134 */
135 [[nodiscard]] std::string get_string() const override;
136
137 int32_t total_count{0}; ///< Total deadline misses across all instances.
138 int32_t total_count_change{0}; ///< Change in total_count since last callback.
139 InstanceHandle last_instance_handle{nullptr}; ///< Handle of the most recently missed instance.
140
141 /**
142 * @brief Writes the status fields to @p ostream.
143 *
144 * @param ostream Output stream.
145 * @param status This @c OfferedDeadlineMissed status.
146 * @return Reference to @p ostream.
147 */
148 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const OfferedDeadlineMissed& status) noexcept;
149};
150
151/**
152 * @struct OfferedIncompatibleQos
153 * @brief Status event fired when a DataWriter discovers a subscriber with incompatible QoS.
154 *
155 * @details
156 * @c last_policy_id identifies the QoS policy ID that caused the incompatibility.
157 */
159 public:
160 /**
161 * @brief Returns @c kOfferedIncompatibleQos.
162 *
163 * @return Status type identifier.
164 */
165 [[nodiscard]] Type get_type() const override;
166
167 /**
168 * @brief Returns a human-readable summary of this status.
169 *
170 * @return String describing incompatible QoS detection counts.
171 */
172 [[nodiscard]] std::string get_string() const override;
173
174 int32_t total_count{0}; ///< Total incompatible subscribers ever detected.
175 int32_t total_count_change{0}; ///< Change in total_count since last callback.
176 int32_t last_policy_id{0}; ///< ID of the QoS policy that caused the last incompatibility.
177
178 /**
179 * @brief Writes the status fields to @p ostream.
180 *
181 * @param ostream Output stream.
182 * @param status This @c OfferedIncompatibleQos status.
183 * @return Reference to @p ostream.
184 */
185 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const OfferedIncompatibleQos& status) noexcept;
186};
187
188/**
189 * @struct LivelinessLost
190 * @brief Status event fired when a DataWriter loses liveliness (failed to assert within duration).
191 *
192 * @details
193 * Delivered to the writer when the liveliness lease expires without a successful assertion.
194 */
195struct VLINK_EXPORT LivelinessLost final : public Base {
196 public:
197 /**
198 * @brief Returns @c kLivelinessLost.
199 *
200 * @return Status type identifier.
201 */
202 [[nodiscard]] Type get_type() const override;
203
204 /**
205 * @brief Returns a human-readable summary of this status.
206 *
207 * @return String describing liveliness loss counts.
208 */
209 [[nodiscard]] std::string get_string() const override;
210
211 int32_t total_count{0}; ///< Total times liveliness was lost.
212 int32_t total_count_change{0}; ///< Change in total_count since last callback.
213
214 /**
215 * @brief Writes the status fields to @p ostream.
216 *
217 * @param ostream Output stream.
218 * @param status This @c LivelinessLost status.
219 * @return Reference to @p ostream.
220 */
221 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const LivelinessLost& status) noexcept;
222};
223
224/* ================== For reader ================== */
225
226/**
227 * @struct SubscriptionMatched
228 * @brief Status event fired when a DataReader gains or loses a matching DataWriter.
229 *
230 * @details
231 * Delivered to the reader's status callback whenever a publisher that matches
232 * the topic name and QoS policy appears or disappears.
233 */
234struct VLINK_EXPORT SubscriptionMatched final : public Base {
235 public:
236 /**
237 * @brief Returns @c kSubscriptionMatched.
238 *
239 * @return Status type identifier.
240 */
241 [[nodiscard]] Type get_type() const override;
242
243 /**
244 * @brief Returns a human-readable summary of this status.
245 *
246 * @return String describing total and current matched writer counts.
247 */
248 [[nodiscard]] std::string get_string() const override;
249
250 int32_t total_count{0}; ///< Cumulative number of writers ever matched.
251 int32_t total_count_change{0}; ///< Change in total_count since last callback.
252 int32_t current_count{0}; ///< Number of writers currently matched.
253 int32_t current_count_change{0}; ///< Change in current_count since last callback.
254 InstanceHandle last_publication_handle{nullptr}; ///< Handle of the most recently matched writer.
255
256 /**
257 * @brief Writes the status fields to @p ostream.
258 *
259 * @param ostream Output stream.
260 * @param status This @c SubscriptionMatched status.
261 * @return Reference to @p ostream.
262 */
263 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const SubscriptionMatched& status) noexcept;
264};
265
266/**
267 * @struct RequestedDeadlineMissed
268 * @brief Status event fired when a DataReader does not receive data within its requested deadline.
269 *
270 * @details
271 * @c last_instance_handle identifies the data instance whose deadline was most recently missed.
272 */
274 public:
275 /**
276 * @brief Returns @c kRequestedDeadlineMissed.
277 *
278 * @return Status type identifier.
279 */
280 [[nodiscard]] Type get_type() const override;
281
282 /**
283 * @brief Returns a human-readable summary of this status.
284 *
285 * @return String describing missed deadline counts.
286 */
287 [[nodiscard]] std::string get_string() const override;
288
289 int32_t total_count{0}; ///< Total deadline misses across all instances.
290 int32_t total_count_change{0}; ///< Change in total_count since last callback.
291 InstanceHandle last_instance_handle{nullptr}; ///< Handle of the most recently missed instance.
292
293 /**
294 * @brief Writes the status fields to @p ostream.
295 *
296 * @param ostream Output stream.
297 * @param status This @c RequestedDeadlineMissed status.
298 * @return Reference to @p ostream.
299 */
300 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const RequestedDeadlineMissed& status) noexcept;
301};
302
303/**
304 * @struct LivelinessChanged
305 * @brief Status event fired when the liveliness state of a matched DataWriter changes.
306 *
307 * @details
308 * Tracks how many matched publishers are alive versus not alive. The @c last_publication_handle
309 * identifies the writer whose liveliness state most recently changed.
310 */
311struct VLINK_EXPORT LivelinessChanged final : public Base {
312 public:
313 /**
314 * @brief Returns @c kLivelinessChanged.
315 *
316 * @return Status type identifier.
317 */
318 [[nodiscard]] Type get_type() const override;
319
320 /**
321 * @brief Returns a human-readable summary of this status.
322 *
323 * @return String describing alive and not-alive writer counts.
324 */
325 [[nodiscard]] std::string get_string() const override;
326
327 int32_t alive_count{0}; ///< Number of matched writers that are currently alive.
328 int32_t not_alive_count{0}; ///< Number of matched writers that are not alive.
329 int32_t alive_count_change{0}; ///< Change in alive_count since last callback.
330 int32_t not_alive_count_change{0}; ///< Change in not_alive_count since last callback.
331 InstanceHandle last_publication_handle{nullptr}; ///< Handle of the writer that most recently changed.
332
333 /**
334 * @brief Writes the status fields to @p ostream.
335 *
336 * @param ostream Output stream.
337 * @param status This @c LivelinessChanged status.
338 * @return Reference to @p ostream.
339 */
340 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const LivelinessChanged& status) noexcept;
341};
342
343/**
344 * @struct SampleRejected
345 * @brief Status event fired when an incoming sample is rejected due to a resource limit.
346 *
347 * @details
348 * The @c Kind enum identifies which resource limit caused the rejection.
349 * @c last_reason and @c last_instance_handle describe the most recent rejection.
350 */
351struct VLINK_EXPORT SampleRejected final : public Base {
352 public:
353 /**
354 * @brief Reason codes for sample rejection.
355 *
356 * | Kind | Limit exceeded |
357 * | -------------------------------- | ----------------------------------- |
358 * | kNotRejected | Sample was not rejected |
359 * | kRejectedByInstancesLimit | Max instances limit reached |
360 * | kRejectedBySamplesLimit | Max total samples limit reached |
361 * | kRejectedBySamplesPerInstanceLimit | Max samples per instance reached |
362 */
363 enum Kind : uint8_t {
364 kNotRejected = 0, ///< No rejection.
365 kRejectedByInstancesLimit = 1, ///< Max instances limit exceeded.
366 kRejectedBySamplesLimit = 2, ///< Max total samples limit exceeded.
367 kRejectedBySamplesPerInstanceLimit = 3 ///< Max samples per instance limit exceeded.
368 };
369
370 /**
371 * @brief Returns @c kSampleRejected.
372 *
373 * @return Status type identifier.
374 */
375 [[nodiscard]] Type get_type() const override;
376
377 /**
378 * @brief Returns a human-readable summary of this status.
379 *
380 * @return String describing rejection counts and last rejection reason.
381 */
382 [[nodiscard]] std::string get_string() const override;
383
384 int32_t total_count{0}; ///< Total number of samples rejected.
385 int32_t total_count_change{0}; ///< Change in total_count since last callback.
386 Kind last_reason{kNotRejected}; ///< Reason for the most recent rejection.
387 InstanceHandle last_instance_handle{nullptr}; ///< Handle of the instance that was most recently rejected.
388
389 /**
390 * @brief Writes the status fields to @p ostream.
391 *
392 * @param ostream Output stream.
393 * @param status This @c SampleRejected status.
394 * @return Reference to @p ostream.
395 */
396 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const SampleRejected& status) noexcept;
397};
398
399/**
400 * @struct RequestedIncompatibleQos
401 * @brief Status event fired when a DataReader discovers a publisher with incompatible QoS.
402 *
403 * @details
404 * @c last_policy_id identifies the QoS policy ID that caused the incompatibility.
405 */
407 public:
408 /**
409 * @brief Returns @c kRequestedIncompatibleQos.
410 *
411 * @return Status type identifier.
412 */
413 [[nodiscard]] Type get_type() const override;
414
415 /**
416 * @brief Returns a human-readable summary of this status.
417 *
418 * @return String describing incompatible QoS detection counts.
419 */
420 [[nodiscard]] std::string get_string() const override;
421
422 int32_t total_count{0}; ///< Total incompatible publishers ever detected.
423 int32_t total_count_change{0}; ///< Change in total_count since last callback.
424 int32_t last_policy_id{0}; ///< ID of the QoS policy that caused the last incompatibility.
425
426 /**
427 * @brief Writes the status fields to @p ostream.
428 *
429 * @param ostream Output stream.
430 * @param status This @c RequestedIncompatibleQos status.
431 * @return Reference to @p ostream.
432 */
433 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const RequestedIncompatibleQos& status) noexcept;
434};
435
436/**
437 * @struct SampleLost
438 * @brief Status event fired when a sample is lost before it can be delivered to the DataReader.
439 *
440 * @details
441 * Sample loss typically occurs when a publisher produces data faster than the subscriber
442 * consumes it and the history depth is exceeded.
443 */
444struct VLINK_EXPORT SampleLost final : public Base {
445 public:
446 /**
447 * @brief Returns @c kSampleLost.
448 *
449 * @return Status type identifier.
450 */
451 [[nodiscard]] Type get_type() const override;
452
453 /**
454 * @brief Returns a human-readable summary of this status.
455 *
456 * @return String describing sample loss counts.
457 */
458 [[nodiscard]] std::string get_string() const override;
459
460 int32_t total_count{0}; ///< Total samples ever lost.
461 int32_t total_count_change{0}; ///< Change in total_count since last callback.
462
463 /**
464 * @brief Writes the status fields to @p ostream.
465 *
466 * @param ostream Output stream.
467 * @param status This @c SampleLost status.
468 * @return Reference to @p ostream.
469 */
470 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const SampleLost& status) noexcept;
471};
472
473} // namespace Status
474
475} // namespace vlink
#define VLINK_EXPORT
Definition macros.h:85
DDS-compatible status type hierarchy for VLink publisher and subscriber callbacks.