ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
controller_registry.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_CONTROLLER_REGISTRY
6
9
10namespace esphome {
11
12class Controller;
13
31 public:
37 static void register_controller(Controller *controller) { controllers.push_back(controller); }
38
39// Notify method declarations (generated from entity_types.h)
40// NOLINTBEGIN(bugprone-macro-parentheses)
41#define ENTITY_TYPE_(type, singular, plural, count, upper) // no controller callback
42#define ENTITY_CONTROLLER_TYPE_(type, singular, plural, count, upper, callback) \
43 static void notify_##callback(type *obj);
45#undef ENTITY_TYPE_
46#undef ENTITY_CONTROLLER_TYPE_
47 // NOLINTEND(bugprone-macro-parentheses)
48
49 protected:
51};
52
53} // namespace esphome
54
55// Include controller.h AFTER the class definition so notify methods can be
56// defined inline. This is safe because controller_registry.h is only ever
57// included from .cpp files, never from other headers.
59
60namespace esphome {
61
62// Inline notify methods — each is a tiny loop over 1-2 controllers.
63// Defining them here (rather than in controller_registry.cpp) allows the
64// compiler to inline them into the single call site in each entity's
65// notify_frontend_(), eliminating an unnecessary function-call frame.
66
67// NOLINTBEGIN(bugprone-macro-parentheses)
68#define ENTITY_TYPE_(type, singular, plural, count, upper) // no controller callback
69#define ENTITY_CONTROLLER_TYPE_(type, singular, plural, count, upper, callback) \
70 inline void ControllerRegistry::notify_##callback(type *obj) { \
71 for (auto *controller : controllers) { \
72 controller->on_##callback(obj); \
73 } \
74 }
76#undef ENTITY_TYPE_
77#undef ENTITY_CONTROLLER_TYPE_
78// NOLINTEND(bugprone-macro-parentheses)
79
80} // namespace esphome
81
82#endif // USE_CONTROLLER_REGISTRY
Global registry for Controllers to receive entity state updates.
static void register_controller(Controller *controller)
Register a controller to receive entity state updates.
static StaticVector< Controller *, CONTROLLER_REGISTRY_MAX > controllers
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:210
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7