|
ESPHome 2026.5.0-dev
|
Helper class to allow having multiple subscribers to a callback. More...
#include <helpers.h>
Public Member Functions | |
| CallbackManager ()=default | |
| ~CallbackManager () | |
| CallbackManager (const CallbackManager &)=delete | |
| CallbackManager & | operator= (const CallbackManager &)=delete |
| CallbackManager (CallbackManager &&other) noexcept | |
| CallbackManager & | operator= (CallbackManager &&other) noexcept |
| template<typename F > | |
| void | add (F &&callback) |
| Add any callable. | |
| void ESPHOME_ALWAYS_INLINE | call (Ts... args) |
| Call all callbacks in this manager. | |
| uint16_t | size () const |
| void | operator() (Ts... args) |
| Call all callbacks in this manager. | |
Protected Member Functions | |
| void | add_ (CbType cb) |
| Non-template core to avoid code duplication per lambda type. | |
Protected Attributes | |
| CbType * | data_ {nullptr} |
| uint16_t | size_ {0} |
| uint16_t | capacity_ {0} |
Helper class to allow having multiple subscribers to a callback.
Uses a trivial-copyable-specialized container instead of std::vector to avoid template bloat (_M_realloc_insert, exception-safe copies). Since Callback is trivially copyable (just {fn_ptr, ctx_ptr}), reallocation is a plain memcpy. Uses uint16_t for size/capacity (8 bytes on 32-bit vs 12 for std::vector). Grows to exact size on each add — callbacks are registered during setup() and most instances have only 1-2 callbacks, so slack capacity is wasteful.
| Ts | The arguments for the callbacks, wrapped in void(). |
|
default |
|
inline |
|
delete |
|
inlinenoexcept |
|
inline |
|
inlineprotected |
Non-template core to avoid code duplication per lambda type.
Inline fast path; cold growth path is in helpers.cpp via callback_manager_grow().
|
inline |
|
inline |
|
inlinenoexcept |
|
delete |
|
inline |
|
protected |
|
protected |
|
protected |