|
ESPHome 2026.3.2
|
Lazy-allocating callback manager that only allocates memory when callbacks are registered. More...
#include <helpers.h>
Public Member Functions | |
| LazyCallbackManager ()=default | |
| ~LazyCallbackManager () | |
| Destructor - clean up allocated CallbackManager if any. | |
| LazyCallbackManager (const LazyCallbackManager &)=delete | |
| LazyCallbackManager & | operator= (const LazyCallbackManager &)=delete |
| LazyCallbackManager (LazyCallbackManager &&)=delete | |
| LazyCallbackManager & | operator= (LazyCallbackManager &&)=delete |
| void | add (std::function< void(Ts...)> &&callback) |
| Add a callback to the list. Allocates the underlying CallbackManager on first use. | |
| void | call (Ts... args) |
| Call all callbacks in this manager. No-op if no callbacks registered. | |
| size_t | size () const |
| Return the number of registered callbacks. | |
| bool | empty () const |
| Check if any callbacks are registered. | |
| void | operator() (Ts... args) |
| Call all callbacks in this manager. | |
Protected Attributes | |
| CallbackManager< void(Ts...)> * | callbacks_ {nullptr} |
Lazy-allocating callback manager that only allocates memory when callbacks are registered.
This is a drop-in replacement for CallbackManager that saves memory when no callbacks are registered (common case after the Controller Registry eliminated per-entity callbacks from API and web_server components).
Memory overhead comparison (32-bit systems):
Uses plain pointer instead of unique_ptr to avoid template instantiation overhead. The class is explicitly non-copyable/non-movable for Rule of Five compliance.
| Ts | The arguments for the callbacks, wrapped in void(). |
|
default |
|
inline |
Destructor - clean up allocated CallbackManager if any.
In practice this never runs (entities live for device lifetime) but included for correctness.
|
delete |
|
delete |
|
inline |
Add a callback to the list. Allocates the underlying CallbackManager on first use.
|
inline |
|
inline |
|
inline |
|
delete |
|
delete |
|
inline |
|
protected |