Skip to content

Commit 3db2ece

Browse files
authored
Fix the keep_last warning when using system defaults. (#2082)
If the user creates SystemDefaultsQoS setting, they are explicitly asking for SystemDefaults. In that case, we should *not* warn, and just let the underlying RMW choose what it wants. Implement that here by passing a boolean parameter through that decides when we should print out the warning, and then skip printing that warning when SystemDefaultsQoS is created. Signed-off-by: Chris Lalancette <[email protected]> Signed-off-by: Chris Lalancette <[email protected]>
1 parent 1bbb033 commit 3db2ece

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

rclcpp/include/rclcpp/qos.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ struct RCLCPP_PUBLIC QoSInitialization
8080
size_t depth;
8181

8282
/// Constructor which takes both a history policy and a depth (even if it would be unused).
83-
QoSInitialization(rmw_qos_history_policy_t history_policy_arg, size_t depth_arg);
83+
QoSInitialization(
84+
rmw_qos_history_policy_t history_policy_arg, size_t depth_arg,
85+
bool print_depth_warning = true);
8486

8587
/// Create a QoSInitialization from an existing rmw_qos_profile_t, using its history and depth.
8688
static
@@ -97,7 +99,7 @@ struct RCLCPP_PUBLIC KeepAll : public rclcpp::QoSInitialization
9799
/// Use to initialize the QoS with the keep_last history setting and the given depth.
98100
struct RCLCPP_PUBLIC KeepLast : public rclcpp::QoSInitialization
99101
{
100-
explicit KeepLast(size_t depth);
102+
explicit KeepLast(size_t depth, bool print_depth_warning = true);
101103
};
102104

103105
/// Encapsulation of Quality of Service settings.

rclcpp/src/rclcpp/qos.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,29 @@ std::string qos_policy_name_from_kind(rmw_qos_policy_kind_t policy_kind)
4545
}
4646
}
4747

48-
QoSInitialization::QoSInitialization(rmw_qos_history_policy_t history_policy_arg, size_t depth_arg)
48+
QoSInitialization::QoSInitialization(
49+
rmw_qos_history_policy_t history_policy_arg, size_t depth_arg,
50+
bool print_depth_warning)
4951
: history_policy(history_policy_arg), depth(depth_arg)
50-
{}
52+
{
53+
if (history_policy == RMW_QOS_POLICY_HISTORY_KEEP_LAST && depth == 0 && print_depth_warning) {
54+
RCLCPP_WARN_ONCE(
55+
rclcpp::get_logger(
56+
"rclcpp"),
57+
"A zero depth with KEEP_LAST doesn't make sense; no data could be stored. "
58+
"This will be interpreted as SYSTEM_DEFAULT");
59+
}
60+
}
5161

5262
QoSInitialization
5363
QoSInitialization::from_rmw(const rmw_qos_profile_t & rmw_qos)
5464
{
5565
switch (rmw_qos.history) {
5666
case RMW_QOS_POLICY_HISTORY_KEEP_ALL:
5767
return KeepAll();
58-
case RMW_QOS_POLICY_HISTORY_KEEP_LAST:
5968
case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
69+
return KeepLast(rmw_qos.depth, false);
70+
case RMW_QOS_POLICY_HISTORY_KEEP_LAST:
6071
case RMW_QOS_POLICY_HISTORY_UNKNOWN:
6172
default:
6273
return KeepLast(rmw_qos.depth);
@@ -67,32 +78,16 @@ KeepAll::KeepAll()
6778
: QoSInitialization(RMW_QOS_POLICY_HISTORY_KEEP_ALL, 0)
6879
{}
6980

70-
KeepLast::KeepLast(size_t depth)
71-
: QoSInitialization(RMW_QOS_POLICY_HISTORY_KEEP_LAST, depth)
81+
KeepLast::KeepLast(size_t depth, bool print_depth_warning)
82+
: QoSInitialization(RMW_QOS_POLICY_HISTORY_KEEP_LAST, depth, print_depth_warning)
7283
{
73-
if (depth == 0) {
74-
RCLCPP_WARN_ONCE(
75-
rclcpp::get_logger(
76-
"rclcpp"),
77-
"A zero depth with KEEP_LAST doesn't make sense; no data could be stored."
78-
"This will be interpreted as SYSTEM_DEFAULT");
79-
}
8084
}
8185

8286
QoS::QoS(
8387
const QoSInitialization & qos_initialization,
8488
const rmw_qos_profile_t & initial_profile)
8589
: rmw_qos_profile_(initial_profile)
8690
{
87-
if (qos_initialization.history_policy == RMW_QOS_POLICY_HISTORY_KEEP_LAST &&
88-
qos_initialization.depth == 0)
89-
{
90-
RCLCPP_WARN_ONCE(
91-
rclcpp::get_logger(
92-
"rclcpp"),
93-
"A zero depth with KEEP_LAST doesn't make sense; no data could be stored."
94-
"This will be interpreted as SYSTEM_DEFAULT");
95-
}
9691
rmw_qos_profile_.history = qos_initialization.history_policy;
9792
rmw_qos_profile_.depth = qos_initialization.depth;
9893
}

0 commit comments

Comments
 (0)