16 #include "rclcpp/generic_publisher.hpp"
26 TRACETOOLS_TRACEPOINT(
34 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to publish serialized message");
40 auto loaned_message = borrow_loaned_message();
42 publish_loaned_message(loaned_message);
45 void * GenericPublisher::borrow_loaned_message()
47 void * loaned_message =
nullptr;
51 if (return_code != RMW_RET_OK) {
53 rclcpp::exceptions::throw_from_rcl_error(
55 "current middleware cannot support loan messages");
57 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to borrow loaned msg");
60 return loaned_message;
63 void GenericPublisher::deserialize_message(
64 const rmw_serialized_message_t & serialized_message,
65 void * deserialized_msg)
67 auto return_code = rmw_deserialize(&serialized_message, &type_support_, deserialized_msg);
68 if (return_code != RMW_RET_OK) {
69 rclcpp::exceptions::throw_from_rcl_error(return_code,
"failed to deserialize msg");
73 void GenericPublisher::publish_loaned_message(
void * loaned_message)
75 TRACETOOLS_TRACEPOINT(rclcpp_publish,
nullptr,
static_cast<const void *
>(loaned_message));
80 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.