16 #include "rclcpp/generic_publisher.hpp"
30 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to publish serialized message");
36 auto loaned_message = borrow_loaned_message();
38 publish_loaned_message(loaned_message);
41 void * GenericPublisher::borrow_loaned_message()
43 void * loaned_message =
nullptr;
47 if (return_code != RMW_RET_OK) {
49 rclcpp::exceptions::throw_from_rcl_error(
51 "current middleware cannot support loan messages");
53 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to borrow loaned msg");
56 return loaned_message;
59 void GenericPublisher::deserialize_message(
60 const rmw_serialized_message_t & serialized_message,
61 void * deserialized_msg)
63 auto return_code = rmw_deserialize(&serialized_message, &type_support_, deserialized_msg);
64 if (return_code != RMW_RET_OK) {
65 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to deserialize msg");
69 void GenericPublisher::publish_loaned_message(
void * loaned_message)
75 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to publish loaned message");
RCLCPP_PUBLIC void publish(const rclcpp::SerializedMessage &message)
Publish a rclcpp::SerializedMessage.
RCLCPP_PUBLIC void publish_as_loaned_msg(const rclcpp::SerializedMessage &message)
RCLCPP_PUBLIC std::shared_ptr< rcl_publisher_t > get_publisher_handle()
Get the rcl publisher handle.
Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.
rcl_serialized_message_t & get_rcl_serialized_message()
Get the underlying rcl_serialized_t handle.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_publish_loaned_message(const rcl_publisher_t *publisher, void *ros_message, rmw_publisher_allocation_t *allocation)
Publish a loaned message on a topic using a publisher.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_publish_serialized_message(const rcl_publisher_t *publisher, const rcl_serialized_message_t *serialized_message, rmw_publisher_allocation_t *allocation)
Publish a serialized message on a topic using a publisher.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_borrow_loaned_message(const rcl_publisher_t *publisher, const rosidl_message_type_support_t *type_support, void **ros_message)
Borrow a loaned message.
#define RCL_RET_UNSUPPORTED
Unsupported return code.
#define RCL_RET_OK
Success return code.