From 2250149cbdb03dd3e678bfbd9e7ab5483cde70de Mon Sep 17 00:00:00 2001 From: Carol Yang Date: Thu, 10 Mar 2022 09:23:27 -0800 Subject: [PATCH] [OTA] Set OTA Requestor server attributes in CHIP context (#16041) --- src/app/clusters/ota-requestor/OTARequestor.cpp | 12 ++++++++++++ src/app/clusters/ota-requestor/OTARequestor.h | 14 +++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index f45a1f1fdb8eb5..b1b91ff82932ba 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -20,6 +20,7 @@ * OTA Requestor logic is contained in this class. */ +#include #include #include #include @@ -101,6 +102,17 @@ OTARequestorInterface * GetRequestorInstance() return globalOTARequestorInstance; } +void OTARequestor::InitState(intptr_t context) +{ + OTARequestor * requestorCore = reinterpret_cast(context); + VerifyOrDie(requestorCore != nullptr); + + // This results in the initial periodic timer kicking off + requestorCore->RecordNewUpdateState(OTAUpdateStateEnum::kIdle, OTAChangeReasonEnum::kSuccess); + + OtaRequestorServerSetUpdateStateProgress(app::DataModel::NullNullable); +} + void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse::DecodableType & response) { LogQueryImageResponse(response); diff --git a/src/app/clusters/ota-requestor/OTARequestor.h b/src/app/clusters/ota-requestor/OTARequestor.h index 0706702f040644..537e51d1d7aa76 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.h +++ b/src/app/clusters/ota-requestor/OTARequestor.h @@ -23,7 +23,6 @@ #pragma once #include -#include #include #include @@ -99,6 +98,8 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe app::Clusters::OtaSoftwareUpdateRequestor::OTAChangeReasonEnum reason) override; void OnUpdateProgressChanged(app::DataModel::Nullable percent) override; + //////////// OTARequestor public APIs /////////////// + /** * Called to perform some initialization including: * - Set server instance used to get access to the system resources necessary to open CASE sessions and drive @@ -119,11 +120,9 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe mCurrentVersion = version; storage.LoadDefaultProviders(mDefaultOtaProviderList); - OtaRequestorServerSetUpdateState(mCurrentUpdateState); - OtaRequestorServerSetUpdateStateProgress(app::DataModel::NullNullable); - // This results in the initial periodic timer kicking off - RecordNewUpdateState(OTAUpdateStateEnum::kIdle, OTAChangeReasonEnum::kSuccess); + // Schedule the initializations that needs to be performed in the CHIP context + DeviceLayer::PlatformMgr().ScheduleWork(InitState, reinterpret_cast(this)); return chip::DeviceLayer::PlatformMgrImpl().AddEventHandler(OnCommissioningCompleteRequestor, reinterpret_cast(this)); @@ -200,6 +199,11 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe chip::BDXDownloader * mDownloader; }; + /** + * Callback to initialize states and server attributes in the CHIP context + */ + static void InitState(intptr_t context); + /** * Record the new update state by updating the corresponding server attribute and logging a StateTransition event */