Skip to content

Commit

Permalink
- Consolidate code for resetting mInvalidSessionRetryCount
Browse files Browse the repository at this point in the history
- scripts/helpers/restyle-diff.sh
  • Loading branch information
isiu-apple committed May 24, 2022
1 parent 6f3f01f commit a47b62b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ IdleStateReason DefaultOTARequestor::MapErrorToIdleStateReason(CHIP_ERROR error)

void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAChangeReasonEnum reason, CHIP_ERROR error)
{
bool handleIdleStateEnter = true;
bool handleIdleStateEnter = true;
IdleStateReason idleStateReason = IdleStateReason::kUnknown;

// Set server UpdateState attribute
Expand All @@ -673,7 +673,7 @@ void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAC

if ((newState == OTAUpdateStateEnum::kIdle) && (mCurrentUpdateState != OTAUpdateStateEnum::kIdle))
{
idleStateReason = MapErrorToIdleStateReason(error);
idleStateReason = MapErrorToIdleStateReason(error);
handleIdleStateEnter = true;
}
else if ((mCurrentUpdateState == OTAUpdateStateEnum::kIdle) && (newState != OTAUpdateStateEnum::kIdle))
Expand All @@ -684,7 +684,7 @@ void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAC
// Update the new state before handling the state transition
mCurrentUpdateState = newState;

if( handleIdleStateEnter )
if (handleIdleStateEnter)
{
mOtaRequestorDriver->HandleIdleStateEnter(idleStateReason);
}
Expand Down
15 changes: 9 additions & 6 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ DefaultOTARequestorDriver * ToDriver(void * context)

void DefaultOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImageProcessorInterface * processor)
{
mRequestor = requestor;
mImageProcessor = processor;
mProviderRetryCount = 0;
mRequestor = requestor;
mImageProcessor = processor;
mProviderRetryCount = 0;
mInvalidSessionRetryCount = 0;

if (mImageProcessor->IsFirstImageRun())
Expand Down Expand Up @@ -129,20 +129,23 @@ void DefaultOTARequestorDriver::HandleIdleStateExit()

void DefaultOTARequestorDriver::HandleIdleStateEnter(IdleStateReason reason)
{
if (reason != IdleStateReason::kInvalidSession)
{
mInvalidSessionRetryCount = 0;
}

switch (reason)
{
case IdleStateReason::kUnknown:
mInvalidSessionRetryCount = 0;
ChipLogProgress(SoftwareUpdate, "Unknown idle state reason so set the periodic timer for a next attempt");
StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer);
break;
case IdleStateReason::kIdle:
mInvalidSessionRetryCount = 0;
// There is no current OTA update in progress so start the periodic query timer
StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer);
break;
case IdleStateReason::kInvalidSession:
if(mInvalidSessionRetryCount < kMaxInvalidSessionRetries)
if (mInvalidSessionRetryCount < kMaxInvalidSessionRetries)
{
// An invalid session is detected which may be temporary so try to query the same provider again
SendQueryImage();
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
// Maximum number of times to retry a BUSY OTA provider before moving to the next available one
static constexpr uint8_t kMaxBusyProviderRetryCount = 3;
// Track retry count for the current provider
uint8_t mProviderRetryCount;
uint8_t mProviderRetryCount;
// Track query image retry count on invalid session error
uint8_t mInvalidSessionRetryCount;
};
Expand Down

0 comments on commit a47b62b

Please sign in to comment.