nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
qos.hpp
Go to the documentation of this file.
1// nros-cpp: QoS (Quality of Service) profiles
2// Freestanding C++ — no STL required
3
10#ifndef NROS_CPP_QOS_HPP
11#define NROS_CPP_QOS_HPP
12
13#include <stdint.h>
14
15// FFI struct definition — mirrors `nros_cpp_qos_t` in
16// nros_cpp_ffi.h. Phase 118.D: guarded by `NROS_CPP_FFI_H`. If
17// `nros_cpp_ffi.h` was included earlier (it sets that guard), the
18// canonical types are already in scope; otherwise emit local
19// definitions so this header stays self-contained for callers that
20// don't pull the cbindgen header directly.
21#ifndef NROS_CPP_FFI_H
22extern "C" {
53}
54#endif // NROS_CPP_FFI_H
55
56namespace nros {
57
68class QoS {
69 public:
77
80 constexpr QoS()
81 : reliability_(Reliable), durability_(Volatile), history_(KeepLast),
82 liveliness_(LivelinessAutomatic), depth_(10), deadline_ms_(0), lifespan_ms_(0),
83 liveliness_lease_ms_(0), avoid_ros_namespace_conventions_(0), tx_express_(0) {}
84
85 // -- Chainable setters (match rclcpp fluent API) --
86
88 constexpr QoS& reliable() {
89 reliability_ = Reliable;
90 return *this;
91 }
92
94 constexpr QoS& best_effort() {
95 reliability_ = BestEffort;
96 return *this;
97 }
98
100 constexpr QoS& transient_local() {
101 durability_ = TransientLocal;
102 return *this;
103 }
104
107 durability_ = Volatile;
108 return *this;
109 }
110
113 constexpr QoS& keep_last(int depth) {
114 history_ = KeepLast;
115 depth_ = depth;
116 return *this;
117 }
118
120 constexpr QoS& keep_all() {
121 history_ = KeepAll;
122 return *this;
123 }
124
128 deadline_ms_ = ms;
129 return *this;
130 }
131
134 lifespan_ms_ = ms;
135 return *this;
136 }
137
141 liveliness_ = kind;
142 return *this;
143 }
144
147 liveliness_lease_ms_ = ms;
148 return *this;
149 }
150
154 avoid_ros_namespace_conventions_ = on ? 1 : 0;
155 return *this;
156 }
157
162 constexpr QoS& tx_express(bool on) {
163 tx_express_ = on ? 1 : 0;
164 return *this;
165 }
166
167 // -- Predefined profiles (match rclcpp named constructors) --
168
170 static constexpr QoS default_profile() { return QoS(); }
171
173 static constexpr QoS sensor_data() { return QoS().best_effort().keep_last(5); }
174
176 static constexpr QoS services() { return QoS().reliable(); }
177
178 // -- Accessors --
179
181 constexpr int reliability_raw() const { return static_cast<int>(reliability_); }
183 constexpr int durability_raw() const { return static_cast<int>(durability_); }
185 constexpr int history_raw() const { return static_cast<int>(history_); }
187 constexpr int liveliness_raw() const { return static_cast<int>(liveliness_); }
189 constexpr int depth() const { return depth_; }
191 constexpr uint32_t deadline_ms() const { return deadline_ms_; }
193 constexpr uint32_t lifespan_ms() const { return lifespan_ms_; }
195 constexpr uint32_t liveliness_lease_ms() const { return liveliness_lease_ms_; }
197 constexpr bool avoid_ros_namespace_conventions() const {
198 return avoid_ros_namespace_conventions_ != 0;
199 }
201 constexpr bool tx_express() const { return tx_express_ != 0; }
202
203 private:
204 enum Reliability { Reliable = 0, BestEffort = 1 } reliability_;
205 enum Durability { Volatile = 0, TransientLocal = 1 } durability_;
206 enum History { KeepLast = 0, KeepAll = 1 } history_;
207 Liveliness liveliness_;
208 int depth_;
209 uint32_t deadline_ms_;
210 uint32_t lifespan_ms_;
211 uint32_t liveliness_lease_ms_;
212 uint8_t avoid_ros_namespace_conventions_;
213 uint8_t tx_express_;
214};
215
216} // namespace nros
217
218#endif // NROS_CPP_QOS_HPP
Definition future.hpp:40
Definition qos.hpp:68
constexpr int depth() const
Configured queue depth (only meaningful for KEEP_LAST).
Definition qos.hpp:189
constexpr QoS & best_effort()
Set reliability to BEST_EFFORT (fire-and-forget; default for sensors).
Definition qos.hpp:94
constexpr int history_raw() const
History as a raw int (0 = KeepLast, 1 = KeepAll).
Definition qos.hpp:185
constexpr bool avoid_ros_namespace_conventions() const
Whether to skip the /rt/ ROS topic-name prefix.
Definition qos.hpp:197
constexpr uint32_t lifespan_ms() const
Lifespan in ms (0 = infinite).
Definition qos.hpp:193
constexpr QoS & deadline_ms(uint32_t ms)
Definition qos.hpp:127
static constexpr QoS default_profile()
Default profile: RELIABLE + VOLATILE + KEEP_LAST(10).
Definition qos.hpp:170
static constexpr QoS services()
Services profile: RELIABLE + VOLATILE + KEEP_LAST(10).
Definition qos.hpp:176
constexpr QoS & avoid_ros_namespace_conventions(bool on)
Definition qos.hpp:153
Liveliness
Liveliness policy kind. Matches DDS LIVELINESS_QOS_POLICY.
Definition qos.hpp:71
@ LivelinessAutomatic
Definition qos.hpp:73
@ LivelinessManualByTopic
Definition qos.hpp:74
@ LivelinessNone
Definition qos.hpp:72
@ LivelinessManualByNode
Definition qos.hpp:75
constexpr QoS & reliable()
Set reliability to RELIABLE (acked transport, retransmits on loss).
Definition qos.hpp:88
static constexpr QoS sensor_data()
Sensor-data profile: BEST_EFFORT + VOLATILE + KEEP_LAST(5).
Definition qos.hpp:173
constexpr QoS & tx_express(bool on)
Definition qos.hpp:162
constexpr uint32_t deadline_ms() const
Deadline in ms (0 = infinite).
Definition qos.hpp:191
constexpr QoS()
Definition qos.hpp:80
constexpr QoS & lifespan_ms(uint32_t ms)
Sample expiry. 0 = infinite.
Definition qos.hpp:133
constexpr int liveliness_raw() const
Liveliness kind as a raw int (0..3).
Definition qos.hpp:187
constexpr int reliability_raw() const
Reliability as a raw int (0 = Reliable, 1 = BestEffort).
Definition qos.hpp:181
constexpr QoS & keep_last(int depth)
Definition qos.hpp:113
constexpr QoS & durability_volatile()
Set durability to VOLATILE — late joiners get nothing (default).
Definition qos.hpp:106
constexpr uint32_t liveliness_lease_ms() const
Liveliness lease in ms (0 = infinite).
Definition qos.hpp:195
constexpr QoS & liveliness(Liveliness kind)
Definition qos.hpp:140
constexpr int durability_raw() const
Durability as a raw int (0 = Volatile, 1 = TransientLocal).
Definition qos.hpp:183
constexpr QoS & keep_all()
Use KEEP_ALL history (bounded by transport).
Definition qos.hpp:120
constexpr bool tx_express() const
Whether this publisher's samples bypass transport tx batching.
Definition qos.hpp:201
constexpr QoS & transient_local()
Set durability to TRANSIENT_LOCAL — late joiners get the last value.
Definition qos.hpp:100
constexpr QoS & liveliness_lease_ms(uint32_t ms)
Liveliness lease duration. 0 = infinite.
Definition qos.hpp:146
Definition nros.hpp:43
nros_cpp_qos_history_t
Definition qos.hpp:31
@ NROS_CPP_QOS_KEEP_LAST
Definition qos.hpp:32
@ NROS_CPP_QOS_KEEP_ALL
Definition qos.hpp:33
nros_cpp_qos_liveliness_t
Definition qos.hpp:35
@ NROS_CPP_QOS_LIVELINESS_MANUAL_BY_NODE
Definition qos.hpp:39
@ NROS_CPP_QOS_LIVELINESS_AUTOMATIC
Definition qos.hpp:37
@ NROS_CPP_QOS_LIVELINESS_MANUAL_BY_TOPIC
Definition qos.hpp:38
@ NROS_CPP_QOS_LIVELINESS_NONE
Definition qos.hpp:36
nros_cpp_qos_durability_t
Definition qos.hpp:27
@ NROS_CPP_QOS_VOLATILE
Definition qos.hpp:28
@ NROS_CPP_QOS_TRANSIENT_LOCAL
Definition qos.hpp:29
nros_cpp_qos_reliability_t
Definition qos.hpp:23
@ NROS_CPP_QOS_RELIABLE
Definition qos.hpp:24
@ NROS_CPP_QOS_BEST_EFFORT
Definition qos.hpp:25
Definition qos.hpp:41
enum nros_cpp_qos_durability_t durability
Definition qos.hpp:43
uint32_t liveliness_lease_ms
Definition qos.hpp:49
uint32_t lifespan_ms
Definition qos.hpp:48
enum nros_cpp_qos_history_t history
Definition qos.hpp:44
uint8_t tx_express
Definition qos.hpp:51
enum nros_cpp_qos_liveliness_t liveliness_kind
Definition qos.hpp:45
enum nros_cpp_qos_reliability_t reliability
Definition qos.hpp:42
uint8_t avoid_ros_namespace_conventions
Definition qos.hpp:50
uint32_t deadline_ms
Definition qos.hpp:47
int depth
Definition qos.hpp:46