15 #ifndef RCLCPP__PUBLISHER_HPP_ 16 #define RCLCPP__PUBLISHER_HPP_ 46 template<
typename MessageT,
typename AllocatorT>
50 template<
typename MessageT,
typename AllocatorT = std::allocator<
void>>
63 rclcpp::node_interfaces::NodeBaseInterface * node_base,
64 const
std::
string & topic,
70 *rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>(),
71 options.template to_rcl_publisher_options<MessageT>(qos)),
112 "intraprocess communication is not allowed with keep all history qos policy");
116 "intraprocess communication is not allowed with a zero qos history depth value");
120 "intraprocess communication allowed only with volatile durability");
122 uint64_t intra_process_publisher_id = ipm->add_publisher(this->
shared_from_this());
124 intra_process_publisher_id,
171 bool inter_process_publish_needed =
174 if (inter_process_publish_needed) {
216 if (!loaned_msg.is_valid()) {
221 throw std::runtime_error(
"storing loaned messages in intra process is not supported yet");
272 throw std::runtime_error(
"storing serialized messages in intra process is not supported yet");
306 "intra process publish called after destruction of intra process manager");
312 ipm->template do_intra_process_publish<MessageT, AllocatorT>(
324 "intra process publish called after destruction of intra process manager");
330 return ipm->template do_intra_process_publish_and_return_shared<MessageT, AllocatorT>(
350 #endif // RCLCPP__PUBLISHER_HPP_ uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:221
void do_serialized_publish(const rcl_serialized_message_t *serialized_msg)
Definition: publisher.hpp:268
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)
T shared_from_this(T... args)
virtual ~Publisher()
Definition: publisher.hpp:129
size_t get_intra_process_subscription_count() const
Get intraprocess subscription count.
typename MessageAllocatorTraits::allocator_type MessageAllocator
Definition: publisher.hpp:55
virtual void publish(std::unique_ptr< MessageT, MessageDeleter > msg)
Send a message to the topic for this publisher.
Definition: publisher.hpp:159
Encapsulation of Quality of Service settings.
Definition: qos.hpp:55
std::shared_ptr< const MessageT > do_intra_process_publish_and_return_shared(std::unique_ptr< MessageT, MessageDeleter > msg)
Definition: publisher.hpp:319
PublisherEventCallbacks event_callbacks
Callbacks for various events related to publishers.
Definition: publisher_options.hpp:45
void do_inter_process_publish(const MessageT &msg)
Definition: publisher.hpp:248
RMW_QOS_POLICY_HISTORY_KEEP_ALL
Definition: publisher_base.hpp:55
virtual rclcpp::Context::SharedPtr get_context()=0
Return the context of the node.
void publish(rclcpp::LoanedMessage< MessageT, AllocatorT > &&loaned_msg)
Publish an instance of a LoanedMessage.
Definition: publisher.hpp:214
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
std::shared_ptr< MessageAllocator > message_allocator_
Definition: publisher.hpp:343
QOSLivelinessLostCallbackType liveliness_callback
Definition: qos_event.hpp:45
bool intra_process_is_enabled_
Definition: publisher_base.hpp:219
void do_intra_process_publish(std::unique_ptr< MessageT, MessageDeleter > msg)
Definition: publisher.hpp:301
allocator::Deleter< MessageAllocator, rcl_interfaces::msg::ParameterEvent > MessageDeleter
Definition: publisher.hpp:56
enum rmw_qos_durability_policy_t durability
size_t get_subscription_count() const
Get subscription count.
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.
bool can_loan_messages() const
Check if publisher instance can loan messages.
rcl_ret_t rcl_publish_loaned_message(const rcl_publisher_t *publisher, void *ros_message, rmw_publisher_allocation_t *allocation)
std::shared_ptr< MessageAllocator > get_allocator() const
Definition: publisher.hpp:241
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
RMW_QOS_POLICY_DURABILITY_VOLATILE
bool resolve_use_intra_process(const OptionsT &options, const NodeBaseT &node_base)
Return whether or not intra process is enabled, resolving "NodeDefault" if needed.
Definition: resolve_use_intra_process.hpp:31
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
bool rcl_context_is_valid(rcl_context_t *context)
#define RCL_RET_PUBLISHER_INVALID
rclcpp::LoanedMessage< MessageT, AllocatorT > borrow_loaned_message()
Borrow a loaned ROS message from the middleware.
Definition: publisher.hpp:148
This class performs intra process communication between nodes.
Definition: intra_process_manager.hpp:91
enum rmw_qos_history_policy_t history
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
virtual void publish(const MessageT &msg)
Definition: publisher.hpp:183
A publisher publishes messages of any type to a topic.
Definition: publisher.hpp:51
bool rcl_publisher_is_valid_except_context(const rcl_publisher_t *publisher)
virtual void post_init_setup(rclcpp::node_interfaces::NodeBaseInterface *node_base, const std::string &topic, const rclcpp::QoS &qos, const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &options)
Called post construction, so that construction may continue after shared_from_this() works...
Definition: publisher.hpp:94
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:57
RCL_PUBLISHER_OFFERED_DEADLINE_MISSED
QOSDeadlineOfferedCallbackType deadline_callback
Definition: qos_event.hpp:44
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:220
allocator::AllocRebind< rcl_interfaces::msg::ParameterEvent, std::allocator< void > > MessageAllocatorTraits
Definition: publisher.hpp:54
void do_loaned_message_publish(MessageT *msg)
Definition: publisher.hpp:281
MessageDeleter message_deleter_
Definition: publisher.hpp:345
void setup_intra_process(uint64_t intra_process_publisher_id, IntraProcessManagerSharedPtr ipm)
Implementation utility function used to setup intra process publishing after creation.
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
const rclcpp::PublisherOptionsWithAllocator< AllocatorT > options_
Copy of original options passed during construction.
Definition: publisher.hpp:341
RCL_PUBLISHER_LIVELINESS_LOST
void publish(const rcl_serialized_message_t &serialized_msg)
Definition: publisher.hpp:200
Definition: loaned_message.hpp:32
void add_event_handler(const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
Definition: publisher_base.hpp:199
rcl_context_t * rcl_publisher_get_context(const rcl_publisher_t *publisher)
rcl_publisher_t publisher_handle_
Definition: publisher_base.hpp:213