Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple committed Jul 22, 2023
1 parent d06f949 commit f915189
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
18 changes: 7 additions & 11 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ void InteractionModelEngine::OnDone(ReadHandler & apReadObj)
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
if (!mSubscriptionResumptionScheduled && HasSubscriptionsToResume())
{
mSubscriptionResumptionScheduled = true;
auto timeTillNextResubscriptionMs = ComputeTimeTillNextSubscriptionResumption();
mpExchangeMgr->GetSessionManager()->SystemLayer()->StartTimer(System::Clock::Seconds32(timeTillNextResubscriptionMs),
mSubscriptionResumptionScheduled = true;
auto timeTillNextResubscriptionSecs = ComputeTimeSecondsTillNextSubscriptionResumption();
mpExchangeMgr->GetSessionManager()->SystemLayer()->StartTimer(System::Clock::Seconds32(timeTillNextResubscriptionSecs),
ResumeSubscriptionsTimerCallback, this);
mNumSubscriptionResumptionRetries++;
}
Expand Down Expand Up @@ -1873,22 +1873,18 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap
}

#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
uint32_t InteractionModelEngine::ComputeTimeTillNextSubscriptionResumption()
uint32_t InteractionModelEngine::ComputeTimeSecondsTillNextSubscriptionResumption()
{
uint32_t waitTimeInSeconds = 0;

if (mNumSubscriptionResumptionRetries <= CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MAX_FIBONACCI_STEP_INDEX)
{
waitTimeInSeconds = CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MIN_RETRY_INTERVAL_SECS +
return CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MIN_RETRY_INTERVAL_SECS +
GetFibonacciForIndex(mNumSubscriptionResumptionRetries) *
CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_WAIT_TIME_MULTIPLIER_SECS;
CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_WAIT_TIME_MULTIPLIER_SECS;
}
else
{
waitTimeInSeconds = CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MAX_RETRY_INTERVAL_SECS;
return CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MAX_RETRY_INTERVAL_SECS;
}

return waitTimeInSeconds;
}

bool InteractionModelEngine::HasSubscriptionsToResume()
Expand Down
2 changes: 1 addition & 1 deletion src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,

#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
bool HasSubscriptionsToResume();
uint32_t ComputeTimeTillNextSubscriptionResumption();
uint32_t ComputeTimeSecondsTillNextSubscriptionResumption();
uint32_t mNumSubscriptionResumptionRetries = 0;
bool mSubscriptionResumptionScheduled = false;
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/app/tests/TestInteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void TestInteractionModelEngine::TestSubscriptionResumptionTimer(nlTestSuite * a

uint32_t timeTillNextResubscriptionMs;
InteractionModelEngine::GetInstance()->mNumSubscriptionResumptionRetries = 0;
timeTillNextResubscriptionMs = InteractionModelEngine::GetInstance()->ComputeTimeTillNextSubscriptionResumption();
timeTillNextResubscriptionMs = InteractionModelEngine::GetInstance()->ComputeTimeSecondsTillNextSubscriptionResumption();
NL_TEST_ASSERT(apSuite, timeTillNextResubscriptionMs == CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MIN_RETRY_INTERVAL_SECS);

uint32_t lastTimeTillNextResubscriptionMs = timeTillNextResubscriptionMs;
Expand All @@ -245,14 +245,14 @@ void TestInteractionModelEngine::TestSubscriptionResumptionTimer(nlTestSuite * a
CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MAX_FIBONACCI_STEP_INDEX;
InteractionModelEngine::GetInstance()->mNumSubscriptionResumptionRetries++)
{
timeTillNextResubscriptionMs = InteractionModelEngine::GetInstance()->ComputeTimeTillNextSubscriptionResumption();
timeTillNextResubscriptionMs = InteractionModelEngine::GetInstance()->ComputeTimeSecondsTillNextSubscriptionResumption();
NL_TEST_ASSERT(apSuite, timeTillNextResubscriptionMs >= lastTimeTillNextResubscriptionMs);
NL_TEST_ASSERT(apSuite, timeTillNextResubscriptionMs < CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MAX_RETRY_INTERVAL_SECS);
lastTimeTillNextResubscriptionMs = timeTillNextResubscriptionMs;
}

InteractionModelEngine::GetInstance()->mNumSubscriptionResumptionRetries = 2000;
timeTillNextResubscriptionMs = InteractionModelEngine::GetInstance()->ComputeTimeTillNextSubscriptionResumption();
timeTillNextResubscriptionMs = InteractionModelEngine::GetInstance()->ComputeTimeSecondsTillNextSubscriptionResumption();
NL_TEST_ASSERT(apSuite, timeTillNextResubscriptionMs == CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION_MAX_RETRY_INTERVAL_SECS);
}
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
Expand Down

0 comments on commit f915189

Please sign in to comment.