idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::event_base< IdEnum > Class Template Reference

Typed event base template. More...

Public Types

using id_type = IdEnum
 The enum type for event IDs.
 

Public Member Functions

constexpr event_base (esp_event_base_t base) noexcept
 Constructs from an ESP-IDF event base pointer.
 
constexpr esp_event_base_t idf_base () const noexcept
 Returns the underlying ESP-IDF event base.
 
constexpr event_type< IdEnum > operator() (IdEnum id) const
 Creates an event_type combining this base with a specific ID.
 

Detailed Description

template<typename IdEnum>
class idfxx::event_base< IdEnum >

Typed event base template.

Represents a category of related events, parameterized by an enum type that defines the specific event IDs within that category. This ensures type safety when registering listeners and posting events.

Template Parameters
IdEnumThe enum type for event IDs within this base.
// Define a custom event category
enum class my_event : int32_t { started, stopped };
IDFXX_EVENT_DEFINE_BASE(my_events, my_event);
// Use with ESP-IDF event categories
inline constexpr event_base<wifi_event_t> wifi{WIFI_EVENT};
Typed event base template.
Definition event.hpp:84
#define IDFXX_EVENT_DEFINE_BASE(name, id_enum)
Defines an event base.
Definition event.hpp:50

Definition at line 84 of file event.hpp.

Member Typedef Documentation

◆ id_type

template<typename IdEnum >
using idfxx::event_base< IdEnum >::id_type = IdEnum

The enum type for event IDs.

Definition at line 87 of file event.hpp.

Constructor & Destructor Documentation

◆ event_base()

template<typename IdEnum >
constexpr idfxx::event_base< IdEnum >::event_base ( esp_event_base_t  base)
inlineconstexprnoexcept

Constructs from an ESP-IDF event base pointer.

Parameters
baseThe event base pointer (must have static storage duration).
Warning
For custom event bases, use the IDFXX_EVENT_DEFINE_BASE macro instead of this constructor. The macro creates the underlying ESP-IDF event base with proper static storage duration.

Only use this constructor directly when wrapping existing ESP-IDF system event bases (e.g., WIFI_EVENT, IP_EVENT):

// Wrap ESP-IDF system events - use constructor directly
inline constexpr event_base<wifi_event_t> wifi{WIFI_EVENT};
inline constexpr event_base<ip_event_t> ip{IP_EVENT};
// Define custom event bases - use the macro instead
enum class my_event_id : int32_t { started, stopped };
IDFXX_EVENT_DEFINE_BASE(my_events, my_event_id);

Definition at line 111 of file event.hpp.

Member Function Documentation

◆ idf_base()

template<typename IdEnum >
constexpr esp_event_base_t idfxx::event_base< IdEnum >::idf_base ( ) const
inlineconstexprnoexcept

Returns the underlying ESP-IDF event base.

Returns
The esp_event_base_t value.

Definition at line 118 of file event.hpp.

Referenced by idfxx::event_loop::try_listener_add(), idfxx::event_loop::try_listener_add(), idfxx::event_loop::try_post(), and idfxx::event_loop::try_post().


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