Timeout Manger

mrs_lib::TimeoutManager2

class TimeoutManager2

Manager for registering callbacks that are called after specified time of inactivity.

Public Types

using Callback = std::function<void(rclcpp::Time)>

Public Functions

explicit TimeoutManager2(TimeoutManagerNodeInterfaces node_interfaces, std::chrono::nanoseconds update_period)

Construct the timeout manager.

Parameters:
  • node_interfaces – ROS node interfaces to use by the timeout manager.

  • update_period – How often to check for the timeout expiration.

~TimeoutManager2()

Destructor.

TimeoutManager2(const TimeoutManager2&) = delete

TimeoutManager2 is not copyable.

TimeoutManager2 &operator=(const TimeoutManager2&) = delete

TimeoutManager2 is not copyable.

TimeoutManager2(TimeoutManager2&&) noexcept

Move constructor.

TimeoutManager2 &operator=(TimeoutManager2&&) noexcept

Move assignment.

std::shared_ptr<TimeoutManagerHandle> register_new(TimeoutManagerRegisterOptions options)

Register a new timeout to be handled by this manager.

Returns:

RAII handle to the timeout for managing it.

void start_all()

Start all timeouts managed by this manager.

void pause_all()

Stop all timeouts managed by this manager.

void clear_deleted()

Remove all timeouts for which the handles were already deleted.

Friends

friend class internal::TimeoutManagerHandleKey

mrs_lib::TimeoutManagerRegisterOptions

struct TimeoutManagerRegisterOptions

Options for registering a timeout.

Public Members

std::chrono::nanoseconds timeout

Time of inactivity after which the callback is called.

std::function<void(rclcpp::Time)> callback

Callback called when timeout is triggered.

bool started = true

Whether the timeout should be created in the started state.

bool oneshot = false

Whether the timeout should stop after triggering once.

mrs_lib::TimeoutManagerHandle

class TimeoutManagerHandle

Handle to a registered timeout, that unregisters it on destruction.

Public Functions

explicit TimeoutManagerHandle(internal::TimeoutManagerHandleKey key, TimeoutManagerRegisterOptions options, std::shared_ptr<rclcpp::node_interfaces::NodeClockInterface> clock_interface)

Construct the handle.

Note

This function is for internal use and should not be called from user code.

Parameters:
  • key – Key type to prevent users from calling this function.

  • options – Options to configure the timeout.

  • clock_interface – Clock interface to use for obtaining current time.

~TimeoutManagerHandle() = default

Default destructor.

TimeoutManagerHandle(const TimeoutManagerHandle&) = delete

TimeoutManagerHandle is immovable.

TimeoutManagerHandle &operator=(const TimeoutManagerHandle&) = delete

TimeoutManagerHandle is immovable.

TimeoutManagerHandle(TimeoutManagerHandle&&) = delete

TimeoutManagerHandle is immovable.

TimeoutManagerHandle &operator=(TimeoutManagerHandle&&) = delete

TimeoutManagerHandle is immovable.

void reset_timeout()

Reset the timeout countdown.

If this function is not called before the timeout expires, the configured callback is called.

void start()

Start the timeout.

void pause()

Stop the timeout.

After this call, new timeout callbacks won’t be called until a call to start.

void set_timeout(std::chrono::nanoseconds timeout)

Set a new duration after which the timeout is called.

bool is_started() const

Check if the timeout is started.

Returns:

true if it is started, false otherwise.

rclcpp::Time get_last_reset() const

Get time of last call to reset.

Returns:

Last time the reset was called.

void run_callback_if_expired(internal::TimeoutManagerHandleKey key)

Check if timeout is expired and if yes, call it.

Note

This function is for internal use and should not be called from user code.

Parameters:

key – Key type to prevent users from calling this function.