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

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

#include <subscription.hpp>

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

Public Types

using MessageAllocTraits = allocator::AllocRebind< CallbackMessageT, Alloc >
 
using MessageAlloc = typename MessageAllocTraits::allocator_type
 
using MessageDeleter = allocator::Deleter< MessageAlloc, CallbackMessageT >
 
using MessageUniquePtr = std::unique_ptr< CallbackMessageT, MessageDeleter >
 
using GetMessageCallbackType = std::function< void(uint64_t, uint64_t, uint64_t, MessageUniquePtr &)>
 
using MatchesAnyPublishersCallbackType = std::function< bool(const rmw_gid_t *)>
 

Public Member Functions

 Subscription (std::shared_ptr< rcl_node_t > node_handle, const rosidl_message_type_support_t &type_support_handle, const std::string &topic_name, const rcl_subscription_options_t &subscription_options, AnySubscriptionCallback< CallbackMessageT, Alloc > callback, typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, Alloc >::SharedPtr memory_strategy=message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, Alloc >::create_default())
 Default constructor. More...
 
void set_message_memory_strategy (typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, Alloc >::SharedPtr message_memory_strategy)
 Support dynamically setting the message memory strategy. More...
 
std::shared_ptr< void > create_message ()
 Borrow a new message. More...
 
std::shared_ptr< rcl_serialized_message_tcreate_serialized_message ()
 Borrow a new serialized message. More...
 
void handle_message (std::shared_ptr< void > &message, const rmw_message_info_t &message_info)
 Check if we need to handle the message, and execute the callback if we do. More...
 
void return_message (std::shared_ptr< void > &message)
 Return the loaned message. More...
 
void return_serialized_message (std::shared_ptr< rcl_serialized_message_t > &message)
 Return the message borrowed in create_serialized_message. More...
 
void handle_intra_process_message (rcl_interfaces::msg::IntraProcessMessage &ipm, const rmw_message_info_t &message_info)
 
void setup_intra_process (uint64_t intra_process_subscription_id, GetMessageCallbackType get_message_callback, MatchesAnyPublishersCallbackType matches_any_publisher_callback, const rcl_subscription_options_t &intra_process_options)
 Implemenation detail. More...
 
const std::shared_ptr< rcl_subscription_tget_intra_process_subscription_handle () const
 Implemenation detail. More...
 
