diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 242dfb1ea08824..9e0f6ef02c2c68 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -2054,12 +2054,12 @@ bool InteractionModelEngine::HasSubscriptionsToResume() #endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS -void InteractionModelEngine::DecrementNumSubscriptionToResume() +void InteractionModelEngine::DecrementNumSubscriptionsToResume() { VerifyOrReturn(mNumOfSubscriptionToResume > 0); #if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION VerifyOrDie(mICDManager); -#endif // CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#endif // CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION mNumOfSubscriptionToResume--; diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index 0916237f5b20b1..b18745e7c4101b 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -328,7 +328,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, bool SubjectHasPersistedSubscription(FabricIndex aFabricIndex, NodeId subjectID) override; #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS - void DecrementNumSubscriptionToResume(); + void DecrementNumSubscriptionsToResume(); #endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS #if CONFIG_BUILD_FOR_HOST_UNIT_TEST diff --git a/src/app/SubscriptionResumptionSessionEstablisher.cpp b/src/app/SubscriptionResumptionSessionEstablisher.cpp index 393ca3d4c6aae5..8eaef424230725 100644 --- a/src/app/SubscriptionResumptionSessionEstablisher.cpp +++ b/src/app/SubscriptionResumptionSessionEstablisher.cpp @@ -92,7 +92,7 @@ void SubscriptionResumptionSessionEstablisher::HandleDeviceConnected(void * cont InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); // Decrement the number of subscriptions to resume - imEngine->DecrementNumSubscriptionToResume(); + imEngine->DecrementNumSubscriptionsToResume(); if (!imEngine->EnsureResourceForSubscription(subscriptionInfo.mFabricIndex, subscriptionInfo.mAttributePaths.AllocatedSize(), subscriptionInfo.mEventPaths.AllocatedSize())) @@ -130,7 +130,7 @@ void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(voi error.Format()); // Decrement the number of subscriptions to resume - imEngine->DecrementNumSubscriptionToResume(); + imEngine->DecrementNumSubscriptionsToResume(); auto * subscriptionResumptionStorage = imEngine->GetSubscriptionResumptionStorage(); if (!subscriptionResumptionStorage) diff --git a/src/app/icd/server/BUILD.gn b/src/app/icd/server/BUILD.gn index 45cc4a845c8965..a6c5096dde7d0c 100644 --- a/src/app/icd/server/BUILD.gn +++ b/src/app/icd/server/BUILD.gn @@ -24,7 +24,7 @@ buildconfig_header("icd-server-buildconfig") { if (chip_enable_icd_lit || chip_enable_icd_checkin || chip_enable_icd_user_active_mode_trigger) { - assert(chip_enable_icd_lit) + assert(chip_enable_icd_server) } if (chip_enable_icd_lit) { diff --git a/src/app/icd/server/ICDManager.cpp b/src/app/icd/server/ICDManager.cpp index d77de97ebe053b..4b026bd76a7930 100644 --- a/src/app/icd/server/ICDManager.cpp +++ b/src/app/icd/server/ICDManager.cpp @@ -108,7 +108,7 @@ void ICDManager::Shutdown() #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION mIsBootUpResumeSubscriptionExecuted = false; -#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION #endif // CHIP_CONFIG_ENABLE_ICD_CIP } @@ -208,7 +208,7 @@ void ICDManager::SendCheckInMsgs() #endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST } -bool ICDManager::CheckInMessagesWouldBeSent(const std::function shouldCheckInMsgsBeSentFunction &) +bool ICDManager::CheckInMessagesWouldBeSent(const std::function & shouldCheckInMsgsBeSentFunction) { VerifyOrReturnValue(shouldCheckInMsgsBeSentFunction, false); @@ -250,18 +250,18 @@ bool ICDManager::CheckInMessagesWouldBeSent(const std::function verifier = + std::function function = std::bind(&ICDManager::ShouldCheckInMsgsBeSentAtActiveModeFunction, this, std::placeholders::_1, std::placeholders::_2); #endif // CHIP_CONFIG_ENABLE_ICD_CIP @@ -398,7 +399,7 @@ void ICDManager::UpdateOperationState(OperationalState state) // unless the device would need to send Check-In messages if (ICDConfigurationData::GetInstance().GetActiveModeDuration() > kZero #if CHIP_CONFIG_ENABLE_ICD_CIP - || CheckInMessagesWouldBeSent(verifier) + || CheckInMessagesWouldBeSent(function) #endif // CHIP_CONFIG_ENABLE_ICD_CIP ) { diff --git a/src/app/icd/server/ICDManager.h b/src/app/icd/server/ICDManager.h index eb33d22a50a778..058285802eb309 100644 --- a/src/app/icd/server/ICDManager.h +++ b/src/app/icd/server/ICDManager.h @@ -135,9 +135,9 @@ class ICDManager : public ICDListener /** * @brief Trigger the ICDManager to send Check-In message if necessary * - * @param[in] algo Verifier function to use to determine if we need to send check-in messages + * @param[in] function to use to determine if we need to send check-in messages */ - void TriggerCheckInMessages(const std::function & verifier); + void TriggerCheckInMessages(const std::function & function); #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION /** @@ -151,7 +151,9 @@ class ICDManager : public ICDListener #if CONFIG_BUILD_FOR_HOST_UNIT_TEST void SetTestFeatureMapValue(uint32_t featureMap) { mFeatureMap = featureMap; }; +#if !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS bool GetIsBootUpResumeSubscriptionExecuted() { return mIsBootUpResumeSubscriptionExecuted; }; +#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS #endif // Implementation of ICDListener functions. @@ -201,7 +203,7 @@ class ICDManager : public ICDListener * @return false None of the registration would require a Check-In message either because there are no registration or * because they all have associated subscriptions. */ - bool CheckInMessagesWouldBeSent(std::function function); + bool CheckInMessagesWouldBeSent(const std::function & function); #endif // CHIP_CONFIG_ENABLE_ICD_CIP KeepActiveFlags mKeepActiveFlags{ 0 }; @@ -214,7 +216,7 @@ class ICDManager : public ICDListener #if CHIP_CONFIG_ENABLE_ICD_CIP #if !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS bool mIsBootUpResumeSubscriptionExecuted = false; -#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS PersistentStorageDelegate * mStorage = nullptr; FabricTable * mFabricTable = nullptr; Messaging::ExchangeManager * mExchangeManager = nullptr; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 0505b5df2b3968..643be723961575 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -449,9 +449,9 @@ void Server::OnPlatformEvent(const DeviceLayer::ChipDeviceEvent & event) // We trigger Check-In messages before resuming subscriptions to avoid doing both. if (!mFailSafeContext.IsFailSafeArmed()) { - std::function verifier = - std::bind(&Server::CheckInWouldBeSentAtBootVerifier, this, std::placeholders::_1, std::placeholders::_2); - mICDManager.TriggerCheckInMessages(verifier); + std::function function = + std::bind(&Server::ShouldCheckInMsgsBeSentAtBootFunction, this, std::placeholders::_1, std::placeholders::_2); + mICDManager.TriggerCheckInMessages(function); } #endif // CHIP_CONFIG_ENABLE_ICD_SERVER && CHIP_CONFIG_ENABLE_ICD_CIP #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 83b0a65b18daf1..8f6fcd5abecc66 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -372,14 +372,14 @@ class Server #if CHIP_CONFIG_ENABLE_ICD_CIP /** - * @brief Verifier to determine if a Check-In message would be sent at Boot up + * @brief Function to determine if a Check-In message would be sent at Boot up * * @param aFabricIndex client fabric index * @param subjectID client subject ID * @return true Check-In message would be sent on boot up. * @return false Device has a persisted subscription with the client. See CHIP_CONFIG_PERSIST_SUBSCRIPTIONS. */ - bool CheckInWouldBeSentAtBootVerifier(FabricIndex aFabricIndex, NodeId subjectID); + bool ShouldCheckInMsgsBeSentAtBootFunction(FabricIndex aFabricIndex, NodeId subjectID); #endif // CHIP_CONFIG_ENABLE_ICD_CIP #endif // CHIP_CONFIG_ENABLE_ICD_SERVER diff --git a/src/app/tests/TestInteractionModelEngine.cpp b/src/app/tests/TestInteractionModelEngine.cpp index 370117032c424e..09f713f170c96e 100644 --- a/src/app/tests/TestInteractionModelEngine.cpp +++ b/src/app/tests/TestInteractionModelEngine.cpp @@ -84,7 +84,7 @@ class TestInteractionModelEngine static void TestSubjectHasActiveSubscriptionMultipleSubsSingleEntry(nlTestSuite * apSuite, void * apContext); static void TestSubjectHasActiveSubscriptionMultipleSubsMultipleEntries(nlTestSuite * apSuite, void * apContext); static void TestSubjectHasActiveSubscriptionSubWithCAT(nlTestSuite * apSuite, void * apContext); - static void TestDecrementNumSubscriptionToResume(nlTestSuite * apSuite, void * apContext); + static void TestDecrementNumSubscriptionsToResume(nlTestSuite * apSuite, void * apContext); }; int TestInteractionModelEngine::GetAttributePathListLength(SingleLinkedListNode * apAttributePathParamsList) @@ -683,9 +683,8 @@ void TestInteractionModelEngine::TestSubscriptionResumptionTimer(nlTestSuite * a } #endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION -#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS -void TestInteractionModelEngine::TestDecrementNumSubscriptionToResume(nlTestSuite * apSuite, void * apContext) +void TestInteractionModelEngine::TestDecrementNumSubscriptionsToResume(nlTestSuite * apSuite, void * apContext) { TestContext & ctx = *static_cast(apContext); CHIP_ERROR err = CHIP_NO_ERROR; @@ -696,7 +695,7 @@ void TestInteractionModelEngine::TestDecrementNumSubscriptionToResume(nlTestSuit err = engine->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable(), app::reporting::GetDefaultReportScheduler()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION ICDManager manager; engine->SetICDManager(&manager); #endif // CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION @@ -704,43 +703,44 @@ void TestInteractionModelEngine::TestDecrementNumSubscriptionToResume(nlTestSuit // Set number of subs engine->mNumOfSubscriptionToResume = kNumberOfSubsToResume; -#if CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION // Verify mIsBootUpResumeSubscriptionExecuted has not been set NL_TEST_ASSERT(apSuite, !manager.GetIsBootUpResumeSubscriptionExecuted()); #endif // CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION // Decrease number of subs by 1 numberOfSubsRemaining--; - engine->DecrementNumSubscriptionToResume(); + engine->DecrementNumSubscriptionsToResume(); NL_TEST_ASSERT_EQUALS(apSuite, numberOfSubsRemaining, engine->mNumOfSubscriptionToResume); // Decrease to 0 subs remaining while (numberOfSubsRemaining > 0) { -#if CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION // Verify mIsBootUpResumeSubscriptionExecuted has not been set NL_TEST_ASSERT(apSuite, !manager.GetIsBootUpResumeSubscriptionExecuted()); #endif // CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION numberOfSubsRemaining--; - engine->DecrementNumSubscriptionToResume(); + engine->DecrementNumSubscriptionsToResume(); NL_TEST_ASSERT_EQUALS(apSuite, numberOfSubsRemaining, engine->mNumOfSubscriptionToResume); } -#if CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION // Verify mIsBootUpResumeSubscriptionExecuted has been set NL_TEST_ASSERT(apSuite, manager.GetIsBootUpResumeSubscriptionExecuted()); #endif // CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION // Make sure we don't rollover / go negative - engine->DecrementNumSubscriptionToResume(); + engine->DecrementNumSubscriptionsToResume(); NL_TEST_ASSERT_EQUALS(apSuite, numberOfSubsRemaining, engine->mNumOfSubscriptionToResume); // Clean up -#if CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION +#if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION engine->SetICDManager(nullptr); #endif // CHIP_CONFIG_ENABLE_ICD_CIP && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION } +#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS } // namespace app } // namespace chip @@ -754,6 +754,7 @@ const nlTest sTests[] = NL_TEST_DEF("TestRemoveDuplicateConcreteAttribute", chip::app::TestInteractionModelEngine::TestRemoveDuplicateConcreteAttribute), #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS NL_TEST_DEF("TestSubjectHasPersistedSubscription", chip::app::TestInteractionModelEngine::TestSubjectHasPersistedSubscription), + NL_TEST_DEF("TestDecrementNumSubscriptionsToResume", chip::app::TestInteractionModelEngine::TestDecrementNumSubscriptionsToResume), #if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION NL_TEST_DEF("TestSubscriptionResumptionTimer", chip::app::TestInteractionModelEngine::TestSubscriptionResumptionTimer), #endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION @@ -763,7 +764,6 @@ const nlTest sTests[] = NL_TEST_DEF("TestSubjectHasActiveSubscriptionMultipleSubsSingleEntry", chip::app::TestInteractionModelEngine::TestSubjectHasActiveSubscriptionMultipleSubsSingleEntry), NL_TEST_DEF("TestSubjectHasActiveSubscriptionMultipleSubsMultipleEntries", chip::app::TestInteractionModelEngine::TestSubjectHasActiveSubscriptionMultipleSubsMultipleEntries), NL_TEST_DEF("TestSubjectHasActiveSubscriptionSubWithCAT", chip::app::TestInteractionModelEngine::TestSubjectHasActiveSubscriptionSubWithCAT), - NL_TEST_DEF("TestDecrementNumSubscriptionToResume", chip::app::TestInteractionModelEngine::TestDecrementNumSubscriptionToResume), NL_TEST_SENTINEL() }; // clang-format on