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

A condition that can be waited on in a single wait set and asynchronously triggered. More...

#include <guard_condition.hpp>

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

Public Member Functions

 GuardCondition (rclcpp::Context::SharedPtr context=rclcpp::contexts::get_global_default_context())
 Construct the guard condition, optionally specifying which Context to use. More...
 
virtual ~GuardCondition ()
 
rclcpp::Context::SharedPtr get_context () const
 Return the context used when creating this guard condition. More...
 
const rcl_guard_condition_tget_rcl_guard_condition () const
 Return the underlying rcl guard condition structure. More...
 
void trigger ()
 Notify the wait set waiting on this condition, if any, that the condition had been met. More...
 
bool exchange_in_use_by_wait_set_state (bool in_use_state)
 Exchange the "in use by wait set" state for this guard condition. More...
 

Protected Attributes

rclcpp::Context::SharedPtr context_
 
rcl_guard_condition_t rcl_guard_condition_
 
std::atomic< bool > in_use_by_wait_set_ {false}
 

Detailed Description

A condition that can be waited on in a single wait set and asynchronously triggered.

Constructor & Destructor Documentation

◆ GuardCondition()

rclcpp::GuardCondition::GuardCondition ( rclcpp::Context::SharedPtr  context = rclcpp::contexts::get_global_default_context())
explicit

Construct the guard condition, optionally specifying which Context to use.

Parameters
[in]contextOptional custom context to be used. Defaults to using the global default context singleton. Shared ownership of the context is held with the guard condition until destruction.
Exceptions
std::invalid_argumentif the context is nullptr.
rclcpp::exceptions::RCLErrorbased exceptions when underlying rcl functions fail.

◆ ~GuardCondition()

virtual rclcpp::GuardCondition::~GuardCondition ( )
virtual

Member Function Documentation

◆ get_context()

rclcpp::Context::SharedPtr rclcpp::GuardCondition::get_context ( ) const

Return the context used when creating this guard condition.

◆ get_rcl_guard_condition()

const rcl_guard_condition_t& rclcpp::GuardCondition::get_rcl_guard_condition ( ) const

Return the underlying rcl guard condition structure.

◆ trigger()

void rclcpp::GuardCondition::trigger ( )

Notify the wait set waiting on this condition, if any, that the condition had been met.

This function is thread-safe, and may be called concurrently with waiting on this guard condition in a wait set.

Exceptions
rclcpp::exceptions::RCLErrorbased exceptions when underlying rcl functions fail.

◆ exchange_in_use_by_wait_set_state()

bool rclcpp::GuardCondition::exchange_in_use_by_wait_set_state ( bool  in_use_state)

Exchange the "in use by wait set" state for this guard condition.

This is used to ensure this guard condition is not used by multiple wait sets at the same time.

Parameters
[in]in_use_statethe new state to exchange into the state, true indicates it is now in use by a wait set, and false is that it is no longer in use by a wait set.
Returns
the previous state.

Member Data Documentation

◆ context_

rclcpp::Context::SharedPtr rclcpp::GuardCondition::context_
protected

◆ rcl_guard_condition_

rcl_guard_condition_t rclcpp::GuardCondition::rcl_guard_condition_
protected

◆ in_use_by_wait_set_

std::atomic<bool> rclcpp::GuardCondition::in_use_by_wait_set_ {false}
protected

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