15 #ifndef RCLCPP__PUBLISHER_BASE_HPP_
16 #define RCLCPP__PUBLISHER_BASE_HPP_
18 #include <rmw/error_handling.h>
27 #include <unordered_map>
33 #include "rclcpp/macros.hpp"
34 #include "rclcpp/network_flow_endpoint.hpp"
35 #include "rclcpp/qos.hpp"
36 #include "rclcpp/event_handler.hpp"
37 #include "rclcpp/type_support_decl.hpp"
38 #include "rclcpp/visibility_control.hpp"
39 #include "rcpputils/time.hpp"
45 namespace node_interfaces
47 class NodeBaseInterface;
48 class NodeTopicsInterface;
51 namespace experimental
57 class IntraProcessManager;
60 class PublisherBase :
public std::enable_shared_from_this<PublisherBase>
62 friend ::rclcpp::node_interfaces::NodeTopicsInterface;
79 const std::string & topic,
80 const rosidl_message_type_support_t & type_support,
83 bool use_default_callbacks);
114 std::shared_ptr<rcl_publisher_t>
120 std::shared_ptr<const rcl_publisher_t>
127 std::unordered_map<rcl_publisher_event_type_t, std::shared_ptr<rclcpp::EventHandlerBase>> &
205 using IntraProcessManagerSharedPtr =
206 std::shared_ptr<rclcpp::experimental::IntraProcessManager>;
212 uint64_t intra_process_publisher_id,
213 IntraProcessManagerSharedPtr ipm);
221 std::vector<rclcpp::NetworkFlowEndpoint>
257 template<
typename DurationRepT =
int64_t,
typename DurationT = std::milli>
260 std::chrono::duration<DurationRepT, DurationT> timeout =
261 std::chrono::duration<DurationRepT, DurationT>(-1))
const
271 rclcpp::exceptions::throw_from_rcl_error(ret);
303 std::function<
void(
size_t)> callback,
306 if (event_handlers_.count(event_type) == 0) {
309 "Calling set_on_new_qos_event_callback for non registered publisher event_type");
314 throw std::invalid_argument(
315 "The callback passed to set_on_new_qos_event_callback "
322 std::function<void(
size_t,
int)> new_callback = std::bind(callback, std::placeholders::_1);
323 event_handlers_[event_type]->set_on_ready_callback(new_callback);
330 if (event_handlers_.count(event_type) == 0) {
333 "Calling clear_on_new_qos_event_callback for non registered event_type");
337 event_handlers_[event_type]->clear_on_ready_callback();
341 template<
typename EventCallbackT>
344 const EventCallbackT & callback,
347 auto handler = std::make_shared<
EventHandler<EventCallbackT,
348 std::shared_ptr<rcl_publisher_t>>>(
353 event_handlers_.insert(std::make_pair(event_type, handler));
357 void default_incompatible_qos_callback(QOSOfferedIncompatibleQoSInfo & info)
const;
360 void default_incompatible_type_callback(IncompatibleTypeInfo & info)
const;
362 std::shared_ptr<rcl_node_t> rcl_node_handle_;
364 std::shared_ptr<rcl_publisher_t> publisher_handle_;
367 std::shared_ptr<rclcpp::EventHandlerBase>> event_handlers_;
369 using IntraProcessManagerWeakPtr =
370 std::weak_ptr<rclcpp::experimental::IntraProcessManager>;
371 bool intra_process_is_enabled_;
372 IntraProcessManagerWeakPtr weak_ipm_;
373 uint64_t intra_process_publisher_id_;
377 const rosidl_message_type_support_t type_support_;
379 const PublisherEventCallbacks event_callbacks_;
RCLCPP_PUBLIC const rmw_gid_t & get_gid() const
Get the global identifier for this publisher (used in rmw and by DDS).
RCLCPP_PUBLIC std::shared_ptr< rcl_publisher_t > get_publisher_handle()
Get the rcl publisher handle.
RCLCPP_PUBLIC size_t get_intra_process_subscription_count() const
Get intraprocess subscription count.
RCLCPP_PUBLIC PublisherBase(rclcpp::node_interfaces::NodeBaseInterface *node_base, const std::string &topic, const rosidl_message_type_support_t &type_support, const rcl_publisher_options_t &publisher_options, const PublisherEventCallbacks &event_callbacks, bool use_default_callbacks)
Default constructor.
RCLCPP_PUBLIC void bind_event_callbacks(const PublisherEventCallbacks &event_callbacks, bool use_default_callbacks)
Add event handlers for passed in event_callbacks.
RCLCPP_PUBLIC rclcpp::QoS get_actual_qos() const
Get the actual QoS settings, after the defaults have been determined.
RCLCPP_PUBLIC const char * get_topic_name() const
Get the topic that this publisher publishes on.
RCLCPP_PUBLIC bool operator==(const rmw_gid_t &gid) const
Compare this publisher to a gid.
RCLCPP_PUBLIC void setup_intra_process(uint64_t intra_process_publisher_id, IntraProcessManagerSharedPtr ipm)
Implementation utility function used to setup intra process publishing after creation.
RCLCPP_PUBLIC size_t get_queue_size() const
Get the queue size for this publisher.
void clear_on_new_qos_event_callback(rcl_publisher_event_type_t event_type)
Unset the callback registered for new qos events, if any.
RCLCPP_PUBLIC bool can_loan_messages() const
Check if publisher instance can loan messages.
RCLCPP_PUBLIC bool is_durability_transient_local() const
Get if durability is transient local.
RCLCPP_PUBLIC size_t get_subscription_count() const
Get subscription count.
RCLCPP_PUBLIC std::vector< rclcpp::NetworkFlowEndpoint > get_network_flow_endpoints() const
Get network flow endpoints.
bool wait_for_all_acked(std::chrono::duration< DurationRepT, DurationT > timeout=std::chrono::duration< DurationRepT, DurationT >(-1)) const
Wait until all published messages are acknowledged or until the specified timeout elapses.
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED bool assert_liveliness() const
Manually assert that this Publisher is alive (for RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC).
RCLCPP_PUBLIC const std::unordered_map< rcl_publisher_event_type_t, std::shared_ptr< rclcpp::EventHandlerBase > > & get_event_handlers() const
Get all the QoS event handlers associated with this publisher.
RCLCPP_PUBLIC size_t lowest_available_ipm_capacity() const
Return the lowest available capacity for all subscription buffers.
void set_on_new_qos_event_callback(std::function< void(size_t)> callback, rcl_publisher_event_type_t event_type)
Set a callback to be called when each new qos event instance occurs.
Encapsulation of Quality of Service settings.
Pure virtual interface class for the NodeBase part of the Node API.
enum rcl_publisher_event_type_e rcl_publisher_event_type_t
Enumeration of all of the publisher events that may fire.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_publisher_event_init(rcl_event_t *event, const rcl_publisher_t *publisher, const rcl_publisher_event_type_t event_type)
Initialize an rcl_event_t with a publisher.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC Logger get_logger(const std::string &name)
Return a named logger.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_publisher_wait_for_all_acked(const rcl_publisher_t *publisher, rcl_duration_value_t timeout)
Wait until all published message data is acknowledged or until the specified timeout elapses.
Options available for a rcl publisher.
Contains callbacks for various types of events a Publisher can receive from the middleware.
rcutils_duration_value_t rcl_duration_value_t
A duration of time, measured in nanoseconds.
#define RCL_RET_OK
Success return code.
#define RCL_RET_TIMEOUT
Timeout occurred return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.