|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
Type-safe event loop management. More...
Namespaces | |
| namespace | idfxx |
Concepts | |
| concept | idfxx::receivable_event_data |
| Concept for types that can be received as event data. | |
| concept | idfxx::event_data |
| Concept for types that can be both received and posted as event data. | |
Classes | |
| class | idfxx::event_base< IdEnum > |
| Typed event base template. More... | |
| struct | idfxx::event< IdEnum, DataType > |
| A typed event that pairs an event ID with its data type. More... | |
| class | idfxx::event_loop |
| Base class for event loops. More... | |
| class | idfxx::event_loop::listener_handle |
| Handle to a registered event listener. More... | |
| class | idfxx::event_loop::unique_listener_handle |
| RAII handle for event listener registration. More... | |
| class | idfxx::user_event_loop |
| User-created event loop with manual dispatch. More... | |
Macros | |
| #define | IDFXX_EVENT_DEFINE_BASE(name, id_enum) |
| Defines an event base. | |
Typedefs | |
| template<typename DataType > | |
| using | idfxx::event_handler = typename event_handler_traits< DataType >::type |
| Handler type for typed event listeners. | |
| template<typename IdEnum > | |
| using | idfxx::opaque_event_handler = std::move_only_function< void(event_base< IdEnum > base, IdEnum id, void *event_data) const > |
| Callback type for wildcard event listeners. | |
Type-safe event loop management.
Provides event loops for posting and subscribing to events with type-safe event bases and IDs.
Depends on Core Utilities for error handling.
| #define IDFXX_EVENT_DEFINE_BASE | ( | name, | |
| id_enum | |||
| ) |
Defines an event base.
Creates an event_base with the given name and enum type. The event base name string is automatically derived from the variable name.
| name | The variable name for the event base. |
| id_enum | The enum class for event IDs within this base. |
Only one event base may be defined for a given enum type. Defining a second base for the same enum will cause a compilation error (duplicate definition of the ADL lookup function).
Handler type for typed event listeners.
For events with data (DataType is not void), the handler receives a const reference to the data type. For events without data (DataType is void), the handler takes no arguments.
| DataType | The event data type, or void for events without data. |
| using idfxx::opaque_event_handler = typedef std::move_only_function<void(event_base<IdEnum> base, IdEnum id, void* event_data) const> |
| event_loop::listener_handle idfxx::event_loop::listener_add | ( | event< IdEnum, DataType > | event, |
| event_handler< DataType > | callback | ||
| ) |
Registers a type-safe listener for a specific event.
The callback receives the event data directly as its correct type, rather than as a raw void pointer. For events without data, the callback takes no arguments.
| IdEnum | The event ID enum type. |
| DataType | The event data type (or void for events without data). |
| event | The typed event to listen for. |
| callback | Function called when the event occurs. Takes ownership of the callback. |
| std::system_error | on failure. |
Definition at line 932 of file event.hpp.
References idfxx::unwrap().
| event_loop::listener_handle idfxx::event_loop::listener_add | ( | event_base< IdEnum > | base, |
| opaque_event_handler< std::type_identity_t< IdEnum > > | callback | ||
| ) |
Registers a listener for any event from a base.
The callback receives the event base, ID, and raw event data pointer. This overload is intended for wildcard listeners where the data type cannot be known at compile time.
| IdEnum | The event ID enum type. |
| base | The event base. |
| callback | Function called when any event from this base occurs. Takes ownership of the callback. |
| std::system_error | on failure. |
Definition at line 938 of file event.hpp.
References idfxx::base, and idfxx::unwrap().
|
inline |
Removes a listener by handle.
| handle | The listener handle to remove. |
| std::system_error | on failure. |
Definition at line 942 of file event.hpp.
References idfxx::unwrap().
| result< event_loop::listener_handle > idfxx::event_loop::try_listener_add | ( | event< IdEnum, DataType > | event, |
| event_handler< DataType > | callback | ||
| ) |
Registers a type-safe listener for a specific event.
The callback receives the event data directly as its correct type, rather than as a raw void pointer. For events without data, the callback takes no arguments.
| IdEnum | The event ID enum type. |
| DataType | The event data type (or void for events without data). |
| event | The typed event to listen for. |
| callback | Function called when the event occurs. Takes ownership of the callback. |
Definition at line 961 of file event.hpp.
References idfxx::error(), idfxx::event< IdEnum, DataType >::id, and idfxx::invalid_state.
| result< event_loop::listener_handle > idfxx::event_loop::try_listener_add | ( | event_base< IdEnum > | base, |
| opaque_event_handler< std::type_identity_t< IdEnum > > | callback | ||
| ) |
Registers a listener for any event from a base.
The callback receives the event base, ID, and raw event data pointer. This overload is intended for wildcard listeners where the data type cannot be known at compile time.
| IdEnum | The event ID enum type. |
| base | The event base. |
| callback | Function called when any event from this base occurs. Takes ownership of the callback. |
Definition at line 984 of file event.hpp.
References idfxx::base, idfxx::error(), and idfxx::invalid_state.