Skip to content

Commit

Permalink
[OTA] Set OTA Requestor server attributes in CHIP context (#16041)
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored and pull[bot] committed May 13, 2022
1 parent b3c25e0 commit 3967379
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OTA Requestor logic is contained in this class.
*/

#include <app/clusters/ota-requestor/ota-requestor-server.h>
#include <lib/core/CHIPEncoding.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/OTAImageProcessor.h>
Expand Down Expand Up @@ -101,6 +102,17 @@ OTARequestorInterface * GetRequestorInstance()
return globalOTARequestorInstance;
}

void OTARequestor::InitState(intptr_t context)
{
OTARequestor * requestorCore = reinterpret_cast<OTARequestor *>(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);
Expand Down
14 changes: 9 additions & 5 deletions src/app/clusters/ota-requestor/OTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#pragma once

#include <app/CASESessionManager.h>
#include <app/clusters/ota-requestor/ota-requestor-server.h>
#include <app/server/Server.h>
#include <protocols/bdx/BdxMessages.h>

Expand Down Expand Up @@ -99,6 +98,8 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe
app::Clusters::OtaSoftwareUpdateRequestor::OTAChangeReasonEnum reason) override;
void OnUpdateProgressChanged(app::DataModel::Nullable<uint8_t> 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
Expand All @@ -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<intptr_t>(this));

return chip::DeviceLayer::PlatformMgrImpl().AddEventHandler(OnCommissioningCompleteRequestor,
reinterpret_cast<intptr_t>(this));
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 3967379

Please sign in to comment.