Skip to content

Commit de70a81

Browse files
authored
Add QoS decoding translation for infinite durations to RMW_DURATION_INFINITE (#684)
* Add QoS decoding translation for infinite durations to RMW_DURATION_INFINITE Signed-off-by: Emerson Knapp <[email protected]>
1 parent 5236f8a commit de70a81

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

rosbag2_transport/src/rosbag2_transport/qos.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@
1919

2020
#include "qos.hpp"
2121

22+
namespace
23+
{
24+
/**
25+
* The following constants were the "Inifinity" value returned by RMW implementations before
26+
* the introduction of RMW_DURATION_INFINITE and associated RMW fixes
27+
* RMW: https://github.com/ros2/rmw/pull/301
28+
* Fast-DDS: https://github.com/ros2/rmw_fastrtps/pull/515
29+
* CycloneDDS: https://github.com/ros2/rmw_cyclonedds/pull/288
30+
* RTI Connext: https://github.com/ros2/rmw_connext/pull/491
31+
*
32+
* These values exist in bags recorded in Foxy, they need to be translated to RMW_DURATION_INFINITE
33+
* to be consistently understood for playback.
34+
* With those values, if a bag is played back in a different implementation than it was recorded,
35+
* the publishers will fail to be created with an error indicating an invalid QoS value..
36+
*/
37+
static const rmw_time_t RMW_CYCLONEDDS_FOXY_INFINITE = rmw_time_from_nsec(0x7FFFFFFFFFFFFFFFll);
38+
static const rmw_time_t RMW_FASTRTPS_FOXY_INFINITE {0x7FFFFFFFll, 0xFFFFFFFFll};
39+
static const rmw_time_t RMW_CONNEXT_FOXY_INFINITE {0x7FFFFFFFll, 0x7FFFFFFFll};
40+
} // namespace
41+
2242
namespace YAML
2343
{
2444
Node convert<rmw_time_t>::encode(const rmw_time_t & time)
@@ -33,6 +53,13 @@ bool convert<rmw_time_t>::decode(const Node & node, rmw_time_t & time)
3353
{
3454
time.sec = node["sec"].as<uint64_t>();
3555
time.nsec = node["nsec"].as<uint64_t>();
56+
if (
57+
rmw_time_equal(time, RMW_CYCLONEDDS_FOXY_INFINITE) ||
58+
rmw_time_equal(time, RMW_FASTRTPS_FOXY_INFINITE) ||
59+
rmw_time_equal(time, RMW_CONNEXT_FOXY_INFINITE))
60+
{
61+
time = RMW_DURATION_INFINITE;
62+
}
3663
return true;
3764
}
3865

rosbag2_transport/test/rosbag2_transport/test_qos.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,53 @@ TEST(TestQoS, detect_new_qos_fields)
9696
EXPECT_EQ(profile.history, RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT); // fix "unused variable"
9797
}
9898

99+
TEST(TestQoS, translates_bad_infinity_values)
100+
{
101+
// Copied from hidden symbols in qos.cpp
102+
const rmw_time_t bad_infinities[3] {
103+
rmw_time_from_nsec(0x7FFFFFFFFFFFFFFFll), // cyclone
104+
{0x7FFFFFFFll, 0xFFFFFFFFll}, // fastrtps
105+
{0x7FFFFFFFll, 0x7FFFFFFFll} // connext
106+
};
107+
rmw_time_t infinity = RMW_DURATION_INFINITE;
108+
const auto expected_qos = rosbag2_transport::Rosbag2QoS{}
109+
.default_history()
110+
.reliable()
111+
.durability_volatile()
112+
.deadline(infinity)
113+
.lifespan(infinity)
114+
.liveliness(RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT)
115+
.liveliness_lease_duration(infinity)
116+
.get_rmw_qos_profile();
117+
118+
for (const auto & infinity : bad_infinities) {
119+
std::ostringstream serialized_profile;
120+
serialized_profile <<
121+
"history: 1\n"
122+
"depth: 10\n"
123+
"reliability: 1\n"
124+
"durability: 2\n"
125+
"deadline:\n"
126+
" sec: " << infinity.sec << "\n"
127+
" nsec: " << infinity.nsec << "\n"
128+
"lifespan:\n"
129+
" sec: " << infinity.sec << "\n"
130+
" nsec: " << infinity.nsec << "\n"
131+
"liveliness: 0\n"
132+
"liveliness_lease_duration:\n"
133+
" sec: " << infinity.sec << "\n"
134+
" nsec: " << infinity.nsec << "\n"
135+
"avoid_ros_namespace_conventions: false\n";
136+
const YAML::Node loaded_node = YAML::Load(serialized_profile.str());
137+
const auto deserialized_profile = loaded_node.as<rosbag2_transport::Rosbag2QoS>();
138+
const auto actual_qos = deserialized_profile.get_rmw_qos_profile();
139+
EXPECT_TRUE(rmw_time_equal(actual_qos.lifespan, expected_qos.lifespan));
140+
EXPECT_TRUE(rmw_time_equal(actual_qos.deadline, expected_qos.deadline));
141+
EXPECT_TRUE(
142+
rmw_time_equal(
143+
actual_qos.liveliness_lease_duration, expected_qos.liveliness_lease_duration));
144+
}
145+
}
99146

100147
using rosbag2_transport::Rosbag2QoS; // NOLINT
101148
class AdaptiveQoSTest : public ::testing::Test

0 commit comments

Comments
 (0)