rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__PUBLISHER_HPP_
16 #define RCLCPP__PUBLISHER_HPP_
28 #include "rcl/error_handling.h"
43 #include "tracetools/tracetools.h"
48 template<
typename MessageT,
typename AllocatorT>
52 template<
typename MessageT,
typename AllocatorT = std::allocator<
void>>
76 rclcpp::node_interfaces::NodeBaseInterface * node_base,
77 const
std::
string & topic,
83 *rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>(),
84 options.template to_rcl_publisher_options<MessageT>(qos)),
90 if (
options_.event_callbacks.deadline_callback) {
92 options_.event_callbacks.deadline_callback,
93 RCL_PUBLISHER_OFFERED_DEADLINE_MISSED);
95 if (
options_.event_callbacks.liveliness_callback) {
97 options_.event_callbacks.liveliness_callback,
98 RCL_PUBLISHER_LIVELINESS_LOST);
100 if (
options_.event_callbacks.incompatible_qos_callback) {
102 options_.event_callbacks.incompatible_qos_callback,
103 RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);
104 }
else if (
options_.use_default_callbacks) {
111 RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);
140 "intraprocess communication is not allowed with keep all history qos policy");
144 "intraprocess communication is not allowed with a zero qos history depth value");
148 "intraprocess communication allowed only with volatile durability");
150 uint64_t intra_process_publisher_id = ipm->add_publisher(this->
shared_from_this());
152 intra_process_publisher_id,
199 bool inter_process_publish_needed =
202 if (inter_process_publish_needed) {
250 if (!loaned_msg.is_valid()) {
255 throw std::runtime_error(
"storing loaned messages in intra process is not supported yet");
287 static_cast<const void *
>(&msg));
310 throw std::runtime_error(
"storing serialized messages in intra process is not supported yet");
344 "intra process publish called after destruction of intra process manager");
350 ipm->template do_intra_process_publish<MessageT, AllocatorT>(
362 "intra process publish called after destruction of intra process manager");
368 return ipm->template do_intra_process_publish_and_return_shared<MessageT, AllocatorT>(
388 #endif // RCLCPP__PUBLISHER_HPP_
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:234
rcl_context_t * rcl_publisher_get_context(const rcl_publisher_t *publisher)
RMW_QOS_POLICY_HISTORY_KEEP_ALL
std::shared_ptr< const MessageT > do_intra_process_publish_and_return_shared(std::unique_ptr< MessageT, MessageDeleter > msg)
Definition: publisher.hpp:357
#define RCL_RET_PUBLISHER_INVALID
bool rcl_publisher_is_valid_except_context(const rcl_publisher_t *publisher)
const rclcpp::PublisherOptionsWithAllocator< AllocatorT > options_
Copy of original options passed during construction.
Definition: publisher.hpp:379
A publisher publishes messages of any type to a topic.
Definition: publisher.hpp:53
virtual rclcpp::Context::SharedPtr get_context()=0
Return the context of the node.
void do_intra_process_publish(std::unique_ptr< MessageT, MessageDeleter > msg)
Definition: publisher.hpp:339
void default_incompatible_qos_callback(QOSOfferedIncompatibleQoSInfo &info) const
rcl_serialized_message_t & get_rcl_serialized_message()
Get the underlying rcl_serialized_t handle.
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
void do_inter_process_publish(const MessageT &msg)
Definition: publisher.hpp:282
std::shared_ptr< MessageAllocator > get_allocator() const
Definition: publisher.hpp:275
rclcpp::LoanedMessage< MessageT, AllocatorT > borrow_loaned_message()
Borrow a loaned ROS message from the middleware.
Definition: publisher.hpp:176
Definition: loaned_message.hpp:32
enum rmw_qos_durability_policy_t durability
virtual void publish(const MessageT &msg)
Definition: publisher.hpp:211
void do_serialized_publish(const rcl_serialized_message_t *serialized_msg)
Definition: publisher.hpp:306
std::shared_ptr< rcl_publisher_t > publisher_handle_
Definition: publisher_base.hpp:227
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
std::shared_ptr< MessageAllocator > message_allocator_
Definition: publisher.hpp:381
typename MessageAllocatorTraits::allocator_type MessageAllocator
Definition: publisher.hpp:57
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
rcl_ret_t rcl_publish_serialized_message(const rcl_publisher_t *publisher, const rcl_serialized_message_t *serialized_message, rmw_publisher_allocation_t *allocation)
Encapsulation of Quality of Service settings.
Definition: qos.hpp:110
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
void setup_intra_process(uint64_t intra_process_publisher_id, IntraProcessManagerSharedPtr ipm)
Implementation utility function used to setup intra process publishing after creation.
T shared_from_this(T... args)
void set_allocator_for_deleter(D *deleter, Alloc *alloc)
Definition: allocator_deleter.hpp:72
void publish(rclcpp::LoanedMessage< MessageT, AllocatorT > &&loaned_msg)
Publish an instance of a LoanedMessage.
Definition: publisher.hpp:248
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
allocator::AllocRebind< statistics_msgs::msg::MetricsMessage, std::allocator< void > > MessageAllocatorTraits
Definition: publisher.hpp:56
Definition: publisher_base.hpp:56
rcl_ret_t rcl_publish(const rcl_publisher_t *publisher, const void *ros_message, rmw_publisher_allocation_t *allocation)
Definition: qos_event.hpp:69
enum rmw_qos_history_policy_t history
void add_event_handler(const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
Definition: publisher_base.hpp:209
MessageDeleter message_deleter_
Definition: publisher.hpp:383
bool intra_process_is_enabled_
Definition: publisher_base.hpp:233
void publish(const rcl_serialized_message_t &serialized_msg)
Definition: publisher.hpp:228
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:65
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
void do_loaned_message_publish(std::unique_ptr< MessageT, std::function< void(MessageT *)>> msg)
Definition: publisher.hpp:319
virtual ~Publisher()
Definition: publisher.hpp:157
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
bool can_loan_messages() const
Check if publisher instance can loan messages.
uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:235
Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.
Definition: serialized_message.hpp:27
size_t get_subscription_count() const
Get subscription count.
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.
This class performs intra process communication between nodes.
Definition: intra_process_manager.hpp:91
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:122
rcl_ret_t rcl_publish_loaned_message(const rcl_publisher_t *publisher, void *ros_message, rmw_publisher_allocation_t *allocation)
void publish(const SerializedMessage &serialized_msg)
Definition: publisher.hpp:234
RMW_QOS_POLICY_DURABILITY_VOLATILE
size_t get_intra_process_subscription_count() const
Get intraprocess subscription count.
virtual void publish(std::unique_ptr< MessageT, MessageDeleter > msg)
Send a message to the topic for this publisher.
Definition: publisher.hpp:187
bool rcl_context_is_valid(const rcl_context_t *context)
allocator::Deleter< MessageAllocator, statistics_msgs::msg::MetricsMessage > MessageDeleter
Definition: publisher.hpp:58