ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
Public Member Functions | List of all members
rclcpp::GenericPublisher Class Reference

Publisher for serialized messages whose type is not known at compile time. More...

#include <rclcpp/generic_publisher.hpp>

Inheritance diagram for rclcpp::GenericPublisher:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::GenericPublisher:
Collaboration graph
[legend]

Public Member Functions

template<typename AllocatorT = std::allocator<void>>
 GenericPublisher (rclcpp::node_interfaces::NodeBaseInterface *node_base, std::shared_ptr< rcpputils::SharedLibrary > ts_lib, const std::string &topic_name, const std::string &topic_type, const rclcpp::QoS &qos, const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &options)
 Constructor. More...
 
RCLCPP_PUBLIC void publish (const rclcpp::SerializedMessage &message)
 Publish a rclcpp::SerializedMessage.
 
RCLCPP_PUBLIC void publish_as_loaned_msg (const rclcpp::SerializedMessage &message)
 
- Public Member Functions inherited from rclcpp::PublisherBase
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. More...
 
RCLCPP_PUBLIC void bind_event_callbacks (const PublisherEventCallbacks &event_callbacks, bool use_default_callbacks)
 Add event handlers for passed in event_callbacks.
 
RCLCPP_PUBLIC const char * get_topic_name () const
 Get the topic that this publisher publishes on. More...
 
RCLCPP_PUBLIC size_t get_queue_size () const
 Get the queue size for this publisher. More...
 
RCLCPP_PUBLIC const rmw_gid_t & get_gid () const
 Get the global identifier for this publisher (used in rmw and by DDS). More...
 
RCLCPP_PUBLIC std::shared_ptr< rcl_publisher_tget_publisher_handle ()
 Get the rcl publisher handle. More...
 
RCLCPP_PUBLIC std::shared_ptr< const rcl_publisher_tget_publisher_handle () const
 Get the rcl publisher handle. More...
 
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. More...
 
RCLCPP_PUBLIC size_t get_subscription_count () const
 Get subscription count. More...
 
RCLCPP_PUBLIC size_t get_intra_process_subscription_count () const
 Get intraprocess subscription count. More...
 
RCLCPP_PUBLIC bool is_durability_transient_local () const
 Get if durability is transient local. More...
 
RCLCPP_PUBLIC RCUTILS_WARN_UNUSED bool assert_liveliness () const
 Manually assert that this Publisher is alive (for RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC). More...
 
RCLCPP_PUBLIC rclcpp::QoS get_actual_qos () const
 Get the actual QoS settings, after the defaults have been determined. More...
 
RCLCPP_PUBLIC bool can_loan_messages () const
 Check if publisher instance can loan messages. More...
 
RCLCPP_PUBLIC bool operator== (const rmw_gid_t &gid) const
 Compare this publisher to a gid. More...
 
RCLCPP_PUBLIC bool operator== (const rmw_gid_t *gid) const
 Compare this publisher to a pointer gid. More...
 
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 std::vector< rclcpp::NetworkFlowEndpointget_network_flow_endpoints () const
 Get network flow endpoints. More...
 
RCLCPP_PUBLIC size_t lowest_available_ipm_capacity () const
 Return the lowest available capacity for all subscription buffers. More...
 
template<typename DurationRepT = int64_t, typename DurationT = std::milli>
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. More...
 
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. More...
 
void clear_on_new_qos_event_callback (rcl_publisher_event_type_t event_type)
 Unset the callback registered for new qos events, if any.
 

Additional Inherited Members

- Public Types inherited from rclcpp::PublisherBase
using IntraProcessManagerSharedPtr = std::shared_ptr< rclcpp::experimental::IntraProcessManager >
 
- Protected Types inherited from rclcpp::PublisherBase
using IntraProcessManagerWeakPtr = std::weak_ptr< rclcpp::experimental::IntraProcessManager >
 
- Protected Member Functions inherited from rclcpp::PublisherBase
template<typename EventCallbackT >
void add_event_handler (const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
 
RCLCPP_PUBLIC void default_incompatible_qos_callback (QOSOfferedIncompatibleQoSInfo &info) const
 
RCLCPP_PUBLIC void default_incompatible_type_callback (IncompatibleTypeInfo &info) const
 
- Protected Attributes inherited from rclcpp::PublisherBase
std::shared_ptr< rcl_node_trcl_node_handle_
 
std::shared_ptr< rcl_publisher_tpublisher_handle_
 
std::unordered_map< rcl_publisher_event_type_t, std::shared_ptr< rclcpp::EventHandlerBase > > event_handlers_
 
bool intra_process_is_enabled_
 
IntraProcessManagerWeakPtr weak_ipm_
 
uint64_t intra_process_publisher_id_
 
rmw_gid_t rmw_gid_
 
const rosidl_message_type_support_t type_support_
 
const PublisherEventCallbacks event_callbacks_
 

Detailed Description

Publisher for serialized messages whose type is not known at compile time.

Since the type is not known at compile time, this is not a template, and the dynamic library containing type support information has to be identified and loaded based on the type name.

It does not support intra-process handling.

Definition at line 46 of file generic_publisher.hpp.

Constructor & Destructor Documentation

◆ GenericPublisher()

template<typename AllocatorT = std::allocator<void>>
rclcpp::GenericPublisher::GenericPublisher ( rclcpp::node_interfaces::NodeBaseInterface node_base,
std::shared_ptr< rcpputils::SharedLibrary >  ts_lib,
const std::string &  topic_name,
const std::string &  topic_type,
const rclcpp::QoS qos,
const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &  options 
)
inline

Constructor.

In order to properly publish to a topic, this publisher needs to be added to the node_topic_interface of the node passed into this constructor.

See also
rclcpp::Node::create_generic_publisher() or rclcpp::create_generic_publisher() for creating an instance of this class and adding it to the node_topic_interface.
Parameters
node_basePointer to parent node's NodeBaseInterface
ts_libType support library, needs to correspond to topic_type
topic_nameTopic name
topic_typeTopic type
qosQoS settings
optionsPublisher options. Not all publisher options are currently respected, the only relevant options for this publisher are event_callbacks, use_default_callbacks, and callback_group.

Definition at line 70 of file generic_publisher.hpp.

Member Function Documentation

◆ publish_as_loaned_msg()

void rclcpp::GenericPublisher::publish_as_loaned_msg ( const rclcpp::SerializedMessage message)

Publish a rclcpp::SerializedMessage via loaned message after de-serialization.

Parameters
messagea serialized message
Exceptions
anythingrclcpp::exceptions::throw_from_rcl_error can show

Definition at line 38 of file generic_publisher.cpp.

References rclcpp::SerializedMessage::get_rcl_serialized_message().

Here is the call graph for this function:

The documentation for this class was generated from the following files: