nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
rclcpp::GuardCondition Class Reference

#include <guard_condition.hpp>

Public Member Functions

void attach_closure_block (detail::HostedBlockBase *block)
 
Result clear ()
 
 GuardCondition ()
 
 GuardCondition (GuardCondition &&other)
 
bool is_triggered () const
 
bool is_valid () const
 Check if the guard condition is initialized and valid.
 
GuardCondition & operator= (GuardCondition &&other)
 
Result trigger ()
 
 ~GuardCondition ()
 

Friends

class ::rclcpp::Node
 

Detailed Description

Guard condition for cross-thread signaling.

Guard conditions allow any thread to wake the executor and optionally invoke a callback during spin_once(). The trigger() method is thread-safe and lock-free.

Usage:

void on_signal(void* ctx) { /* handle event *&zwj;/ }
rclcpp::GuardCondition guard;
RCLCPP_TRY(node.create_guard_condition(guard, on_signal));
// From another thread:
guard.trigger();
// Callback fires on next spin_once()
Definition client.hpp:129

Constructor & Destructor Documentation

◆ ~GuardCondition()

rclcpp::GuardCondition::~GuardCondition ( )
inline

Destructor — releases the guard condition (issue 1667): its executor entry is freed, so spin_once stops polling it and the callback slot goes back to NROS_EXECUTOR_MAX_CBS. Sound because this object is non-copyable and the only holder of the trigger handle; trigger it from another thread only while it is alive.

◆ GuardCondition() [1/2]

rclcpp::GuardCondition::GuardCondition ( GuardCondition &&  other)
inline

◆ GuardCondition() [2/2]

rclcpp::GuardCondition::GuardCondition ( )
inline

Default constructor — creates an uninitialized guard condition. Use Node::create_guard_condition() to initialize.

Member Function Documentation

◆ attach_closure_block()

void rclcpp::GuardCondition::attach_closure_block ( detail::HostedBlockBase *  block)
inline

◆ clear()

Result rclcpp::GuardCondition::clear ( )
inline

Clear the flag without dispatching — the other half of is_triggered(), for a polling owner that has handled the event itself.

◆ is_triggered()

bool rclcpp::GuardCondition::is_triggered ( ) const
inline

Is this guard condition triggered and not yet dispatched?

The RFC-0022 polling tier: a task that owns its own loop and never reaches spin_once still needs to see the flag another thread or an ISR set. rcl and rclcpp have no such reader — a wait set is the only way to observe an rclcpp guard condition — so this is ours, and phase-417 W4.e gave C++ and Rust the reader C already had.

The executor CONSUMES the flag when it dispatches, so this answers "set and not yet dispatched": poll it or take the callback, not both.

◆ is_valid()

bool rclcpp::GuardCondition::is_valid ( ) const
inline

Check if the guard condition is initialized and valid.

◆ operator=()

GuardCondition & rclcpp::GuardCondition::operator= ( GuardCondition &&  other)
inline

◆ trigger()

Result rclcpp::GuardCondition::trigger ( )
inline

Trigger the guard condition (thread-safe, lock-free).

The callback will be invoked on the next spin_once().

Friends And Related Symbol Documentation

◆ ::rclcpp::Node


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