rclcpp  master
C++ ROS Client Library API
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
rclcpp::CallbackGroup Class Reference

#include <callback_group.hpp>

Collaboration diagram for rclcpp::CallbackGroup:
Collaboration graph
[legend]

Public Member Functions

 CallbackGroup (CallbackGroupType group_type, bool automatically_add_to_executor_with_node=true)
 Constructor for CallbackGroup. More...
 
template<typename Function >
rclcpp::SubscriptionBase::SharedPtr find_subscription_ptrs_if (Function func) const
 
template<typename Function >
rclcpp::TimerBase::SharedPtr find_timer_ptrs_if (Function func) const
 
template<typename Function >
rclcpp::ServiceBase::SharedPtr find_service_ptrs_if (Function func) const
 
template<typename Function >
rclcpp::ClientBase::SharedPtr find_client_ptrs_if (Function func) const
 
template<typename Function >
rclcpp::Waitable::SharedPtr find_waitable_ptrs_if (Function func) const
 
std::atomic_bool & can_be_taken_from ()
 
const CallbackGroupTypetype () const
 
std::atomic_bool & get_associated_with_executor_atomic ()
 Return a reference to the 'associated with executor' atomic boolean. More...
 
bool automatically_add_to_executor_with_node () const
 Return true if this callback group should be automatically added to an executor by the node. More...
 

Protected Member Functions

void add_publisher (const rclcpp::PublisherBase::SharedPtr publisher_ptr)
 
void add_subscription (const rclcpp::SubscriptionBase::SharedPtr subscription_ptr)
 
void add_timer (const rclcpp::TimerBase::SharedPtr timer_ptr)
 
void add_service (const rclcpp::ServiceBase::SharedPtr service_ptr)
 
void add_client (const rclcpp::ClientBase::SharedPtr client_ptr)
 
void add_waitable (const rclcpp::Waitable::SharedPtr waitable_ptr)
 
void remove_waitable (const rclcpp::Waitable::SharedPtr waitable_ptr) noexcept
 

Protected Attributes

CallbackGroupType type_
 
std::mutex mutex_
 
std::atomic_bool associated_with_executor_
 
std::vector< rclcpp::SubscriptionBase::WeakPtr > subscription_ptrs_
 
std::vector< rclcpp::TimerBase::WeakPtr > timer_ptrs_
 
std::vector< rclcpp::ServiceBase::WeakPtr > service_ptrs_
 
std::vector< rclcpp::ClientBase::WeakPtr > client_ptrs_
 
std::vector< rclcpp::Waitable::WeakPtr > waitable_ptrs_
 
std::atomic_bool can_be_taken_from_
 
const bool automatically_add_to_executor_with_node_
 

Friends

class rclcpp::node_interfaces::NodeServices
 
class rclcpp::node_interfaces::NodeTimers
 
class rclcpp::node_interfaces::NodeTopics
 
class rclcpp::node_interfaces::NodeWaitables
 

Constructor & Destructor Documentation

◆ CallbackGroup()

rclcpp::CallbackGroup::CallbackGroup ( CallbackGroupType  group_type,
bool  automatically_add_to_executor_with_node = true 
)
explicit

Constructor for CallbackGroup.

Callback Groups have a type, either 'Mutually Exclusive' or 'Reentrant' and when creating one the type must be specified.

Callbacks in Reentrant Callback Groups must be able to:

  • run at the same time as themselves (reentrant)
  • run at the same time as other callbacks in their group
  • run at the same time as other callbacks in other groups

Callbacks in Mutually Exclusive Callback Groups:

  • will not be run multiple times simultaneously (non-reentrant)
  • will not be run at the same time as other callbacks in their group
  • but must run at the same time as callbacks in other groups

Additionally, callback groups have a property which determines whether or not they are added to an executor with their associated node automatically. When creating a callback group the automatically_add_to_executor_with_node argument determines this behavior, and if true it will cause the newly created callback group to be added to an executor with the node when the Executor::add_node method is used. If false, this callback group will not be added automatically and would have to be added to an executor manually using the Executor::add_callback_group method.

Whether the node was added to the executor before creating the callback group, or after, is irrelevant; the callback group will be automatically added to the executor in either case.

Parameters
[in]group_typeThe type of the callback group.
[in]automatically_add_to_executor_with_nodeA boolean that determines whether a callback group is automatically added to an executor with the node with which it is associated.

Member Function Documentation

◆ find_subscription_ptrs_if()

template<typename Function >
rclcpp::SubscriptionBase::SharedPtr rclcpp::CallbackGroup::find_subscription_ptrs_if ( Function  func) const
inline

