mirror of
https://github.com/esphome/esphome.git
synced 2025-08-07 19:07:45 +00:00
Revert "fix"
This reverts commit c96ffefa42b43cf102f9615ace915f2d0fc532ac.
This commit is contained in:
parent
c96ffefa42
commit
519c49f175
@ -69,29 +69,29 @@ class OTAComponent : public Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Thread-safe callback wrapper that automatically defers to main loop.
|
/** Thread-safe callback manager that automatically defers to main loop.
|
||||||
*
|
*
|
||||||
* This ensures all OTA callbacks are executed in the main loop task,
|
* This ensures all OTA callbacks are executed in the main loop task,
|
||||||
* making them safe to call from any context (including web_server's OTA task).
|
* making them safe to call from any context (including web_server's OTA task).
|
||||||
* Existing code doesn't need changes - callbacks are automatically deferred.
|
* Existing code doesn't need changes - callbacks are automatically deferred.
|
||||||
*/
|
*/
|
||||||
class StateCallbackManager {
|
class DeferredCallbackManager : public CallbackManager<void(OTAState, float, uint8_t)> {
|
||||||
public:
|
public:
|
||||||
StateCallbackManager(OTAComponent *component) : component_(component) {}
|
DeferredCallbackManager(OTAComponent *component) : component_(component) {}
|
||||||
|
|
||||||
void add(std::function<void(OTAState, float, uint8_t)> &&callback) { callbacks_.add(std::move(callback)); }
|
|
||||||
|
|
||||||
|
/// Override call to automatically defer to main loop
|
||||||
void call(OTAState state, float progress, uint8_t error) {
|
void call(OTAState state, float progress, uint8_t error) {
|
||||||
// Always defer to main loop for thread safety
|
// Always defer to main loop for thread safety
|
||||||
component_->defer([this, state, progress, error]() { this->callbacks_.call(state, progress, error); });
|
component_->defer([this, state, progress, error]() {
|
||||||
|
CallbackManager<void(OTAState, float, uint8_t)>::call(state, progress, error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OTAComponent *component_;
|
OTAComponent *component_;
|
||||||
CallbackManager<void(OTAState, float, uint8_t)> callbacks_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
StateCallbackManager state_callback_{this};
|
DeferredCallbackManager state_callback_{this};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,10 +114,10 @@ class OTAGlobalCallback {
|
|||||||
OTAGlobalCallback *get_global_ota_callback();
|
OTAGlobalCallback *get_global_ota_callback();
|
||||||
void register_ota_platform(OTAComponent *ota_caller);
|
void register_ota_platform(OTAComponent *ota_caller);
|
||||||
|
|
||||||
// Thread-safe callback execution is automatically provided by StateCallbackManager
|
// Thread-safe callback execution is automatically provided by DeferredCallbackManager
|
||||||
// which uses Component::defer() to ensure all OTA callbacks run in the main loop task.
|
// which overrides call() to use Component::defer(). This ensures all OTA callbacks
|
||||||
// This makes OTA callbacks safe to call from any context including web_server's
|
// run in the main loop task, making them safe to call from any context including
|
||||||
// separate OTA task. No code changes needed.
|
// web_server's separate OTA task. No code changes needed.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace ota_base
|
} // namespace ota_base
|
||||||
|
Loading…
x
Reference in New Issue
Block a user