rclcpp  master
C++ ROS Client Library API
Public Member Functions | List of all members
rclcpp::GenericSubscription Class Reference

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

#include <generic_subscription.hpp>

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

Public Member Functions

template<typename AllocatorT = std::allocator<void>>
 GenericSubscription (rclcpp::node_interfaces::NodeBaseInterface *node_base, const std::shared_ptr< rcpputils::SharedLibrary > ts_lib, const std::string &topic_name, const std::string &topic_type, const rclcpp::QoS &qos, std::function< void(std::shared_ptr< rclcpp::SerializedMessage >)> callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options)
 Constructor. More...
 
virtual ~GenericSubscription ()=default
 
std::shared_ptr< void > create_message () override
 Borrow a new message. More...
 
std::shared_ptr< rclcpp::SerializedMessagecreate_serialized_message () override
 Borrow a new serialized message. More...
 
void handle_message (std::shared_ptr< void > &message, const rclcpp::MessageInfo &message_info) override
 Cast the message to a rclcpp::SerializedMessage and call the callback. More...
 
void handle_loaned_message (void *loaned_message, const rclcpp::MessageInfo &message_info) override
 This function is currently not implemented. More...
 
void return_message (std::shared_ptr< void > &message) override
 Return the message borrowed in create_message. More...
 
void return_serialized_message (std::shared_ptr< rclcpp::SerializedMessage > &message) override
 Return the message borrowed in create_serialized_message. More...
 
- Public Member Functions inherited from rclcpp::SubscriptionBase
 SubscriptionBase (rclcpp::node_interfaces::NodeBaseInterface *node_base, const rosidl_message_type_support_t &type_support_handle, const std::string &topic_name, const rcl_subscription_options_t &subscription_options, bool is_serialized=false)
 Constructor. More...
 
virtual ~SubscriptionBase ()
 Destructor. More...
 
const char * get_topic_name () const
 Get the topic that this subscription is subscribed on. More...
 
std::shared_ptr< rcl_subscription_tget_subscription_handle ()
 
std::shared_ptr< const rcl_subscription_tget_subscription_handle () const
 
const std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > & get_event_handlers () const
 Get all the QoS event handlers associated with this subscription. More...
 
rclcpp::QoS get_actual_qos () const
 Get the actual QoS settings, after the defaults have been determined. More...
 
bool take_type_erased (void *message_out, rclcpp::MessageInfo &message_info_out)
 Take the next inter-process message from the subscription as a type erased pointer. More...
 
bool take_serialized (rclcpp::SerializedMessage &message_out, rclcpp::MessageInfo &message_info_out)
 Take the next inter-process message, in its serialized form, from the subscription. More...
 
const rosidl_message_type_support_t & get_message_type_support_handle () const
 
bool is_serialized () const
 Return if the subscription is serialized. More...
 
size_t get_publisher_count () const
 Get matching publisher count. More...
 
bool can_loan_messages () const
 Check if subscription instance can loan messages. More...
 
void setup_intra_process (uint64_t intra_process_subscription_id, IntraProcessManagerWeakPtr weak_ipm)
 Implemenation detail. More...
 
rclcpp::Waitable::SharedPtr get_intra_process_waitable () const
 Return the waitable for intra-process. More...
 
bool exchange_in_use_by_wait_set_state (void *pointer_to_subscription_part, bool in_use_state)
 Exchange state of whether or not a part of the subscription is used by a wait set. More...
 
std::vector< rclcpp::NetworkFlowEndpointget_network_flow_endpoints () const
 Get network flow endpoints. More...
 
- Public Member Functions inherited from std::enable_shared_from_this< SubscriptionBase >
enable_shared_from_this (T... args)
 
operator= (T... args)
 
shared_from_this (T... args)
 
~enable_shared_from_this (T... args)
 

Additional Inherited Members

- Public Types inherited from rclcpp::SubscriptionBase
using IntraProcessManagerWeakPtr = std::weak_ptr< rclcpp::experimental::IntraProcessManager >
 
- Protected Member Functions inherited from rclcpp::SubscriptionBase
template<typename EventCallbackT >
void add_event_handler (const EventCallbackT &callback, const rcl_subscription_event_type_t event_type)
 
void default_incompatible_qos_callback (QOSRequestedIncompatibleQoSInfo &info) const
 
bool matches_any_intra_process_publishers (const rmw_gid_t *sender_gid) const
 
- Protected Attributes inherited from rclcpp::SubscriptionBase
rclcpp::node_interfaces::NodeBaseInterface *const node_base_
 
std::shared_ptr< rcl_node_tnode_handle_
 
std::shared_ptr< rcl_subscription_tsubscription_handle_
 
std::shared_ptr< rcl_subscription_tintra_process_subscription_handle_
 
std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > event_handlers_
 
bool use_intra_process_
 
IntraProcessManagerWeakPtr weak_ipm_
 
uint64_t intra_process_subscription_id_
 

Detailed Description

Subscription 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.

Constructor & Destructor Documentation

◆ GenericSubscription()

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

Constructor.

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

See also
rclcpp::Node::create_generic_subscription() or rclcpp::create_generic_subscription() 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
callbackCallback for new messages of serialized form
optionsSubscription options. Not all subscription options are currently respected, the only relevant options for this subscription are event_callbacks, use_default_callbacks, ignore_local_publications, and callback_group.

◆ ~GenericSubscription()

virtual rclcpp::GenericSubscription::~GenericSubscription ( )
virtualdefault

Member Function Documentation

◆ create_message()

std::shared_ptr<void> rclcpp::GenericSubscription::create_message ( )
overridevirtual

Borrow a new message.

Returns
Shared pointer to the fresh message.

Implements rclcpp::SubscriptionBase.

◆ create_serialized_message()

std::shared_ptr<rclcpp::SerializedMessage> rclcpp::GenericSubscription::create_serialized_message ( )
overridevirtual

Borrow a new serialized message.

Returns
Shared pointer to a rcl_message_serialized_t.

Implements rclcpp::SubscriptionBase.

◆ handle_message()

void rclcpp::GenericSubscription::handle_message ( std::shared_ptr< void > &  message,
const rclcpp::MessageInfo message_info 
)
overridevirtual

Cast the message to a rclcpp::SerializedMessage and call the callback.

Implements rclcpp::SubscriptionBase.

◆ handle_loaned_message()

void rclcpp::GenericSubscription::handle_loaned_message ( void *  loaned_message,
const rclcpp::MessageInfo message_info 
)
overridevirtual

This function is currently not implemented.

Implements rclcpp::SubscriptionBase.

◆ return_message()

void rclcpp::GenericSubscription::return_message ( std::shared_ptr< void > &  message)
overridevirtual

Return the message borrowed in create_message.

Parameters
[in]messageShared pointer to the returned message.

Implements rclcpp::SubscriptionBase.

◆ return_serialized_message()

void rclcpp::GenericSubscription::return_serialized_message ( std::shared_ptr< rclcpp::SerializedMessage > &  message)
overridevirtual

Return the message borrowed in create_serialized_message.

Parameters
[in]messageShared pointer to the returned message.

Implements rclcpp::SubscriptionBase.


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