VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
qos_profile.h
浏览该文件的文档.
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 qos_profile.h
26 * @brief Pre-defined QoS profiles for common VLink communication patterns.
27 *
28 * @details
29 * The @c QosProfile namespace provides a set of ready-to-use @c Qos constant instances
30 * covering the most common autonomy and embedded system use cases. Each profile has
31 * @c valid = @c true and can be passed directly to any VLink endpoint.
32 *
33 * Available profiles:
34 *
35 * | Profile | Reliability | History | Durability | PubMode | Priority | Use case |
36 * | ---------- | ---------- | -------------- | -------------- | ------- | ---------- | --------------------------- |
37 * | kEvent | Reliable | KeepLast(10) | Volatile | Sync | RealTime | Discrete control events |
38 * | kMethod | Reliable | KeepAll(1) | Volatile | Sync | High | RPC request/response |
39 * | kField | Reliable | KeepLast(1) | TransientLocal | Sync | High | Latest-value state sync |
40 * | kSensor | BestEffort | KeepLast(20) | Volatile | ASync | Normal | High-rate sensor data |
41 * | kParameter | Reliable | KeepLast(1000) | Volatile | Sync | Normal | Configuration parameters |
42 * | kService | Reliable | KeepLast(10) | TransientLocal | Sync | Normal | Service discovery |
43 * | kClock | BestEffort | KeepLast(1) | Volatile | ASync | Low | Time synchronisation |
44 * | kStatic | Reliable | KeepAll(1) | TransientLocal | Sync | Normal | Static/slow-changing data |
45 * | kLight | Reliable | KeepLast(1) | Volatile | ASync | High | Lightweight fast messaging |
46 * | kPoor | BestEffort | KeepLast(5) | Volatile | ASync | Background | Low-priority best-effort |
47 * | kBetter | BestEffort | KeepLast(50) | Volatile | Sync | RealTime | High-throughput best-effort |
48 * | kBest | Reliable | KeepLast(200) | Volatile | Sync | RealTime | High-throughput reliable |
49 * | kLarge | Reliable | KeepLast(500) | Volatile | Sync | Low | Large payload transfers |
50 *
51 * @par Lookup by name
52 * @c get_available_qos_map() returns an @c unordered_map from profile name string to @c Qos,
53 * enabling runtime profile selection:
54 * @code
55 * auto& qos_map = vlink::QosProfile::get_available_qos_map();
56 * auto it = qos_map.find("sensor");
57 * if (it != qos_map.end()) {
58 * pub->set_qos(it->second);
59 * }
60 * @endcode
61 *
62 * @par Direct usage
63 * @code
64 * auto pub = vlink::Publisher<MyMsg>::create("dds://sensor_data");
65 * pub->set_qos(vlink::QosProfile::kSensor);
66 * @endcode
67 */
68
69#pragma once
70
71#include <string>
72#include <unordered_map>
73
74#include "../base/macros.h"
75#include "./qos.h"
76
77namespace vlink {
78
79/**
80 * @namespace vlink::QosProfile
81 * @brief Pre-built @c Qos constant instances covering common communication patterns.
82 *
83 * @details
84 * All profiles have @c valid = @c true. Choose the profile that best matches your
85 * use case, or customise a copy for specific requirements.
86 *
87 * @see Qos, get_available_qos_map()
88 */
89namespace QosProfile { // NOLINT(readability-identifier-naming)
90
91/**
92 * @brief Reliable, KeepLast(10), Volatile, Sync, RealTime priority.
93 *
94 * @details Designed for discrete control events where delivery must be guaranteed
95 * and late arrivals are acceptable up to a depth of 10.
96 */
97[[maybe_unused]] static inline constexpr Qos kEvent{
98 "event",
99 true,
112};
113
114/**
115 * @brief Reliable, KeepAll, Volatile, Sync, High priority.
116 *
117 * @details Designed for RPC-style request/response (Method model).
118 * KeepAll ensures no request is dropped even under load.
119 */
120[[maybe_unused]] static inline constexpr Qos kMethod{
121 "method",
122 true,
135};
136
137/**
138 * @brief Reliable, KeepLast(1), TransientLocal, Sync, High priority.
139 *
140 * @details Designed for Field model (Getter/Setter) where only the latest value matters
141 * and late-joining subscribers must receive the last published value.
142 */
143[[maybe_unused]] static inline constexpr Qos kField{
144 "field",
145 true,
158};
159
160/**
161 * @brief BestEffort, KeepLast(20), Volatile, ASync, Normal priority, express.
162 *
163 * @details Designed for high-rate sensor streams (LiDAR, camera, IMU) where throughput
164 * is more important than delivery guarantees. Express mode hints for minimal queuing delay.
165 */
166[[maybe_unused]] static inline constexpr Qos kSensor{
167 "sensor",
168 true,
181};
182
183/**
184 * @brief Reliable, KeepLast(1000), Volatile, Sync, Normal priority.
185 *
186 * @details Designed for configuration parameters that change infrequently but must
187 * be delivered reliably with a large history window.
188 */
189[[maybe_unused]] static inline constexpr Qos kParameter{
190 "parameter",
191 true,
204};
205
206/**
207 * @brief Reliable, KeepLast(10), TransientLocal, Sync, Normal priority.
208 *
209 * @details Designed for service discovery and advertisement where late joiners
210 * must see the current service registry.
211 */
212[[maybe_unused]] static inline constexpr Qos kService{
213 "service",
214 true,
227};
228
229/**
230 * @brief BestEffort, KeepLast(1), Volatile, ASync, Low priority.
231 *
232 * @details Designed for time synchronisation broadcasts where the newest value
233 * is always more useful than older ones and missing a tick is acceptable.
234 */
235[[maybe_unused]] static inline constexpr Qos kClock{
236 "clock",
237 true,
250};
251
252/**
253 * @brief Reliable, KeepAll, TransientLocal, Sync, Normal priority.
254 *
255 * @details Designed for slowly-changing or static data (maps, calibration files) that
256 * must be fully received by any late-joining subscriber.
257 */
258[[maybe_unused]] static inline constexpr Qos kStatic{
259 "static",
260 true,
273};
274
275/**
276 * @brief Reliable, KeepLast(1), Volatile, ASync, High priority.
277 *
278 * @details Designed for lightweight, frequent messages where only the latest value
279 * is needed and asynchronous delivery provides low overhead.
280 */
281[[maybe_unused]] static inline constexpr Qos kLight{
282 "light",
283 true,
296};
297
298/**
299 * @brief BestEffort, KeepLast(5), Volatile, ASync, Background priority.
300 *
301 * @details Designed for low-priority non-critical data streams where some loss
302 * is acceptable and the lowest possible CPU overhead is desired.
303 */
304[[maybe_unused]] static inline constexpr Qos kPoor{
305 "poor",
306 true,
319};
320
321/**
322 * @brief BestEffort, KeepLast(50), Volatile, Sync, RealTime priority.
323 *
324 * @details Designed for high-throughput best-effort streams that benefit from
325 * a larger history buffer and real-time dispatch priority.
326 */
327[[maybe_unused]] static inline constexpr Qos kBetter{
328 "better",
329 true,
342};
343
344/**
345 * @brief Reliable, KeepLast(200), Volatile, Sync, RealTime priority.
346 *
347 * @details Designed for high-throughput reliable streams with a large history buffer.
348 * Combines reliability guarantees with synchronous sending for predictable latency.
349 */
350[[maybe_unused]] static inline constexpr Qos kBest{
351 "best",
352 true,
365};
366
367/**
368 * @brief Reliable, KeepLast(500), Volatile, Sync, Low priority, extended heartbeat.
369 *
370 * @details Designed for large payload transfers (maps, point clouds, images) where
371 * a large history window and extended heartbeat interval accommodate slower transport.
372 */
373[[maybe_unused]] static inline constexpr Qos kLarge{
374 "large",
375 true,
388};
389
390/**
391 * @brief Returns a reference to the global map of all named QoS profiles.
392 *
393 * @details
394 * The map is keyed by the profile name string (e.g., @c "sensor", @c "event") and maps
395 * to the corresponding @c Qos constant. The map is populated with all profiles defined
396 * in this namespace and is safe to query from any thread after construction.
397 *
398 * @return Const reference to an @c unordered_map<string, Qos> of all available profiles.
399 */
400[[nodiscard]] VLINK_EXPORT const std::unordered_map<std::string, Qos>& get_available_qos_map() noexcept;
401
402} // namespace QosProfile
403
404} // namespace vlink
Platform-independent macro definitions for the VLink library.
#define VLINK_EXPORT
定义 macros.h:85
Quality of Service (QoS) policy aggregate for VLink publishers and subscribers.