ROS 2 rclcpp + rcl - rolling  rolling-d1a7896a
ROS 2 C++ Client Library with ROS Client Library
qos.hpp
1 // Copyright 2019 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__QOS_HPP_
16 #define RCLCPP__QOS_HPP_
17 
18 #include <string>
19 
20 #include "rclcpp/duration.hpp"
21 #include "rclcpp/visibility_control.hpp"
22 #include "rmw/incompatible_qos_events_statuses.h"
23 #include "rmw/qos_profiles.h"
24 #include "rmw/types.h"
25 
26 namespace rclcpp
27 {
28 
29 RCLCPP_PUBLIC
30 std::string qos_policy_name_from_kind(rmw_qos_policy_kind_t policy_kind);
31 
32 enum class HistoryPolicy
33 {
34  KeepLast = RMW_QOS_POLICY_HISTORY_KEEP_LAST,
35  KeepAll = RMW_QOS_POLICY_HISTORY_KEEP_ALL,
36  SystemDefault = RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT,
37  Unknown = RMW_QOS_POLICY_HISTORY_UNKNOWN,
38 };
39 
40 enum class ReliabilityPolicy
41 {
42  BestEffort = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
43  Reliable = RMW_QOS_POLICY_RELIABILITY_RELIABLE,
44  SystemDefault = RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT,
45  BestAvailable = RMW_QOS_POLICY_RELIABILITY_BEST_AVAILABLE,
46  Unknown = RMW_QOS_POLICY_RELIABILITY_UNKNOWN,
47 };
48 
49 enum class DurabilityPolicy
50 {
51  Volatile = RMW_QOS_POLICY_DURABILITY_VOLATILE,
52  TransientLocal = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL,
53  SystemDefault = RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT,
54  BestAvailable = RMW_QOS_POLICY_DURABILITY_BEST_AVAILABLE,
55  Unknown = RMW_QOS_POLICY_DURABILITY_UNKNOWN,
56 };
57 
58 enum class LivelinessPolicy
59 {
60  Automatic = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC,
61  ManualByTopic = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC,
62  SystemDefault = RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
63  BestAvailable = RMW_QOS_POLICY_LIVELINESS_BEST_AVAILABLE,
64  Unknown = RMW_QOS_POLICY_LIVELINESS_UNKNOWN,
65 };
66 
67 enum class QoSCompatibility
68 {
69  Ok = RMW_QOS_COMPATIBILITY_OK,
70  Warning = RMW_QOS_COMPATIBILITY_WARNING,
71  Error = RMW_QOS_COMPATIBILITY_ERROR,
72 };
73 
75 struct RCLCPP_PUBLIC QoSInitialization
76 {
77  rmw_qos_history_policy_t history_policy;
78  size_t depth;
79 
82  rmw_qos_history_policy_t history_policy_arg, size_t depth_arg,
83  bool print_depth_warning = true);
84 
86  static
88  from_rmw(const rmw_qos_profile_t & rmw_qos);
89 };
90 
92 struct RCLCPP_PUBLIC KeepAll : public rclcpp::QoSInitialization
93 {
94  KeepAll();
95 };
96 
98 struct RCLCPP_PUBLIC KeepLast : public rclcpp::QoSInitialization
99 {
100  explicit KeepLast(size_t depth, bool print_depth_warning = true);
101 };
102 
104 
113 class RCLCPP_PUBLIC QoS
114 {
115 public:
117 
130  explicit
131  QoS(
132  const QoSInitialization & qos_initialization,
133  const rmw_qos_profile_t & initial_profile = rmw_qos_profile_default);
134 
136 
143  // cppcheck-suppress noExplicitConstructor
144  QoS(size_t history_depth); // NOLINT(runtime/explicit): conversion constructor
145 
147 
151  rmw_qos_profile_t &
152  get_rmw_qos_profile();
153 
155 
159  const rmw_qos_profile_t &
160  get_rmw_qos_profile() const;
161 
163  QoS &
164  history(HistoryPolicy history);
165 
167  QoS &
168  history(rmw_qos_history_policy_t history);
169 
171  QoS &
172  keep_last(size_t depth);
173 
175  QoS &
176  keep_all();
177 
179  QoS &
180  reliability(rmw_qos_reliability_policy_t reliability);
181 
183  QoS &
184  reliability(ReliabilityPolicy reliability);
185 
187  QoS &
188  reliable();
189 
191  QoS &
192  best_effort();
193 
195  QoS &
196  reliability_best_available();
197 
199  QoS &
200  durability(rmw_qos_durability_policy_t durability);
201 
203  QoS &
204  durability(DurabilityPolicy durability);
205 
207 
210  QoS &
211  durability_volatile();
212 
214  QoS &
215  transient_local();
216 
218  QoS &
219  durability_best_available();
220 
222  QoS &
223  deadline(rmw_time_t deadline);
224 
226  QoS &
227  deadline(const rclcpp::Duration & deadline);
228 
230  QoS &
231  lifespan(rmw_time_t lifespan);
232 
234  QoS &
235  lifespan(const rclcpp::Duration & lifespan);
236 
238  QoS &
239  liveliness(rmw_qos_liveliness_policy_t liveliness);
240 
242  QoS &
243  liveliness(LivelinessPolicy liveliness);
244 
246  QoS &
247  liveliness_lease_duration(rmw_time_t liveliness_lease_duration);
248 
250  QoS &
251  liveliness_lease_duration(const rclcpp::Duration & liveliness_lease_duration);
252 
254  QoS &
255  avoid_ros_namespace_conventions(bool avoid_ros_namespace_conventions);
256 
258  HistoryPolicy
259  history() const;
260 
262  size_t
263  depth() const;
264 
266  ReliabilityPolicy
267  reliability() const;
268 
270  DurabilityPolicy
271  durability() const;
272 
275  deadline() const;
276 
279  lifespan() const;
280 
282  LivelinessPolicy
283  liveliness() const;
284 
287  liveliness_lease_duration() const;
288 
290  bool
291  avoid_ros_namespace_conventions() const;
292 
293 private:
294  rmw_qos_profile_t rmw_qos_profile_;
295 };
296 
298 RCLCPP_PUBLIC
299 bool operator==(const QoS & left, const QoS & right);
300 RCLCPP_PUBLIC
301 bool operator!=(const QoS & left, const QoS & right);
302 
304 
308 {
310  QoSCompatibility compatibility;
311 
313 
317  std::string reason;
318 };
319 
321 
354 RCLCPP_PUBLIC
356 qos_check_compatible(const QoS & publisher_qos, const QoS & subscription_qos);
357 
370 class RCLCPP_PUBLIC ClockQoS : public QoS
371 {
372 public:
373  explicit
374  ClockQoS(
375  const QoSInitialization & qos_initialization = KeepLast(1));
376 };
377 
390 class RCLCPP_PUBLIC SensorDataQoS : public QoS
391 {
392 public:
393  explicit
395  const QoSInitialization & qos_initialization = (
396  QoSInitialization::from_rmw(rmw_qos_profile_sensor_data)
397  ));
398 };
399 
412 class RCLCPP_PUBLIC ParametersQoS : public QoS
413 {
414 public:
415  explicit
417  const QoSInitialization & qos_initialization = (
418  QoSInitialization::from_rmw(rmw_qos_profile_parameters)
419  ));
420 };
421 
434 class RCLCPP_PUBLIC ServicesQoS : public QoS
435 {
436 public:
437  explicit
438  ServicesQoS(
439  const QoSInitialization & qos_initialization = (
440  QoSInitialization::from_rmw(rmw_qos_profile_services_default)
441  ));
442 };
443 
456 class RCLCPP_PUBLIC ParameterEventsQoS : public QoS
457 {
458 public:
459  explicit
461  const QoSInitialization & qos_initialization = (
462  QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
463  ));
464 };
465 
478 class RCLCPP_PUBLIC RosoutQoS : public QoS
479 {
480 public:
481  explicit
482  RosoutQoS(
483  const QoSInitialization & rosout_qos_initialization = (
484  QoSInitialization::from_rmw(rmw_qos_profile_rosout_default)
485  ));
486 };
487 
500 class RCLCPP_PUBLIC SystemDefaultsQoS : public QoS
501 {
502 public:
503  explicit
505  const QoSInitialization & qos_initialization = (
506  QoSInitialization::from_rmw(rmw_qos_profile_system_default)
507  ));
508 };
509 
530 class RCLCPP_PUBLIC BestAvailableQoS : public QoS
531 {
532 public:
533  explicit
535  const QoSInitialization & qos_initialization = (
536  QoSInitialization::from_rmw(rmw_qos_profile_best_available)
537  ));
538 };
539 
540 } // namespace rclcpp
541 
542 #endif // RCLCPP__QOS_HPP_
Encapsulation of Quality of Service settings.
Definition: qos.hpp:114
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC QoSCheckCompatibleResult qos_check_compatible(const QoS &publisher_qos, const QoS &subscription_qos)
Check if two QoS profiles are compatible.
Definition: qos.cpp:358
RCLCPP_PUBLIC bool operator==(const NetworkFlowEndpoint &left, const NetworkFlowEndpoint &right)
Check if two NetworkFlowEndpoint instances are equal.
RCLCPP_PUBLIC bool operator!=(const NetworkFlowEndpoint &left, const NetworkFlowEndpoint &right)
Check if two NetworkFlowEndpoint instances are not equal.
Use to initialize the QoS with the keep_all history setting.
Definition: qos.hpp:93
Use to initialize the QoS with the keep_last history setting and the given depth.
Definition: qos.hpp:99
Result type for checking QoS compatibility.
Definition: qos.hpp:308
QoSCompatibility compatibility
Compatibility result.
Definition: qos.hpp:310
std::string reason
Reason for a (possible) incompatibility.
Definition: qos.hpp:317
QoS initialization values, cannot be created directly, use KeepAll or KeepLast instead.
Definition: qos.hpp:76
static QoSInitialization from_rmw(const rmw_qos_profile_t &rmw_qos)
Create a QoSInitialization from an existing rmw_qos_profile_t, using its history and depth.
Definition: qos.cpp:70