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"
29 #include "rcl/publisher.h"
46 template<
typename MessageT,
typename AllocatorT>
50 template<
typename MessageT,
typename AllocatorT = std::allocator<
void>>
74 rclcpp::node_interfaces::NodeBaseInterface * node_base,
75 const
std::
string & topic,
81 *rosidl_typesupport_cpp::get_message_type_support_handle<MessageT>(),
82 options.template to_rcl_publisher_options<MessageT>(qos)),
88 if (
options_.event_callbacks.deadline_callback) {
90 options_.event_callbacks.deadline_callback,
91 RCL_PUBLISHER_OFFERED_DEADLINE_MISSED);
93 if (
options_.event_callbacks.liveliness_callback) {
95 options_.event_callbacks.liveliness_callback,
96 RCL_PUBLISHER_LIVELINESS_LOST);
98 if (
options_.event_callbacks.incompatible_qos_callback) {
100 options_.event_callbacks.incompatible_qos_callback,
101 RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);
102 }
else if (
options_.use_default_callbacks) {
109 RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);
138 "intraprocess communication is not allowed with keep all history qos policy");
142 "intraprocess communication is not allowed with a zero qos history depth value");
146 "intraprocess communication allowed only with volatile durability");
148 uint64_t intra_process_publisher_id = ipm->add_publisher(this->
shared_from_this());
150 intra_process_publisher_id,
197 bool inter_process_publish_needed =
200 if (inter_process_publish_needed) {
226 publish(
const rcl_serialized_message_t & serialized_msg)
248 if (!loaned_msg.is_valid()) {
253 throw std::runtime_error(
"storing loaned messages in intra process is not supported yet");
284 if (RCL_RET_PUBLISHER_INVALID == status) {
288 if (
nullptr != context && !rcl_context_is_valid(context)) {
294 if (RCL_RET_OK != status) {
304 throw std::runtime_error(
"storing serialized messages in intra process is not supported yet");
307 if (RCL_RET_OK != status) {
317 if (RCL_RET_PUBLISHER_INVALID == status) {
321 if (
nullptr != context && !rcl_context_is_valid(context)) {
327 if (RCL_RET_OK != status) {
338 "intra process publish called after destruction of intra process manager");
344 ipm->template do_intra_process_publish<MessageT, AllocatorT>(
356 "intra process publish called after destruction of intra process manager");
362 return ipm->template do_intra_process_publish_and_return_shared<MessageT, AllocatorT>(
382 #endif // RCLCPP__PUBLISHER_HPP_
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:224
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:351
const rclcpp::PublisherOptionsWithAllocator< AllocatorT > options_
Copy of original options passed during construction.
Definition: publisher.hpp:373
A publisher publishes messages of any type to a topic.
Definition: publisher.hpp:51
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:333
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:280
std::shared_ptr< MessageAllocator > get_allocator() const
Definition: publisher.hpp:273
rclcpp::LoanedMessage< MessageT, AllocatorT > borrow_loaned_message()
Borrow a loaned ROS message from the middleware.
Definition: publisher.hpp:174
Definition: loaned_message.hpp:32
void do_loaned_message_publish(MessageT *msg)
Definition: publisher.hpp:313
enum rmw_qos_durability_policy_t durability
virtual void publish(const MessageT &msg)
Definition: publisher.hpp:209
void do_serialized_publish(const rcl_serialized_message_t *serialized_msg)
Definition: publisher.hpp:300
std::shared_ptr< rcl_publisher_t > publisher_handle_
Definition: publisher_base.hpp:217
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
std::shared_ptr< MessageAllocator > message_allocator_
Definition: publisher.hpp:375
typename MessageAllocatorTraits::allocator_type MessageAllocator
Definition: publisher.hpp:55
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
Encapsulation of Quality of Service settings.
Definition: qos.hpp:59
#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:246
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:54
Definition: publisher_base.hpp:55
Definition: qos_event.hpp:64
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:199
MessageDeleter message_deleter_
Definition: publisher.hpp:377
bool intra_process_is_enabled_
Definition: publisher_base.hpp:223
void publish(const rcl_serialized_message_t &serialized_msg)
Definition: publisher.hpp:226
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:57
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
virtual ~Publisher()
Definition: publisher.hpp:155
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:225
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:120
void publish(const SerializedMessage &serialized_msg)
Definition: publisher.hpp:232
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:185
allocator::Deleter< MessageAllocator, statistics_msgs::msg::MetricsMessage > MessageDeleter
Definition: publisher.hpp:56