Class CallbackSignal
Defined in File callback_signal.hpp
Nested Relationships
Nested Types
Class Documentation
-
class CallbackSignal
Thread-safe callback fan-out primitive for cross-state coordination.
CallbackSignal stores a set of zero-argument callbacks. Any state can place a shared CallbackSignal instance in the blackboard, register callbacks from C++ or Python, and later trigger all registered callbacks synchronously or asynchronously.
Triggering uses a snapshot of the currently registered callbacks. Callbacks added or removed while a trigger is already running only affect future triggers.
Public Types
-
using CallbackId = std::uint64_t
Shared pointer aliases for CallbackSignal.
Identifier returned when a callback is registered.
-
using Callback = std::function<void()>
Callback signature used by the signal.
Public Functions
-
CallbackId add_callback(Callback callback)
Register a callback.
- Parameters:
callback – Zero-argument callback to register.
- Throws:
std::invalid_argument – if the callback is empty.
- Returns:
Identifier that can later be passed to remove_callback().
Register a callback that cancels a state when triggered.
- Parameters:
state – State to cancel.
- Throws:
std::invalid_argument – if the state pointer is null.
- Returns:
Identifier that can later be passed to remove_callback().
-
bool remove_callback(CallbackId callback_id)
Remove a previously registered callback.
- Parameters:
callback_id – Identifier returned by add_callback().
- Returns:
True if the callback existed and was removed, false otherwise.
-
void clear_callbacks()
Remove all registered callbacks.
-
std::size_t callback_count() const
Get the number of currently registered callbacks.
- Returns:
Number of callbacks.
-
bool empty() const
Check whether the signal currently has no callbacks.
- Returns:
True when no callbacks are registered.
-
void trigger() const
Trigger all registered callbacks synchronously.
All callbacks from the captured snapshot are executed before this function returns. If one or more callbacks throw an exception, the first exception is rethrown after the snapshot has been processed completely.
-
CallbackSignalFuture::SharedPtr trigger_async() const
Trigger all registered callbacks on a background thread.
- Returns:
Future-like handle that can be waited on.
-
using CallbackId = std::uint64_t