@@ -336,30 +336,20 @@ bool InteractionModelEngine::SubjectHasActiveSubscription(FabricIndex aFabricInd
336
336
{
337
337
bool isActive = false ;
338
338
mReadHandlers .ForEachActiveObject ([aFabricIndex, subjectID, &isActive](ReadHandler * handler) {
339
- if (!handler->IsType (ReadHandler::InteractionType::Subscribe))
340
- {
341
- return Loop::Continue;
342
- }
339
+ VerifyOrReturnValue (handler->IsType (ReadHandler::InteractionType::Subscribe), Loop::Continue);
343
340
344
341
Access::SubjectDescriptor subject = handler->GetSubjectDescriptor ();
345
- if (subject.fabricIndex != aFabricIndex)
346
- {
347
- return Loop::Continue;
348
- }
342
+ VerifyOrReturnValue (subject.fabricIndex == aFabricIndex, Loop::Continue);
349
343
350
344
if (subject.authMode == Access::AuthMode::kCase )
351
345
{
352
346
if (subject.cats .CheckSubjectAgainstCATs (subjectID) || subjectID == subject.subject )
353
347
{
354
348
isActive = handler->IsActiveSubscription ();
355
349
356
- // Exit loop only if isActive is set to true
357
- // Otherwise keep looking for another subscription that could
358
- // match the subject
359
- if (isActive)
360
- {
361
- return Loop::Break;
362
- }
350
+ // Exit loop only if isActive is set to true.
351
+ // Otherwise keep looking for another subscription that could match the subject.
352
+ VerifyOrReturnValue (!isActive, Loop::Break);
363
353
}
364
354
}
365
355
@@ -371,8 +361,30 @@ bool InteractionModelEngine::SubjectHasActiveSubscription(FabricIndex aFabricInd
371
361
372
362
bool InteractionModelEngine::SubjectHasPersistedSubscription (FabricIndex aFabricIndex, NodeId subjectID)
373
363
{
374
- // TODO(#30281) : Implement persisted sub check and verify how persistent subscriptions affects this at ICDManager::Init
375
- return false ;
364
+ bool persistedSubMatches = false ;
365
+
366
+ #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
367
+ auto * iterator = mpSubscriptionResumptionStorage->IterateSubscriptions ();
368
+ // Verify that we were able to allocate an iterator. If not, we are probably currently trying to resubscribe to our persisted
369
+ // subscriptions. As such, we assume we have a persisted subscription and return true.
370
+ // If we don't have a persisted subscription for the given fabric index and subjectID, we will send a Check-In message next time
371
+ // we transition to ActiveMode.
372
+ VerifyOrReturnValue (iterator, true );
373
+
374
+ SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo;
375
+ while (iterator->Next (subscriptionInfo))
376
+ {
377
+ // TODO(#31873): Persistent subscription only stores the NodeID for now. We cannot check if the CAT matches
378
+ if (subscriptionInfo.mFabricIndex == aFabricIndex && subscriptionInfo.mNodeId == subjectID)
379
+ {
380
+ persistedSubMatches = true ;
381
+ break ;
382
+ }
383
+ }
384
+ iterator->Release ();
385
+ #endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
386
+
387
+ return persistedSubMatches;
376
388
}
377
389
378
390
void InteractionModelEngine::OnDone (CommandResponseSender & apResponderObj)
@@ -1917,22 +1929,22 @@ CHIP_ERROR InteractionModelEngine::ResumeSubscriptions()
1917
1929
// future improvements: https://github.com/project-chip/connectedhomeip/issues/25439
1918
1930
1919
1931
SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo;
1920
- auto * iterator = mpSubscriptionResumptionStorage->IterateSubscriptions ();
1921
- int subscriptionsToResume = 0 ;
1922
- uint16_t minInterval = 0 ;
1932
+ auto * iterator = mpSubscriptionResumptionStorage->IterateSubscriptions ();
1933
+ mNumOfSubscriptionsToResume = 0 ;
1934
+ uint16_t minInterval = 0 ;
1923
1935
while (iterator->Next (subscriptionInfo))
1924
1936
{
1925
- subscriptionsToResume ++;
1937
+ mNumOfSubscriptionsToResume ++;
1926
1938
minInterval = std::max (minInterval, subscriptionInfo.mMinInterval );
1927
1939
}
1928
1940
iterator->Release ();
1929
1941
1930
- if (subscriptionsToResume )
1942
+ if (mNumOfSubscriptionsToResume )
1931
1943
{
1932
1944
#if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
1933
1945
mSubscriptionResumptionScheduled = true ;
1934
1946
#endif
1935
- ChipLogProgress (InteractionModel, " Resuming %d subscriptions in %u seconds" , subscriptionsToResume , minInterval);
1947
+ ChipLogProgress (InteractionModel, " Resuming %d subscriptions in %u seconds" , mNumOfSubscriptionsToResume , minInterval);
1936
1948
ReturnErrorOnFailure (mpExchangeMgr->GetSessionManager ()->SystemLayer ()->StartTimer (System::Clock::Seconds16 (minInterval),
1937
1949
ResumeSubscriptionsTimerCallback, this ));
1938
1950
}
@@ -2054,5 +2066,24 @@ bool InteractionModelEngine::HasSubscriptionsToResume()
2054
2066
}
2055
2067
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
2056
2068
2069
+ #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
2070
+ void InteractionModelEngine::DecrementNumSubscriptionsToResume ()
2071
+ {
2072
+ VerifyOrReturn (mNumOfSubscriptionsToResume > 0 );
2073
+ #if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
2074
+ VerifyOrDie (mICDManager );
2075
+ #endif // CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
2076
+
2077
+ mNumOfSubscriptionsToResume --;
2078
+
2079
+ #if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
2080
+ if (!mNumOfSubscriptionsToResume )
2081
+ {
2082
+ mICDManager ->SetBootUpResumeSubscriptionExecuted ();
2083
+ }
2084
+ #endif // CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
2085
+ }
2086
+ #endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
2087
+
2057
2088
} // namespace app
2058
2089
} // namespace chip
0 commit comments