nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
rclcpp::TimerHandle Class Reference

#include <timer.hpp>

Inheritance diagram for rclcpp::TimerHandle:
Collaboration diagram for rclcpp::TimerHandle:

Public Types

using element_type = ::rclcpp::Timer

Public Member Functions

constexpr size_t handle_id () const
 The packed executor handle this refers to. For introspection and tests.
constexpr operator bool () const
TimerOps * operator-> ()
 timer_->cancel() and friends.
const TimerOps * operator-> () const
 Const overload of operator->.
void reset ()
constexpr TimerHandle ()
constexpr TimerHandle (decltype(nullptr))
constexpr TimerHandle (void *executor, size_t handle_id)

Friends

constexpr bool operator!= (const TimerHandle &a, const TimerHandle &b)
constexpr bool operator!= (const TimerHandle &a, decltype(nullptr))
constexpr bool operator!= (decltype(nullptr), const TimerHandle &a)
constexpr bool operator== (const TimerHandle &a, const TimerHandle &b)
constexpr bool operator== (const TimerHandle &a, decltype(nullptr))
constexpr bool operator== (decltype(nullptr), const TimerHandle &a)

Detailed Description

The handle create_wall_timer / rclcpp::create_timer return, and what Timer::SharedPtr names — phase-476 W2.

Two words, trivially copyable, no allocation, and present on every target: the timer's callable lives in the executor arena (phase-476 W2), so there is nothing on the C++ side for a std::shared_ptr to own. That is what freed timer.hpp from <memory> and <functional>.

timer_->cancel(), timer_->reset(), timer_->is_ready() and timer_->time_until_trigger() keep their rclcpp spelling through operator->, which reaches a [TimerOps].

WHAT DIFFERS FROM A shared_ptr, stated because a ported file cannot see it:

  • The handle does not OWN the timer. Dropping or overwriting it leaves the timer firing, where upstream destroys a timer when its last shared_ptr goes. The node owns its timers: destroying the node releases them (phase-476 W0). That matches what this API did before W2, when the node co-owned a heap cell for every timer.
  • timer_.reset() RELEASES the timer, for every copy at once: the closest thing to upstream's "drop my reference" that a non-counting handle can offer, and the spelling ported code uses to stop a timer for good.
  • A copy that outlives a release is SAFE. The handle carries the generation of the slot it was issued for (phase-476 W0), so every operation through a stale copy fails instead of reaching whatever registration took the slot.

Member Typedef Documentation

◆ element_type

using rclcpp::TimerHandle::element_type = ::rclcpp::Timer

What this handle refers to, for generic code that spells a pointee type the way std::shared_ptr exposes one. A NAME only: operator-> reaches a [TimerOps], not a Timer object.

Constructor & Destructor Documentation

◆ TimerHandle() [1/3]

rclcpp::TimerHandle::TimerHandle ( )
inlineconstexpr

◆ TimerHandle() [2/3]

rclcpp::TimerHandle::TimerHandle ( decltype(nullptr) )
inlineconstexpr

Null, spelled the way a ported file spells it (Timer::SharedPtr timer_ = nullptr;).

◆ TimerHandle() [3/3]

rclcpp::TimerHandle::TimerHandle ( void * executor,
size_t handle_id )
inlineconstexpr

Member Function Documentation

◆ handle_id()

size_t rclcpp::TimerHandle::handle_id ( ) const
inlineconstexpr

The packed executor handle this refers to. For introspection and tests.

◆ operator bool()

rclcpp::TimerHandle::operator bool ( ) const
inlineexplicitconstexpr

if (timer_). A default-constructed or reset() handle is empty; one from a successful registration is not (even once released elsewhere — the operations are what report that).

◆ operator->() [1/2]

TimerOps * rclcpp::TimerHandle::operator-> ( )
inline

timer_->cancel() and friends.

◆ operator->() [2/2]

const TimerOps * rclcpp::TimerHandle::operator-> ( ) const
inline

Const overload of operator->.

◆ reset()

void rclcpp::TimerHandle::reset ( )
inline

timer_.reset() — release the timer: it stops for good, its arena entry and captured callable are freed, and this handle becomes empty. Other copies become stale and fail safely. A no-op on an empty handle.

◆ operator!= [1/3]

bool operator!= ( const TimerHandle & a,
const TimerHandle & b )
friend

◆ operator!= [2/3]

bool operator!= ( const TimerHandle & a,
decltype(nullptr)  )
friend

◆ operator!= [3/3]

bool operator!= ( decltype(nullptr) ,
const TimerHandle & a )
friend

◆ operator== [1/3]

bool operator== ( const TimerHandle & a,
const TimerHandle & b )
friend

◆ operator== [2/3]

bool operator== ( const TimerHandle & a,
decltype(nullptr)  )
friend

◆ operator== [3/3]

bool operator== ( decltype(nullptr) ,
const TimerHandle & a )
friend

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