rclcpp  master
C++ ROS Client Library API
Public Types | Public Member Functions | Friends | List of all members
rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT > Class Template Reference

Subscription implementation, templated on the type of message this subscription receives. More...

#include <subscription.hpp>

Inheritance diagram for rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >:
Collaboration graph
[legend]

Public Types

using MessageAllocatorTraits = allocator::AllocRebind< CallbackMessageT, AllocatorT >
 
using MessageAllocator = typename MessageAllocatorTraits::allocator_type
 
using MessageDeleter = allocator::Deleter< MessageAllocator, CallbackMessageT >
 
using ConstMessageSharedPtr = std::shared_ptr< const CallbackMessageT >
 
using MessageUniquePtr = std::unique_ptr< CallbackMessageT, MessageDeleter >
 
- Public Types inherited from rclcpp::SubscriptionBase
using IntraProcessManagerWeakPtr = std::weak_ptr< rclcpp::experimental::IntraProcessManager >
 

Public Member Functions

 Subscription (rclcpp::node_interfaces::NodeBaseInterface *node_base, const rosidl_message_type_support_t &type_support_handle, const std::string &topic_name, const rclcpp::QoS &qos, AnySubscriptionCallback< CallbackMessageT, AllocatorT > callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options, typename MessageMemoryStrategyT::SharedPtr message_memory_strategy)
 Default constructor. More...
 
void post_init_setup (rclcpp::node_interfaces::NodeBaseInterface *node_base, const rclcpp::QoS &qos, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options)
 Called after construction to continue setup that requires shared_from_this(). More...
 
void set_message_memory_strategy (typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >::SharedPtr message_memory_strategy)
 Support dynamically setting the message memory strategy. More...
 
std::shared_ptr< void > create_message () override
 Borrow a new message. More...
 
std::shared_ptr< rcl_serialized_message_tcreate_serialized_message () override
 Borrow a new serialized message. More...
 
void handle_message (std::shared_ptr< void > &message, const rmw_message_info_t &message_info) override
 Check if we need to handle the message, and execute the callback if we do. More...
 
void handle_loaned_message (void *loaned_message, const rmw_message_info_t &message_info) override
 
void return_message (std::shared_ptr< void > &message) override
 Return the borrowed message. More...
 
void return_serialized_message (std::shared_ptr< rcl_serialized_message_t > &message) override
 Return the message borrowed in create_serialized_message. More...
 
bool use_take_shared_method () const
 
- 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)
 Default constructor. More...
 
virtual ~SubscriptionBase ()
 Default 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 ()
 
const std::shared_ptr< 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...
 
const rosidl_message_type_support_t & get_message_type_support_handle () const
 
bool is_serialized () const
 
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, or nullptr if intra-process is not setup. 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)
 

Friends

class rclcpp::node_interfaces::NodeTopicsInterface
 

Additional Inherited Members

- 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)
 
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

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
class rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >

Subscription implementation, templated on the type of message this subscription receives.

Member Typedef Documentation

◆ MessageAllocatorTraits

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
using rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::MessageAllocatorTraits = allocator::AllocRebind<CallbackMessageT, AllocatorT>

◆ MessageAllocator

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
using rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::MessageAllocator = typename MessageAllocatorTraits::allocator_type

◆ MessageDeleter

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
using rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::MessageDeleter = allocator::Deleter<MessageAllocator, CallbackMessageT>

◆ ConstMessageSharedPtr

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
using rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::ConstMessageSharedPtr = std::shared_ptr<const CallbackMessageT>

◆ MessageUniquePtr

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
using rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::MessageUniquePtr = std::unique_ptr<CallbackMessageT, MessageDeleter>

Constructor & Destructor Documentation

◆ Subscription()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::Subscription ( rclcpp::node_interfaces::NodeBaseInterface node_base,
const rosidl_message_type_support_t &  type_support_handle,
const std::string topic_name,
const rclcpp::QoS qos,
AnySubscriptionCallback< CallbackMessageT, AllocatorT >  callback,
const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &  options,
typename MessageMemoryStrategyT::SharedPtr  message_memory_strategy 
)
inline

Default constructor.

The constructor for a subscription is almost never called directly. Instead, subscriptions should be instantiated through the function rclcpp::create_subscription().

Parameters
[in]node_baseNodeBaseInterface pointer that is used in part of the setup.
[in]type_support_handlerosidl type support struct, for the Message type of the topic.
[in]topic_nameName of the topic to subscribe to.
[in]callbackUser defined callback to call when a message is received.
[in]optionsoptions for the subscription.
[in]message_memory_strategyThe memory strategy to be used for managing message memory.

Member Function Documentation

◆ post_init_setup()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
void rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::post_init_setup ( rclcpp::node_interfaces::NodeBaseInterface node_base,
const rclcpp::QoS qos,
const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &  options 
)
inline

Called after construction to continue setup that requires shared_from_this().

◆ set_message_memory_strategy()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
void rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::set_message_memory_strategy ( typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >::SharedPtr  message_memory_strategy)
inline

Support dynamically setting the message memory strategy.

Behavior may be undefined if called while the subscription could be executing.

Parameters
[in]message_memory_strategyShared pointer to the memory strategy to set.

◆ create_message()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
std::shared_ptr<void> rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::create_message ( )
inlineoverridevirtual

Borrow a new message.

Returns
Shared pointer to the fresh message.

Implements rclcpp::SubscriptionBase.

◆ create_serialized_message()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
std::shared_ptr<rcl_serialized_message_t> rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::create_serialized_message ( )
inlineoverridevirtual

Borrow a new serialized message.

Returns
Shared pointer to a rcl_message_serialized_t.

Implements rclcpp::SubscriptionBase.

◆ handle_message()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
void rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::handle_message ( std::shared_ptr< void > &  message,
const rmw_message_info_t message_info 
)
inlineoverridevirtual

Check if we need to handle the message, and execute the callback if we do.

Parameters
[in]messageShared pointer to the message to handle.
[in]message_infoMetadata associated with this message.

Implements rclcpp::SubscriptionBase.

◆ handle_loaned_message()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
void rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::handle_loaned_message ( void *  loaned_message,
const rmw_message_info_t message_info 
)
inlineoverridevirtual

◆ return_message()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
void rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::return_message ( std::shared_ptr< void > &  message)
inlineoverridevirtual

Return the borrowed message.

Parameters
messagemessage to be returned

Implements rclcpp::SubscriptionBase.

◆ return_serialized_message()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
void rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::return_serialized_message ( std::shared_ptr< rcl_serialized_message_t > &  message)
inlineoverridevirtual

Return the message borrowed in create_serialized_message.

Parameters
[in]messageShared pointer to the returned message.

Implements rclcpp::SubscriptionBase.

◆ use_take_shared_method()

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
bool rclcpp::Subscription< CallbackMessageT, AllocatorT, MessageMemoryStrategyT >::use_take_shared_method ( ) const
inline

Friends And Related Function Documentation

◆ rclcpp::node_interfaces::NodeTopicsInterface

template<typename CallbackMessageT, typename AllocatorT = std::allocator<void>, typename MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, AllocatorT >>
friend class rclcpp::node_interfaces::NodeTopicsInterface
friend

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