mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Manage global pointer better
This commit is contained in:
		| @@ -58,7 +58,7 @@ void ESP32BLETracker::setup() { | ||||
|   this->scanner_idle_ = true; | ||||
|  | ||||
| #ifdef USE_OTA | ||||
|   ota::global_ota_component->add_on_state_callback( | ||||
|   ota::get_global_ota_callback()->add_on_state_callback( | ||||
|       [this](ota::OTAState state, float progress, uint8_t error, ota::OTAComponent *comp) { | ||||
|         if (state == ota::OTA_STARTED) { | ||||
|           this->stop_scan(); | ||||
|   | ||||
| @@ -23,7 +23,7 @@ static constexpr u_int16_t OTA_BLOCK_SIZE = 8192; | ||||
|  | ||||
| void ESPHomeOTAComponent::setup() { | ||||
| #ifdef USE_OTA_STATE_CALLBACK | ||||
|   ota::global_ota_component->register_ota(this); | ||||
|   ota::register_ota_platform(this); | ||||
| #endif | ||||
|  | ||||
|   server_ = socket::socket_ip(SOCK_STREAM, 0); | ||||
|   | ||||
| @@ -4,7 +4,16 @@ namespace esphome { | ||||
| namespace ota { | ||||
|  | ||||
| #ifdef USE_OTA_STATE_CALLBACK | ||||
| OTAGlobalCallback *global_ota_component = new OTAGlobalCallback();  // NOLINT | ||||
| OTAGlobalCallback *global_ota_callback{nullptr}; | ||||
|  | ||||
| OTAGlobalCallback *get_global_ota_callback() { | ||||
|   if (global_ota_callback == nullptr) { | ||||
|     global_ota_callback = new OTAGlobalCallback(); | ||||
|   } | ||||
|   return global_ota_callback; | ||||
| } | ||||
|  | ||||
| void register_ota_platform(OTAComponent *ota_caller) { get_global_ota_callback()->register_ota(ota_caller); } | ||||
| #endif | ||||
|  | ||||
| }  // namespace ota | ||||
|   | ||||
| @@ -81,7 +81,8 @@ class OTAGlobalCallback { | ||||
|   CallbackManager<void(OTAState, float, uint8_t, OTAComponent *)> state_callback_{}; | ||||
| }; | ||||
|  | ||||
| extern OTAGlobalCallback *global_ota_component;  // NOLINT | ||||
| OTAGlobalCallback *get_global_ota_callback(); | ||||
| void register_ota_platform(OTAComponent *ota_caller); | ||||
| #endif | ||||
| std::unique_ptr<ota::OTABackend> make_ota_backend(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user