15 #include "rclcpp/qos.hpp"
19 #include "rclcpp/exceptions.hpp"
20 #include "rclcpp/logging.hpp"
22 #include "rmw/error_handling.h"
23 #include "rmw/types.h"
24 #include "rmw/qos_profiles.h"
29 std::string qos_policy_name_from_kind(rmw_qos_policy_kind_t policy_kind)
31 switch (policy_kind) {
32 case RMW_QOS_POLICY_DURABILITY:
33 return "DURABILITY_QOS_POLICY";
34 case RMW_QOS_POLICY_DEADLINE:
35 return "DEADLINE_QOS_POLICY";
36 case RMW_QOS_POLICY_LIVELINESS:
37 return "LIVELINESS_QOS_POLICY";
38 case RMW_QOS_POLICY_RELIABILITY:
39 return "RELIABILITY_QOS_POLICY";
40 case RMW_QOS_POLICY_HISTORY:
41 return "HISTORY_QOS_POLICY";
42 case RMW_QOS_POLICY_LIFESPAN:
43 return "LIFESPAN_QOS_POLICY";
44 case RMW_QOS_POLICY_DEPTH:
45 return "DEPTH_QOS_POLICY";
46 case RMW_QOS_POLICY_LIVELINESS_LEASE_DURATION:
47 return "LIVELINESS_LEASE_DURATION_QOS_POLICY";
48 case RMW_QOS_POLICY_AVOID_ROS_NAMESPACE_CONVENTIONS:
49 return "AVOID_ROS_NAMESPACE_CONVENTIONS_QOS_POLICY";
51 return "INVALID_QOS_POLICY";
56 rmw_qos_history_policy_t history_policy_arg,
size_t depth_arg,
57 bool print_depth_warning)
58 : history_policy(history_policy_arg), depth(depth_arg)
60 if (history_policy == RMW_QOS_POLICY_HISTORY_KEEP_LAST && depth == 0 && print_depth_warning) {
64 "A zero depth with KEEP_LAST doesn't make sense; no data could be stored. "
65 "This will be interpreted as SYSTEM_DEFAULT");
72 switch (rmw_qos.history) {
73 case RMW_QOS_POLICY_HISTORY_KEEP_ALL:
75 case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
76 return KeepLast(rmw_qos.depth,
false);
77 case RMW_QOS_POLICY_HISTORY_KEEP_LAST:
78 case RMW_QOS_POLICY_HISTORY_UNKNOWN:
81 throw std::invalid_argument(
82 "Invalid history policy enum value passed to QoSInitialization::from_rmw");
90 KeepLast::KeepLast(
size_t depth,
bool print_depth_warning)
91 : QoSInitialization(RMW_QOS_POLICY_HISTORY_KEEP_LAST, depth, print_depth_warning)
97 const rmw_qos_profile_t & initial_profile)
98 : rmw_qos_profile_(initial_profile)
100 rmw_qos_profile_.history = qos_initialization.history_policy;
101 rmw_qos_profile_.depth = qos_initialization.depth;
111 return rmw_qos_profile_;
114 const rmw_qos_profile_t &
117 return rmw_qos_profile_;
123 rmw_qos_profile_.history =
history;
130 rmw_qos_profile_.history =
static_cast<rmw_qos_history_policy_t
>(
history);
141 "A zero depth with KEEP_LAST doesn't make sense; no data could be stored."
142 "This will be interpreted as SYSTEM_DEFAULT");
145 rmw_qos_profile_.history = RMW_QOS_POLICY_HISTORY_KEEP_LAST;
146 rmw_qos_profile_.depth =
depth;
153 rmw_qos_profile_.history = RMW_QOS_POLICY_HISTORY_KEEP_ALL;
154 rmw_qos_profile_.depth = 0;
168 rmw_qos_profile_.reliability =
static_cast<rmw_qos_reliability_policy_t
>(
reliability);
175 return this->
reliability(RMW_QOS_POLICY_RELIABILITY_RELIABLE);
181 return this->
reliability(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT);
187 return this->
reliability(RMW_QOS_POLICY_RELIABILITY_BEST_AVAILABLE);
200 rmw_qos_profile_.durability =
static_cast<rmw_qos_durability_policy_t
>(
durability);
207 return this->
durability(RMW_QOS_POLICY_DURABILITY_VOLATILE);
213 return this->
durability(RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL);
219 return this->
durability(RMW_QOS_POLICY_DURABILITY_BEST_AVAILABLE);
225 rmw_qos_profile_.deadline =
deadline;
238 rmw_qos_profile_.lifespan =
lifespan;
258 rmw_qos_profile_.liveliness =
static_cast<rmw_qos_liveliness_policy_t
>(
liveliness);
286 return static_cast<HistoryPolicy
>(rmw_qos_profile_.history);
295 return static_cast<ReliabilityPolicy
>(rmw_qos_profile_.reliability);
301 return static_cast<DurabilityPolicy
>(rmw_qos_profile_.durability);
305 QoS::deadline()
const {
return Duration::from_rmw_time(rmw_qos_profile_.deadline);}
308 QoS::lifespan()
const {
return Duration::from_rmw_time(rmw_qos_profile_.lifespan);}
313 return static_cast<LivelinessPolicy
>(rmw_qos_profile_.liveliness);
319 return Duration::from_rmw_time(rmw_qos_profile_.liveliness_lease_duration);
325 return rmw_qos_profile_.avoid_ros_namespace_conventions;
331 bool operator==(
const rmw_time_t & left,
const rmw_time_t & right)
333 return left.sec == right.sec && left.nsec == right.nsec;
341 return pl.history == pr.history &&
342 pl.depth == pr.depth &&
343 pl.reliability == pr.reliability &&
344 pl.durability == pr.durability &&
345 pl.deadline == pr.deadline &&
346 pl.lifespan == pr.lifespan &&
347 pl.liveliness == pr.liveliness &&
348 pl.liveliness_lease_duration == pr.liveliness_lease_duration &&
349 pl.avoid_ros_namespace_conventions == pr.avoid_ros_namespace_conventions;
352 bool operator!=(
const QoS & left,
const QoS & right)
354 return !(left == right);
357 QoSCheckCompatibleResult
360 rmw_qos_compatibility_type_t compatible;
361 const size_t reason_size = 2048u;
362 char reason_c_str[reason_size] =
"";
363 rmw_ret_t ret = rmw_qos_profile_check_compatible(
369 if (RMW_RET_OK != ret) {
370 std::string error_str(rmw_get_error_string().str);
376 result.
reason = std::string(reason_c_str);
378 switch (compatible) {
379 case RMW_QOS_COMPATIBILITY_OK:
382 case RMW_QOS_COMPATIBILITY_WARNING:
385 case RMW_QOS_COMPATIBILITY_ERROR:
390 "Unexpected compatibility value returned by rmw '" + std::to_string(compatible) +
396 ClockQoS::ClockQoS(
const QoSInitialization & qos_initialization)
399 : QoS(qos_initialization, rmw_qos_profile_sensor_data)
402 SensorDataQoS::SensorDataQoS(
const QoSInitialization & qos_initialization)
403 : QoS(qos_initialization, rmw_qos_profile_sensor_data)
406 ParametersQoS::ParametersQoS(
const QoSInitialization & qos_initialization)
407 : QoS(qos_initialization, rmw_qos_profile_parameters)
410 ServicesQoS::ServicesQoS(
const QoSInitialization & qos_initialization)
411 : QoS(qos_initialization, rmw_qos_profile_services_default)
414 ParameterEventsQoS::ParameterEventsQoS(
const QoSInitialization & qos_initialization)
415 : QoS(qos_initialization, rmw_qos_profile_parameter_events)
418 RosoutQoS::RosoutQoS(
const QoSInitialization & rosout_initialization)
419 : QoS(rosout_initialization, rmw_qos_profile_rosout_default)
422 SystemDefaultsQoS::SystemDefaultsQoS(
const QoSInitialization & qos_initialization)
423 : QoS(qos_initialization, rmw_qos_profile_system_default)
426 BestAvailableQoS::BestAvailableQoS(
const QoSInitialization & qos_initialization)
427 : QoS(qos_initialization, rmw_qos_profile_best_available)
rmw_time_t to_rmw_time() const
Convert Duration into rmw_time_t.
Encapsulation of Quality of Service settings.
QoS & durability_best_available()
Set the durability setting to best available.
QoS & best_effort()
Set the reliability setting to best effort.
bool avoid_ros_namespace_conventions() const
Get the avoid ros namespace convention setting.
QoS & reliable()
Set the reliability setting to reliable.
QoS & keep_all()
Set the history to keep all.
rclcpp::Duration deadline() const
Get the deadline duration setting.
DurabilityPolicy durability() const
Get the durability policy.
rclcpp::Duration lifespan() const
Get the lifespan duration setting.
QoS & durability_volatile()
Set the durability setting to volatile.
ReliabilityPolicy reliability() const
Get the reliability policy.
LivelinessPolicy liveliness() const
Get the liveliness policy.
HistoryPolicy history() const
Get the history qos policy.
QoS(const QoSInitialization &qos_initialization, const rmw_qos_profile_t &initial_profile=rmw_qos_profile_default)
Create a QoS by specifying only the history policy and history depth.
QoS & reliability_best_available()
Set the reliability setting to best available.
QoS & transient_local()
Set the durability setting to transient local.
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
size_t depth() const
Get the history depth.
rclcpp::Duration liveliness_lease_duration() const
Get the liveliness lease duration setting.
QoS & keep_last(size_t depth)
Set the history to keep last.
Thrown if a QoS compatibility check fails.
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.
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.
RCLCPP_PUBLIC Logger get_logger(const std::string &name)
Return a named logger.
Use to initialize the QoS with the keep_all history setting.
Use to initialize the QoS with the keep_last history setting and the given depth.
Result type for checking QoS compatibility.
QoSCompatibility compatibility
Compatibility result.
std::string reason
Reason for a (possible) incompatibility.
QoS initialization values, cannot be created directly, use KeepAll or KeepLast instead.
QoSInitialization(rmw_qos_history_policy_t history_policy_arg, size_t depth_arg, bool print_depth_warning=true)
Constructor which takes both a history policy and a depth (even if it would be unused).
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.