rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__LOANED_MESSAGE_HPP_
16 #define RCLCPP__LOANED_MESSAGE_HPP_
25 #include "rcl/allocator.h"
26 #include "rcl/publisher.h"
31 template<
typename MessageT,
typename AllocatorT = std::allocator<
void>>
35 using MessageAllocator =
typename MessageAllocatorTraits::allocator_type;
67 void * message_ptr =
nullptr;
68 auto ret = rcl_borrow_loaned_message(
70 rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>(),
72 if (RCL_RET_OK != ret) {
75 message_ =
static_cast<MessageT *
>(message_ptr);
79 "Currently used middleware can't loan messages. Local allocator will be used.");
143 if (ret != RCL_RET_OK) {
145 error_logger,
"rcl_deallocate_loaned_message failed: %s", rcl_get_error_string().str);
209 #endif // RCLCPP__LOANED_MESSAGE_HPP_
std::shared_ptr< rcl_publisher_t > get_publisher_handle()
Get the rcl publisher handle.
LoanedMessage(LoanedMessage< MessageT > &&other)
Move semantic for RVO.
Definition: loaned_message.hpp:113
Logger get_logger(const std::string &name)
Return a named logger.
Definition: loaned_message.hpp:32
MessageT * release()
Release ownership of the ROS message instance.
Definition: loaned_message.hpp:189
MessageT * message_
Definition: loaned_message.hpp:199
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
MessageAllocator message_allocator_
Definition: loaned_message.hpp:201
virtual ~LoanedMessage()
Destructor of the LoanedMessage class.
Definition: loaned_message.hpp:131
bool is_valid() const
Validate if the message was correctly allocated.
Definition: loaned_message.hpp:164
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
Definition: publisher_base.hpp:55
const rclcpp::PublisherBase & pub_
Definition: loaned_message.hpp:197
MessageT & get() const
Access the ROS message instance.
Definition: loaned_message.hpp:177
bool can_loan_messages() const
Check if publisher instance can loan messages.
LoanedMessage(const rclcpp::PublisherBase &pub, std::allocator< MessageT > allocator)
Constructor of the LoanedMessage class.
Definition: loaned_message.hpp:59
#define RCLCPP_INFO_ONCE(logger,...)
Definition: logging.hpp:559
void throw_from_rcl_error(rcl_ret_t ret, const std::string &prefix="", const rcl_error_state_t *error_state=nullptr, void(*reset_error)()=rcl_reset_error)
Throw a C++ std::exception which was created based on an rcl error.
LoanedMessage(const rclcpp::PublisherBase *pub, std::shared_ptr< std::allocator< MessageT >> allocator)
Constructor of the LoanedMessage class.
Definition: loaned_message.hpp:106
#define RCLCPP_ERROR(logger,...)
Definition: logging.hpp:1419