Skip to content

Commit

Permalink
Allow publishing borrowed messages with intra-process enabled (ros2#2108
Browse files Browse the repository at this point in the history
)

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany authored and Alberto Soragna committed Apr 28, 2023
1 parent c3052ca commit fe51f16
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
6 changes: 1 addition & 5 deletions rclcpp/include/rclcpp/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ class Publisher : public PublisherBase
if (!loaned_msg.is_valid()) {
throw std::runtime_error("loaned message is not valid");
}
if (intra_process_is_enabled_) {
// TODO(Karsten1987): support loaned message passed by intraprocess
throw std::runtime_error("storing loaned messages in intra process is not supported yet");
}

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

Expand Down
2 changes: 1 addition & 1 deletion rclcpp/src/rclcpp/publisher_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ PublisherBase::assert_liveliness() const
bool
PublisherBase::can_loan_messages() const
{
return rcl_publisher_can_loan_messages(publisher_handle_.get());
return !intra_process_is_enabled_ && rcl_publisher_can_loan_messages(publisher_handle_.get());
}

bool
Expand Down
4 changes: 1 addition & 3 deletions rclcpp/test/rclcpp/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ TEST_F(TestPublisher, intra_process_publish_failures) {
std::allocator<void> allocator;
{
rclcpp::LoanedMessage<test_msgs::msg::Empty> loaned_msg(*publisher, allocator);
RCLCPP_EXPECT_THROW_EQ(
publisher->publish(std::move(loaned_msg)),
std::runtime_error("storing loaned messages in intra process is not supported yet"));
EXPECT_NO_THROW(publisher->publish(std::move(loaned_msg)));
}

{
Expand Down

0 comments on commit fe51f16

Please sign in to comment.