15 #ifndef RCLCPP__PUBLISHER_HPP_ 16 #define RCLCPP__PUBLISHER_HPP_ 31 #include "rcl_interfaces/msg/intra_process_message.hpp" 45 template<
typename MessageT,
typename Alloc = std::allocator<
void>>
58 rclcpp::node_interfaces::NodeBaseInterface * node_base,
59 const
std::
string & topic,
66 *rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>(),
72 if (event_callbacks.deadline_callback) {
76 if (event_callbacks.liveliness_callback) {
85 mapped_ring_buffer::MappedRingBufferBase::SharedPtr
112 uint64_t message_seq;
113 bool inter_process_publish_needed =
116 if (inter_process_publish_needed) {
125 if (inter_process_publish_needed) {
133 "publishing an unique_ptr is prefered when using intra process communication." 134 " If using a shared_ptr, use publish(*msg).")]]
162 "Use publish(*msg). Check against nullptr before calling if necessary.")]]
182 "Use publish(*serialized_msg). Check against nullptr before calling if necessary.")]]
193 "Use publish(*serialized_msg). Check against nullptr before calling if necessary.")]]
231 throw std::runtime_error(
"storing serialized messages in intra process is not supported yet");
242 rcl_interfaces::msg::IntraProcessMessage ipm;
244 ipm.message_sequence = message_seq;
263 uint64_t publisher_id,
269 "intra process publish called after destruction of intra process manager");
274 uint64_t message_seq =
275 ipm->template store_intra_process_message<MessageT, Alloc>(publisher_id, msg);
281 uint64_t publisher_id,
287 "intra process publish called after destruction of intra process manager");
292 uint64_t message_seq =
293 ipm->template store_intra_process_message<MessageT, Alloc>(publisher_id,
std::move(msg));
304 #endif // RCLCPP__PUBLISHER_HPP_ uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:224
std::shared_ptr< MessageAlloc > get_allocator() const
Definition: publisher.hpp:201
rcl_ret_t rcl_publish_serialized_message(const rcl_publisher_t *publisher, const rcl_serialized_message_t *serialized_message, rmw_publisher_allocation_t *allocation)
rcl_ret_t rcl_publish(const rcl_publisher_t *publisher, const void *ros_message, rmw_publisher_allocation_t *allocation)
size_t get_intra_process_subscription_count() const
Get intraprocess subscription count.
void publish(const rcl_serialized_message_t &serialized_msg)
Definition: publisher.hpp:174
MessageDeleter message_deleter_
Definition: publisher.hpp:299
Contains callbacks for various types of events a Publisher can receive from the middleware.
Definition: qos_event.hpp:42
typename MessageAllocTraits::allocator_type MessageAlloc
Definition: publisher.hpp:50
Definition: publisher_base.hpp:55
void do_intra_process_publish(uint64_t message_seq)
Definition: publisher.hpp:240
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
virtual ~Publisher()
Definition: publisher.hpp:82
bool intra_process_is_enabled_
Definition: publisher_base.hpp:222
Ring buffer container of shared_ptr's or unique_ptr's of T, which can be accessed by a key...
Definition: mapped_ring_buffer.hpp:60
rcl_publisher_t intra_process_publisher_handle_
Definition: publisher_base.hpp:216
void do_serialized_publish(const rcl_serialized_message_t *serialized_msg)
Definition: publisher.hpp:227
size_t get_subscription_count() const
Get subscription count.
allocator::Deleter< MessageAlloc, rcl_interfaces::msg::ParameterEvent > MessageDeleter
Definition: publisher.hpp:51
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
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
bool rcl_context_is_valid(rcl_context_t *context)
virtual void publish(std::unique_ptr< MessageT, MessageDeleter > msg)
Send a message to the topic for this publisher.
Definition: publisher.hpp:100
#define RCL_RET_PUBLISHER_INVALID
void publish(std::shared_ptr< const rcl_serialized_message_t > serialized_msg)
Definition: publisher.hpp:196
A publisher publishes messages of any type to a topic.
Definition: publisher.hpp:46
bool rcl_publisher_is_valid_except_context(const rcl_publisher_t *publisher)
virtual void publish(const MessageT *msg)
Definition: publisher.hpp:165
void do_inter_process_publish(const MessageT *msg)
Definition: publisher.hpp:208
std::shared_ptr< MessageAlloc > message_allocator_
Definition: publisher.hpp:297
RCL_PUBLISHER_OFFERED_DEADLINE_MISSED
virtual void publish(const MessageT &msg)
Definition: publisher.hpp:143
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:223
void publish(const rcl_serialized_message_t *serialized_msg)
Definition: publisher.hpp:185
uint64_t store_intra_process_message(uint64_t publisher_id, std::unique_ptr< MessageT, MessageDeleter > msg)
Definition: publisher.hpp:280
allocator::AllocRebind< rcl_interfaces::msg::ParameterEvent, std::allocator< void > > MessageAllocTraits
Definition: publisher.hpp:49
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
mapped_ring_buffer::MappedRingBufferBase::SharedPtr make_mapped_ring_buffer(size_t size) const override
Implementation utility function that creates a typed mapped ring buffer.
Definition: publisher.hpp:86
RCL_PUBLISHER_LIVELINESS_LOST
virtual void publish(const std::shared_ptr< const MessageT > &msg)
Definition: publisher.hpp:137
void add_event_handler(const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
Definition: publisher_base.hpp:201
rcl_context_t * rcl_publisher_get_context(const rcl_publisher_t *publisher)
uint64_t store_intra_process_message(uint64_t publisher_id, std::shared_ptr< const MessageT > msg)
Definition: publisher.hpp:262
rcl_publisher_t publisher_handle_
Definition: publisher_base.hpp:215