Skip to content

Commit 99f1d8d

Browse files
apply actual QoS from rmw to the IPC publisher. (backport #2707) (#2711)
* apply actual QoS from rmw to the IPC publisher. (#2707) * apply actual QoS from rmw to the IPC publisher. Signed-off-by: Tomoya Fujita <[email protected]> * address uncrustify warning. Signed-off-by: Tomoya Fujita <[email protected]> --------- Signed-off-by: Tomoya Fujita <[email protected]> (cherry picked from commit 016cfea) # Conflicts: # rclcpp/include/rclcpp/publisher.hpp * resolve conflicts for backport humble. Signed-off-by: Tomoya Fujita <[email protected]> * address uncrustify failure. Signed-off-by: Tomoya Fujita <[email protected]> --------- Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Tomoya Fujita <[email protected]>
1 parent 1a353f0 commit 99f1d8d

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

rclcpp/include/rclcpp/publisher.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,31 @@ class Publisher : public PublisherBase
177177
const rclcpp::QoS & qos,
178178
const rclcpp::PublisherOptionsWithAllocator<AllocatorT> & options)
179179
{
180-
// Topic is unused for now.
180+
(void)qos;
181181
(void)options;
182182

183183
// If needed, setup intra process communication.
184184
if (rclcpp::detail::resolve_use_intra_process(options_, *node_base)) {
185185
auto context = node_base->get_context();
186186
// Get the intra process manager instance for this context.
187187
auto ipm = context->get_sub_context<rclcpp::experimental::IntraProcessManager>();
188-
// Register the publisher with the intra process manager.
189-
if (qos.history() != rclcpp::HistoryPolicy::KeepLast) {
188+
// Check if the QoS is compatible with intra-process.
189+
auto qos_profile = get_actual_qos();
190+
if (qos_profile.history() != rclcpp::HistoryPolicy::KeepLast) {
190191
throw std::invalid_argument(
191192
"intraprocess communication on topic '" + topic +
192193
"' allowed only with keep last history qos policy");
193194
}
194-
if (qos.depth() == 0) {
195+
if (qos_profile.depth() == 0) {
195196
throw std::invalid_argument(
196197
"intraprocess communication on topic '" + topic +
197198
"' is not allowed with a zero qos history depth value");
198199
}
199-
if (qos.durability() != rclcpp::DurabilityPolicy::Volatile) {
200+
if (qos_profile.durability() != rclcpp::DurabilityPolicy::Volatile) {
200201
throw std::invalid_argument(
201202
"intraprocess communication allowed only with volatile durability");
202203
}
204+
// Register the publisher with the intra process manager.
203205
uint64_t intra_process_publisher_id = ipm->add_publisher(this->shared_from_this());
204206
this->setup_intra_process(
205207
intra_process_publisher_id,

rclcpp/test/rclcpp/test_create_subscription.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,19 @@ TEST_F(TestCreateSubscription, create_with_statistics) {
9393
ASSERT_NE(nullptr, subscription);
9494
EXPECT_STREQ("/ns/topic_name", subscription->get_topic_name());
9595
}
96+
97+
TEST_F(TestCreateSubscription, create_with_intra_process_com) {
98+
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
99+
auto options = rclcpp::SubscriptionOptions();
100+
options.use_intra_process_comm = rclcpp::IntraProcessSetting::Enable;
101+
102+
auto callback = [](test_msgs::msg::Empty::ConstSharedPtr) {};
103+
rclcpp::Subscription<test_msgs::msg::Empty>::SharedPtr subscription;
104+
ASSERT_NO_THROW(
105+
{
106+
subscription = rclcpp::create_subscription<test_msgs::msg::Empty>(
107+
node, "topic_name", rclcpp::SystemDefaultsQoS(), callback, options);
108+
});
109+
ASSERT_NE(nullptr, subscription);
110+
EXPECT_STREQ("/ns/topic_name", subscription->get_topic_name());
111+
}

rclcpp/test/rclcpp/test_publisher.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ TEST_F(TestPublisher, various_creation_signatures) {
176176
}
177177
}
178178

179+
/*
180+
Testing publisher with intraprocess enabled and SystemDefaultQoS
181+
*/
182+
TEST_F(TestPublisher, test_publisher_with_system_default_qos) {
183+
initialize(rclcpp::NodeOptions().use_intra_process_comms(false));
184+
// explicitly enable intra-process comm with publisher option
185+
auto options = rclcpp::PublisherOptions();
186+
options.use_intra_process_comm = rclcpp::IntraProcessSetting::Enable;
187+
using test_msgs::msg::Empty;
188+
ASSERT_NO_THROW(
189+
{
190+
auto publisher = node->create_publisher<Empty>("topic", rclcpp::SystemDefaultsQoS());
191+
});
192+
}
193+
179194
/*
180195
Testing publisher with intraprocess enabled and invalid QoS
181196
*/
@@ -418,12 +433,10 @@ TEST_F(TestPublisher, intra_process_publish_failures) {
418433
publisher->publish(std::move(loaned_msg)),
419434
std::runtime_error("loaned message is not valid"));
420435
}
421-
RCLCPP_EXPECT_THROW_EQ(
422-
node->create_publisher<test_msgs::msg::Empty>(
423-
"topic", rclcpp::QoS(0), options),
424-
std::invalid_argument(
425-
"intraprocess communication on topic 'topic' "
426-
"is not allowed with a zero qos history depth value"));
436+
// a zero depth with KEEP_LAST doesn't make sense,
437+
// this will be interpreted as SystemDefaultQoS by rclcpp.
438+
EXPECT_NO_THROW(
439+
node->create_publisher<test_msgs::msg::Empty>("topic", rclcpp::QoS(0), options));
427440
}
428441

429442
TEST_F(TestPublisher, inter_process_publish_failures) {

0 commit comments

Comments
 (0)