diff --git a/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp b/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp index f0be547259a2b8..3f1d88621bdbfb 100644 --- a/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp @@ -127,9 +127,6 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ChipLogProgress(DeviceLayer, "IPv4 Server ready..."); @@ -145,11 +142,10 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event chip::app::DnssdServer::Instance().StartServer(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR // Init OTA requestor only when we have gotten IPv6 address - if (!isOTAInitialized) + if (OTAInitializer::Instance().CheckInit()) { chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - isOTAInitialized = true; } #endif } diff --git a/examples/chef/ameba/main/DeviceCallbacks.cpp b/examples/chef/ameba/main/DeviceCallbacks.cpp index 23030fead6f986..d32135cb48765c 100644 --- a/examples/chef/ameba/main/DeviceCallbacks.cpp +++ b/examples/chef/ameba/main/DeviceCallbacks.cpp @@ -105,9 +105,6 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ChipLogProgress(DeviceLayer, "IPv4 Server ready..."); @@ -123,11 +120,10 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event chip::app::DnssdServer::Instance().StartServer(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR // Init OTA requestor only when we have gotten IPv6 address - if (!isOTAInitialized) + if (OTAInitializer::Instance().CheckInit()) { chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - isOTAInitialized = true; } #endif } diff --git a/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp b/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp index babcc549eba3bb..cc855031952eda 100644 --- a/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp @@ -127,9 +127,6 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ChipLogProgress(DeviceLayer, "IPv4 Server ready..."); @@ -145,11 +142,10 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event chip::app::DnssdServer::Instance().StartServer(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR // Init OTA requestor only when we have gotten IPv6 address - if (!isOTAInitialized) + if (OTAInitializer::Instance().CheckInit()) { chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - isOTAInitialized = true; } #endif } diff --git a/examples/lighting-app/ameba/main/DeviceCallbacks.cpp b/examples/lighting-app/ameba/main/DeviceCallbacks.cpp index 957512f727ba1a..d6fd23d9521451 100644 --- a/examples/lighting-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/lighting-app/ameba/main/DeviceCallbacks.cpp @@ -107,10 +107,6 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif - if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { printf("IPv4 Server ready..."); @@ -126,11 +122,10 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event chip::app::DnssdServer::Instance().StartServer(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR // Init OTA requestor only when we have gotten IPv6 address - if (!isOTAInitialized) + if (OTAInitializer::Instance().CheckInit()) { chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - isOTAInitialized = true; } #endif } diff --git a/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp b/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp index e2da60638d3d7d..baa7910e3030bf 100644 --- a/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp @@ -127,9 +127,6 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ChipLogProgress(DeviceLayer, "IPv4 Server ready..."); @@ -145,11 +142,10 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event chip::app::DnssdServer::Instance().StartServer(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR // Init OTA requestor only when we have gotten IPv6 address - if (!isOTAInitialized) + if (OTAInitializer::Instance().CheckInit()) { chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - isOTAInitialized = true; } #endif } diff --git a/examples/platform/ameba/ota/OTAInitializer.cpp b/examples/platform/ameba/ota/OTAInitializer.cpp index 5f2bcaab0b9b21..e1ea16197f0a40 100644 --- a/examples/platform/ameba/ota/OTAInitializer.cpp +++ b/examples/platform/ameba/ota/OTAInitializer.cpp @@ -36,16 +36,18 @@ AmebaOTAImageProcessor gImageProcessor; extern "C" void amebaQueryImageCmdHandler() { ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler"); - PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); }); + if (OTAInitializer::Instance().CheckInit()) + PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); }); } extern "C" void amebaApplyUpdateCmdHandler() { ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler"); - PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); }); + if (OTAInitializer::Instance().CheckInit()) + PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); }); } -void OTAInitializer::InitOTARequestor(void) +void OTAInitializer::InitOTARequestor() { SetRequestorInstance(&gRequestorCore); gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage()); @@ -55,4 +57,10 @@ void OTAInitializer::InitOTARequestor(void) // Connect the Downloader and Image Processor objects gDownloader.SetImageProcessorDelegate(&gImageProcessor); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); + initialized = true; +} + +bool OTAInitializer::CheckInit() +{ + return initialized; } diff --git a/examples/platform/ameba/ota/OTAInitializer.h b/examples/platform/ameba/ota/OTAInitializer.h index f678c80a780c00..26e3bc4aaca849 100644 --- a/examples/platform/ameba/ota/OTAInitializer.h +++ b/examples/platform/ameba/ota/OTAInitializer.h @@ -24,4 +24,8 @@ class OTAInitializer return sInitOTA; } void InitOTARequestor(void); + bool CheckInit(void); + +private: + bool initialized = false; };