Skip to content

Commit 00d3b01

Browse files
MiguelCompanyAlberto Soragna
authored andcommitted
Allow publishing borrowed messages with intra-process enabled (ros2#2108)
Signed-off-by: Miguel Company <[email protected]>
1 parent d41b913 commit 00d3b01

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

rclcpp/include/rclcpp/publisher.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,6 @@ class Publisher : public PublisherBase
405405
if (!loaned_msg.is_valid()) {
406406
throw std::runtime_error("loaned message is not valid");
407407
}
408-
if (intra_process_is_enabled_) {
409-
// TODO(Karsten1987): support loaned message passed by intraprocess
410-
throw std::runtime_error("storing loaned messages in intra process is not supported yet");
411-
}
412408

413409
// verify that publisher supports loaned messages
414410
// TODO(Karsten1987): This case separation has to be done in rclcpp
@@ -422,7 +418,7 @@ class Publisher : public PublisherBase
422418
} else {
423419
// we don't release the ownership, let the middleware copy the ros message
424420
// and thus the destructor of rclcpp::LoanedMessage cleans up the memory.
425-
this->do_inter_process_publish(loaned_msg.get());
421+
this->publish(loaned_msg.get());
426422
}
427423
}
428424

rclcpp/src/rclcpp/publisher_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ PublisherBase::assert_liveliness() const
233233
bool
234234
PublisherBase::can_loan_messages() const
235235
{
236-
return rcl_publisher_can_loan_messages(publisher_handle_.get());
236+
return !intra_process_is_enabled_ && rcl_publisher_can_loan_messages(publisher_handle_.get());
237237
}
238238

239239
bool

rclcpp/test/rclcpp/test_publisher.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,7 @@ TEST_F(TestPublisher, intra_process_publish_failures) {
406406
std::allocator<void> allocator;
407407
{
408408
rclcpp::LoanedMessage<test_msgs::msg::Empty> loaned_msg(*publisher, allocator);
409-
RCLCPP_EXPECT_THROW_EQ(
410-
publisher->publish(std::move(loaned_msg)),
411-
std::runtime_error("storing loaned messages in intra process is not supported yet"));
409+
EXPECT_NO_THROW(publisher->publish(std::move(loaned_msg)));
412410
}
413411

414412
{

0 commit comments

Comments
 (0)