From 248c2e1ca768dc97e9f85358357197a582f6f8c7 Mon Sep 17 00:00:00 2001 From: Carol Yang Date: Thu, 31 Mar 2022 09:53:03 -0700 Subject: [PATCH] [OTA] Shutdown server and stop event loop directly from OTA Image Processor (#16698) --- src/app/clusters/ota-requestor/OTARequestor.cpp | 5 ----- src/app/clusters/ota-requestor/OTARequestor.h | 1 - src/app/clusters/ota-requestor/OTARequestorInterface.h | 3 --- src/platform/Linux/OTAImageProcessorImpl.cpp | 10 +++++++--- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index 6e5b57fb145284..c65620f09e8d10 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -286,11 +286,6 @@ void OTARequestor::Reset() StoreCurrentUpdateInfo(); } -void OTARequestor::Shutdown(void) -{ - mServer->DispatchShutDownAndStopEventLoop(); -} - EmberAfStatus OTARequestor::HandleAnnounceOTAProvider(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const AnnounceOtaProvider::DecodableType & commandData) diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index 664bf4c9b97947..5c64a18adf8a56 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -41,7 +41,6 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe //////////// OTARequestorInterface Implementation /////////////// void Reset(void) override; - void Shutdown(void) override; EmberAfStatus HandleAnnounceOTAProvider( app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, diff --git a/src/app/clusters/ota-requestor/OTARequestorInterface.h b/src/app/clusters/ota-requestor/OTARequestorInterface.h index 855e08233b3f45..f4d593fc217ec8 100644 --- a/src/app/clusters/ota-requestor/OTARequestorInterface.h +++ b/src/app/clusters/ota-requestor/OTARequestorInterface.h @@ -156,9 +156,6 @@ class OTARequestorInterface // Reset any relevant states virtual void Reset(void) = 0; - // Perform any clean up necessary - virtual void Shutdown(void) = 0; - // Handler for the AnnounceOTAProvider command virtual EmberAfStatus HandleAnnounceOTAProvider( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, diff --git a/src/platform/Linux/OTAImageProcessorImpl.cpp b/src/platform/Linux/OTAImageProcessorImpl.cpp index b9668ffc5e61c7..51a1a7bf5d650b 100644 --- a/src/platform/Linux/OTAImageProcessorImpl.cpp +++ b/src/platform/Linux/OTAImageProcessorImpl.cpp @@ -104,9 +104,12 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() } uint32_t currentVersion; + uint32_t targetVersion = requestor->GetTargetVersion(); ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion)); - if (currentVersion != requestor->GetTargetVersion()) + if (currentVersion != targetVersion) { + ChipLogError(SoftwareUpdate, "Current software version = %" PRIu32 ", expected software version = %" PRIu32, currentVersion, + targetVersion); return CHIP_ERROR_INCORRECT_STATE; } @@ -167,8 +170,9 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) rename(imageProcessor->mImageFile, kImageExecPath); chmod(kImageExecPath, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - // Shutdown the stack and expect to boot into the new image once shutdown is complete - requestor->Shutdown(); + // Shutdown the stack and expect to boot into the new image once the event loop is stopped + DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) { DeviceLayer::PlatformMgr().HandleServerShuttingDown(); }); + DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) { DeviceLayer::PlatformMgr().StopEventLoopTask(); }); } void OTAImageProcessorImpl::HandleAbort(intptr_t context)