◆ find_timer_ptrs_if()

template<typename Function >
rclcpp::TimerBase::SharedPtr rclcpp::CallbackGroup::find_timer_ptrs_if ( Function  func) const
inline

◆ find_service_ptrs_if()

template<typename Function >
rclcpp::ServiceBase::SharedPtr rclcpp::CallbackGroup::find_service_ptrs_if ( Function  func) const
inline

◆ find_client_ptrs_if()

template<typename Function >
rclcpp::ClientBase::SharedPtr rclcpp::CallbackGroup::find_client_ptrs_if ( Function  func) const
inline

◆ find_waitable_ptrs_if()

template<typename Function >
rclcpp::Waitable::SharedPtr rclcpp::CallbackGroup::find_waitable_ptrs_if ( Function  func) const
inline

◆ can_be_taken_from()

std::atomic_bool& rclcpp::CallbackGroup::can_be_taken_from ( )

◆ type()

const CallbackGroupType& rclcpp::CallbackGroup::type ( ) const

◆ get_associated_with_executor_atomic()

std::atomic_bool& rclcpp::CallbackGroup::get_associated_with_executor_atomic ( )

Return a reference to the 'associated with executor' atomic boolean.

When a callback group is added to an executor this boolean is checked to ensure it has not already been added to another executor. If it has not been, then this boolean is set to true to indicate it is now associated with an executor.

When the callback group is removed from the executor, this atomic boolean is set back to false.

Returns
the 'associated with executor' atomic boolean

◆ automatically_add_to_executor_with_node()

bool rclcpp::CallbackGroup::automatically_add_to_executor_with_node ( ) const

Return true if this callback group should be automatically added to an executor by the node.

Returns
boolean true if this callback group should be automatically added to an executor when the associated node is added, otherwise false.

◆ add_publisher()

void rclcpp::CallbackGroup::add_publisher ( const rclcpp::PublisherBase::SharedPtr  publisher_ptr)
protected

◆ add_subscription()

void rclcpp::CallbackGroup::add_subscription ( const rclcpp::SubscriptionBase::SharedPtr  subscription_ptr)
protected

◆ add_timer()

void rclcpp::CallbackGroup::add_timer ( const rclcpp::TimerBase::SharedPtr  timer_ptr)
protected

◆ add_service()

void rclcpp::CallbackGroup::add_service ( const rclcpp::ServiceBase::SharedPtr  service_ptr)
protected

◆ add_client()

void rclcpp::CallbackGroup::add_client ( const rclcpp::ClientBase::SharedPtr  client_ptr)
protected

◆ add_waitable()

void rclcpp::CallbackGroup::add_waitable ( const rclcpp::Waitable::SharedPtr  waitable_ptr)
protected

◆ remove_waitable()

void rclcpp::CallbackGroup::remove_waitable ( const rclcpp::Waitable::SharedPtr  waitable_ptr)
protectednoexcept

Friends And Related Function Documentation

◆ rclcpp::node_interfaces::NodeServices

◆ rclcpp::node_interfaces::NodeTimers

◆ rclcpp::node_interfaces::NodeTopics

◆ rclcpp::node_interfaces::NodeWaitables

Member Data Documentation

◆ type_

CallbackGroupType rclcpp::CallbackGroup::type_
protected

◆ mutex_

std::mutex rclcpp::CallbackGroup::mutex_
mutableprotected

◆ associated_with_executor_

std::atomic_bool rclcpp::CallbackGroup::associated_with_executor_
protected

◆ subscription_ptrs_

std::vector<rclcpp::SubscriptionBase::WeakPtr> rclcpp::CallbackGroup::subscription_ptrs_
protected

◆ timer_ptrs_

std::vector<rclcpp::TimerBase::WeakPtr> rclcpp::CallbackGroup::timer_ptrs_
protected

◆ service_ptrs_

std::vector<rclcpp::ServiceBase::WeakPtr> rclcpp::CallbackGroup::service_ptrs_
protected

◆ client_ptrs_

std::vector<rclcpp::ClientBase::WeakPtr> rclcpp::CallbackGroup::client_ptrs_
protected

◆ waitable_ptrs_

std::vector<rclcpp::Waitable::WeakPtr> rclcpp::CallbackGroup::waitable_ptrs_
protected

◆ can_be_taken_from_

std::atomic_bool rclcpp::CallbackGroup::can_be_taken_from_
protected

◆ automatically_add_to_executor_with_node_

const bool rclcpp::CallbackGroup::automatically_add_to_executor_with_node_
protected

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