- Public Member Functions inherited from rclcpp::SubscriptionBase
 SubscriptionBase (std::shared_ptr< rcl_node_t > node_handle, 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 rosidl_message_type_support_t & get_message_type_support_handle () const
 
bool is_serialized () const
 

Friends

class rclcpp::node_interfaces::NodeTopicsInterface
 

Additional Inherited Members

- Protected Attributes inherited from rclcpp::SubscriptionBase
std::shared_ptr< rcl_subscription_tintra_process_subscription_handle_
 
std::shared_ptr< rcl_subscription_tsubscription_handle_
 
std::shared_ptr< rcl_node_tnode_handle_
 

Detailed Description

template<typename CallbackMessageT, typename Alloc = std::allocator<void>>
class rclcpp::Subscription< CallbackMessageT, Alloc >

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

Member Typedef Documentation

◆ MessageAllocTraits

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
using rclcpp::Subscription< CallbackMessageT, Alloc >::MessageAllocTraits = allocator::AllocRebind<CallbackMessageT, Alloc>

◆ MessageAlloc

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
using rclcpp::Subscription< CallbackMessageT, Alloc >::MessageAlloc = typename MessageAllocTraits::allocator_type

◆ MessageDeleter

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
using rclcpp::Subscription< CallbackMessageT, Alloc >::MessageDeleter = allocator::Deleter<MessageAlloc, CallbackMessageT>

◆ MessageUniquePtr

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
using rclcpp::Subscription< CallbackMessageT, Alloc >::MessageUniquePtr = std::unique_ptr<CallbackMessageT, MessageDeleter>

◆ GetMessageCallbackType

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
using rclcpp::Subscription< CallbackMessageT, Alloc >::GetMessageCallbackType = std::function<void (uint64_t, uint64_t, uint64_t, MessageUniquePtr &)>

◆ MatchesAnyPublishersCallbackType

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
using rclcpp::Subscription< CallbackMessageT, Alloc >::MatchesAnyPublishersCallbackType = std::function<bool (const rmw_gid_t *)>

Constructor & Destructor Documentation

◆ Subscription()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
rclcpp::Subscription< CallbackMessageT, Alloc >::Subscription ( std::shared_ptr< rcl_node_t node_handle,
const rosidl_message_type_support_t &  type_support_handle,
const std::string topic_name,
const rcl_subscription_options_t subscription_options,
AnySubscriptionCallback< CallbackMessageT, Alloc >  callback,
typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, Alloc >::SharedPtr  memory_strategy = message_memory_strategy::MessageMemoryStrategy<CallbackMessageT, Alloc>::create_default() 
)
inline

Default constructor.

The constructor for a subscription is almost never called directly. Instead, subscriptions should be instantiated through Node::create_subscription.

Parameters
[in]node_handlercl representation of the node that owns this subscription.
[in]type_support_handlerosidl type support struct, for the Message type of the topic.
[in]topic_nameName of the topic to subscribe to.
[in]subscription_optionsoptions for the subscription.
[in]callbackUser defined callback to call when a message is received.
[in]memory_strategyThe memory strategy to be used for managing message memory.

Member Function Documentation

◆ set_message_memory_strategy()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
void rclcpp::Subscription< CallbackMessageT, Alloc >::set_message_memory_strategy ( typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, Alloc >::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 Alloc = std::allocator<void>>
std::shared_ptr<void> rclcpp::Subscription< CallbackMessageT, Alloc >::create_message ( )
inlinevirtual

Borrow a new message.

Returns
Shared pointer to the fresh message.

Implements rclcpp::SubscriptionBase.

◆ create_serialized_message()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
std::shared_ptr<rcl_serialized_message_t> rclcpp::Subscription< CallbackMessageT, Alloc >::create_serialized_message ( )
inlinevirtual

Borrow a new serialized message.

Returns
Shared pointer to a rcl_message_serialized_t.

Implements rclcpp::SubscriptionBase.

◆ handle_message()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
void rclcpp::Subscription< CallbackMessageT, Alloc >::handle_message ( std::shared_ptr< void > &  message,
const rmw_message_info_t message_info 
)
inlinevirtual

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.

◆ return_message()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
void rclcpp::Subscription< CallbackMessageT, Alloc >::return_message ( std::shared_ptr< void > &  message)
inlinevirtual

Return the loaned message.

Parameters
messagemessage to be returned

Implements rclcpp::SubscriptionBase.

◆ return_serialized_message()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
void rclcpp::Subscription< CallbackMessageT, Alloc >::return_serialized_message ( std::shared_ptr< rcl_serialized_message_t > &  message)
inlinevirtual

Return the message borrowed in create_serialized_message.

Parameters
[in]messageShared pointer to the returned message.

Implements rclcpp::SubscriptionBase.

◆ handle_intra_process_message()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
void rclcpp::Subscription< CallbackMessageT, Alloc >::handle_intra_process_message ( rcl_interfaces::msg::IntraProcessMessage &  ipm,
const rmw_message_info_t message_info 
)
inlinevirtual

◆ setup_intra_process()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
void rclcpp::Subscription< CallbackMessageT, Alloc >::setup_intra_process ( uint64_t  intra_process_subscription_id,
GetMessageCallbackType  get_message_callback,
MatchesAnyPublishersCallbackType  matches_any_publisher_callback,
const rcl_subscription_options_t intra_process_options 
)
inline

Implemenation detail.

◆ get_intra_process_subscription_handle()

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
const std::shared_ptr<rcl_subscription_t> rclcpp::Subscription< CallbackMessageT, Alloc >::get_intra_process_subscription_handle ( ) const
inlinevirtual

Implemenation detail.

Reimplemented from rclcpp::SubscriptionBase.

Friends And Related Function Documentation

◆ rclcpp::node_interfaces::NodeTopicsInterface

template<typename CallbackMessageT , typename Alloc = std::allocator<void>>
friend class rclcpp::node_interfaces::NodeTopicsInterface
friend

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