15 #ifndef RCLCPP__PUBLISHER_HPP_ 16 #define RCLCPP__PUBLISHER_HPP_ 30 #include "rcl_interfaces/msg/intra_process_message.hpp" 43 namespace node_interfaces
45 class NodeTopicsInterface;
50 friend ::rclcpp::node_interfaces::NodeTopicsInterface;
68 const rosidl_message_type_support_t & type_support,
72 virtual ~PublisherBase();
78 get_topic_name()
const;
84 get_queue_size()
const;
96 get_intra_process_gid()
const;
102 get_publisher_handle();
108 get_publisher_handle()
const;
136 uint64_t intra_process_publisher_id,
154 template<
typename MessageT,
typename Alloc = std::allocator<
void>>
166 rclcpp::node_interfaces::NodeBaseInterface * node_base,
167 const
std::
string & topic,
173 *rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>(),
175 message_allocator_(allocator)
191 this->do_inter_process_publish(msg.
get());
192 if (store_intra_process_message_) {
200 MessageT * msg_ptr = msg.
get();
202 uint64_t message_seq =
203 store_intra_process_message_(intra_process_publisher_id_, msg_ptr,
typeid(MessageT));
204 rcl_interfaces::msg::IntraProcessMessage ipm;
205 ipm.publisher_id = intra_process_publisher_id_;
206 ipm.message_sequence = message_seq;
207 auto status =
rcl_publish(&intra_process_publisher_handle_, &ipm);
231 if (!store_intra_process_message_) {
233 return this->do_inter_process_publish(msg.
get());
240 auto ptr = MessageAllocTraits::allocate(*message_allocator_.get(), 1);
241 MessageAllocTraits::construct(*message_allocator_.get(), ptr, *msg.
get());
243 return this->publish(unique_msg);
250 if (!store_intra_process_message_) {
252 return this->do_inter_process_publish(msg.
get());
259 auto ptr = MessageAllocTraits::allocate(*message_allocator_.get(), 1);
260 MessageAllocTraits::construct(*message_allocator_.get(), ptr, *msg.
get());
262 return this->publish(unique_msg);
269 if (!store_intra_process_message_) {
271 return this->do_inter_process_publish(&msg);
274 auto ptr = MessageAllocTraits::allocate(*message_allocator_.get(), 1);
275 MessageAllocTraits::construct(*message_allocator_.get(), ptr, msg);
277 return this->publish(unique_msg);
286 return this->publish(*msg);
292 if (store_intra_process_message_) {
294 throw std::runtime_error(
"storing serialized messages in intra process is not supported yet");
305 return this->publish(serialized_msg.
get());
310 return message_allocator_;
317 auto status =
rcl_publish(&publisher_handle_, msg);
340 #endif // RCLCPP__PUBLISHER_HPP_ uint64_t intra_process_publisher_id_
Definition: publisher.hpp:146
virtual void publish(std::shared_ptr< const MessageT > msg)
Definition: publisher.hpp:247
std::shared_ptr< MessageAlloc > get_allocator() const
Definition: publisher.hpp:308
MessageDeleter message_deleter_
Definition: publisher.hpp:335
typename MessageAllocTraits::allocator_type MessageAlloc
Definition: publisher.hpp:159
Definition: publisher.hpp:48
Definition: allocator_common.hpp:24
virtual ~Publisher()
Definition: publisher.hpp:180
allocator::Deleter< MessageAlloc, rcl_interfaces::msg::ParameterEvent > MessageDeleter
Definition: publisher.hpp:160
void set_allocator_for_deleter(D *deleter, Alloc *alloc)
Definition: allocator_deleter.hpp:72
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.
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
rcl_publisher_t rcl_get_zero_initialized_publisher(void)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
bool rcl_context_is_valid(rcl_context_t *context)
rmw_gid_t rmw_gid_
Definition: publisher.hpp:149
#define RCL_RET_PUBLISHER_INVALID
void publish(std::shared_ptr< const rcl_serialized_message_t > serialized_msg)
Definition: publisher.hpp:303
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
A publisher publishes messages of any type to a topic.
Definition: publisher.hpp:155
bool rcl_publisher_is_valid_except_context(const rcl_publisher_t *publisher)
virtual void publish(const MessageT *msg)
Definition: publisher.hpp:281
std::shared_ptr< rcl_node_t > rcl_node_handle_
Definition: publisher.hpp:141
void do_inter_process_publish(const MessageT *msg)
Definition: publisher.hpp:315
std::shared_ptr< MessageAlloc > message_allocator_
Definition: publisher.hpp:333
virtual void publish(std::unique_ptr< MessageT, MessageDeleter > &msg)
Send a message to the topic for this publisher.
Definition: publisher.hpp:189
virtual void publish(const MessageT &msg)
Definition: publisher.hpp:266
virtual void publish(const std::shared_ptr< MessageT > &msg)
Definition: publisher.hpp:228
StoreMessageCallbackT store_intra_process_message_
Definition: publisher.hpp:147
rcl_ret_t rcl_publish_serialized_message(const rcl_publisher_t *publisher, const rcl_serialized_message_t *serialized_message)
void publish(const rcl_serialized_message_t *serialized_msg)
Definition: publisher.hpp:290
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
allocator::AllocRebind< rcl_interfaces::msg::ParameterEvent, std::allocator< void > > MessageAllocTraits
Definition: publisher.hpp:158
rmw_gid_t intra_process_rmw_gid_
Definition: publisher.hpp:150
typename std::conditional< std::is_same< typename std::allocator_traits< Alloc >::template rebind_alloc< T >, typename std::allocator< void >::template rebind< T >::other >::value, std::default_delete< T >, AllocatorDeleter< Alloc > >::type Deleter
Definition: allocator_deleter.hpp:101
rcl_ret_t rcl_publish(const rcl_publisher_t *publisher, const void *ros_message)
rcl_context_t * rcl_publisher_get_context(const rcl_publisher_t *publisher)