Skip to content

Commit 81d7774

Browse files
Rename verifier function
1 parent 52939ca commit 81d7774

File tree

4 files changed

+32
-42
lines changed

4 files changed

+32
-42
lines changed

src/app/icd/server/ICDManager.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void ICDManager::SendCheckInMsgs()
178178
continue;
179179
}
180180

181-
if (!CheckInWouldBeSentAtActiveModeVerifier(entry.fabricIndex, entry.monitoredSubject))
181+
if (!ShouldCheckInMsgsBeSentAtActiveModeFunction(entry.fabricIndex, entry.monitoredSubject))
182182
{
183183
continue;
184184
}
@@ -208,9 +208,9 @@ void ICDManager::SendCheckInMsgs()
208208
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
209209
}
210210

211-
bool ICDManager::CheckInMessagesWouldBeSent(std::function<RegistrationVerificationFunction> RegistrationVerifier)
211+
bool ICDManager::CheckInMessagesWouldBeSent(const std::function<ShouldCheckInMsgsBeSentFunction> shouldCheckInMsgsBeSentFunction &)
212212
{
213-
VerifyOrReturnValue(RegistrationVerifier, false);
213+
VerifyOrReturnValue(shouldCheckInMsgsBeSentFunction, false);
214214

215215
for (const auto & fabricInfo : *mFabricTable)
216216
{
@@ -240,7 +240,7 @@ bool ICDManager::CheckInMessagesWouldBeSent(std::function<RegistrationVerificati
240240
}
241241

242242
// At least one registration would require a Check-In message
243-
VerifyOrReturnValue(!RegistrationVerifier(entry.fabricIndex, entry.monitoredSubject), true);
243+
VerifyOrReturnValue(!shouldCheckInMsgsBeSentFunction(entry.fabricIndex, entry.monitoredSubject), true);
244244
}
245245
}
246246

@@ -249,7 +249,7 @@ bool ICDManager::CheckInMessagesWouldBeSent(std::function<RegistrationVerificati
249249
}
250250

251251
/**
252-
* CheckInWouldBeSentAtActiveModeVerifier is used to determine if a Check-In message is required for a given registration.
252+
* ShouldCheckInMsgsBeSentAtActiveModeFunction is used to determine if a Check-In message is required for a given registration.
253253
* Due to how the ICD Check-In use-case interacts with the persistent subscription and subscription timeout resumption,
254254
* having a single implementation of the function renders the implematention very difficult to understand and maintain.
255255
* Because of this, each valid feature combination has its own implementation of the verifier.
@@ -266,7 +266,7 @@ bool ICDManager::CheckInMessagesWouldBeSent(std::function<RegistrationVerificati
266266
* @return true Returns true if the fabricIndex and subjectId combination does not have an active or a persisted subscription.
267267
* @return false Returns false if the fabricIndex and subjectId combination has an active or persisted subscription.
268268
*/
269-
bool ICDManager::CheckInWouldBeSentAtActiveModeVerifier(FabricIndex aFabricIndex, NodeId subjectID)
269+
bool ICDManager::ShouldCheckInMsgsBeSentAtActiveModeFunction(FabricIndex aFabricIndex, NodeId subjectID)
270270
{
271271
return !(mSubInfoProvider->SubjectHasActiveSubscription(aFabricIndex, subjectID) ||
272272
mSubInfoProvider->SubjectHasPersistedSubscription(aFabricIndex, subjectID));
@@ -291,7 +291,7 @@ bool ICDManager::CheckInWouldBeSentAtActiveModeVerifier(FabricIndex aFabricIndex
291291
* If the boot up susbscription has not been completed,
292292
* if the fabricIndex and subjectId combination has a persisted subscription.
293293
*/
294-
bool ICDManager::CheckInWouldBeSentAtActiveModeVerifier(FabricIndex aFabricIndex, NodeId subjectID)
294+
bool ICDManager::ShouldCheckInMsgsBeSentAtActiveModeFunction(FabricIndex aFabricIndex, NodeId subjectID)
295295
{
296296
bool wouldSendCheckIn = !(mSubInfoProvider->SubjectHasActiveSubscription(aFabricIndex, subjectID));
297297

@@ -314,13 +314,13 @@ bool ICDManager::CheckInWouldBeSentAtActiveModeVerifier(FabricIndex aFabricIndex
314314
* @return true Returns true if the fabricIndex and subjectId combination does not have an active subscription.
315315
* @return false Returns false if the fabricIndex and subjectId combination has an active subscription.
316316
*/
317-
bool ICDManager::CheckInWouldBeSentAtActiveModeVerifier(FabricIndex aFabricIndex, NodeId subjectID)
317+
bool ICDManager::ShouldCheckInMsgsBeSentAtActiveModeFunction(FabricIndex aFabricIndex, NodeId subjectID)
318318
{
319319
return !(mSubInfoProvider->SubjectHasActiveSubscription(aFabricIndex, subjectID));
320320
}
321321
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
322322

323-
void ICDManager::TriggerCheckInMessages(const std::function<RegistrationVerificationFunction> & verifier)
323+
void ICDManager::TriggerCheckInMessages(const std::function<ShouldCheckInMsgsBeSentFunction> & verifier)
324324
{
325325
VerifyOrReturn(SupportsFeature(Feature::kCheckInProtocolSupport));
326326

@@ -390,8 +390,8 @@ void ICDManager::UpdateOperationState(OperationalState state)
390390
mOperationalState = OperationalState::IdleMode;
391391

392392
#if CHIP_CONFIG_ENABLE_ICD_CIP
393-
std::function<RegistrationVerificationFunction> verifier =
394-
std::bind(&ICDManager::CheckInWouldBeSentAtActiveModeVerifier, this, std::placeholders::_1, std::placeholders::_2);
393+
std::function<ShouldCheckInMsgsBeSentFunction> verifier =
394+
std::bind(&ICDManager::ShouldCheckInMsgsBeSentAtActiveModeFunction, this, std::placeholders::_1, std::placeholders::_2);
395395
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
396396

397397
// When the active mode interval is 0, we stay in idleMode until a notification brings the icd into active mode

src/app/icd/server/ICDManager.h

+5-15
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ICDManager : public ICDListener
8989
* false No Check-In messages would be sent
9090
*/
9191

92-
using RegistrationVerificationFunction = bool(FabricIndex aFabricIndex, NodeId subjectID);
92+
using ShouldCheckInMsgsBeSentFunction = bool(FabricIndex aFabricIndex, NodeId subjectID);
9393

9494
ICDManager() {}
9595
void Init(PersistentStorageDelegate * storage, FabricTable * fabricTable, Crypto::SymmetricKeystore * symmetricKeyStore,
@@ -137,7 +137,7 @@ class ICDManager : public ICDListener
137137
*
138138
* @param[in] algo Verifier function to use to determine if we need to send check-in messages
139139
*/
140-
void TriggerCheckInMessages(const std::function<RegistrationVerificationFunction> & verifier);
140+
void TriggerCheckInMessages(const std::function<ShouldCheckInMsgsBeSentFunction> & verifier);
141141

142142
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
143143
/**
@@ -190,28 +190,18 @@ class ICDManager : public ICDListener
190190

191191
private:
192192
#if CHIP_CONFIG_ENABLE_ICD_CIP
193-
/**
194-
* @brief Verifier to determine if a Check-In message would be sent on transition to ActiveMode
195-
*
196-
* @param aFabricIndex client fabric index
197-
* @param subjectID client subject ID
198-
* @return true Check-In message would be sent on transition to ActiveMode.
199-
* @return false Device has an active subscription with the subjectID.
200-
* Device is trying to resume inactive subscriptions with the client. See CHIP_CONFIG_PERSIST_SUBSCRIPTIONS and
201-
* CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
202-
*/
203-
bool CheckInWouldBeSentAtActiveModeVerifier(FabricIndex aFabricIndex, NodeId subjectID);
193+
bool ShouldCheckInMsgsBeSentAtActiveModeFunction(FabricIndex aFabricIndex, NodeId subjectID);
204194

205195
/**
206196
* @brief Function checks if at least one client registration would require a Check-In message
207197
*
208-
* @param[in] RegistrationVerifier function to use to determine if a Check-In message would be sent for a given registration
198+
* @param[in] function function to use to determine if a Check-In message would be sent for a given registration
209199
*
210200
* @return true At least one registration would require an Check-In message if we were entering ActiveMode.
211201
* @return false None of the registration would require a Check-In message either because there are no registration or
212202
* because they all have associated subscriptions.
213203
*/
214-
bool CheckInMessagesWouldBeSent(std::function<RegistrationVerificationFunction> RegistrationVerifier);
204+
bool CheckInMessagesWouldBeSent(std::function<ShouldCheckInMsgsBeSentFunction> function);
215205
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
216206

217207
KeepActiveFlags mKeepActiveFlags{ 0 };

src/app/server/Server.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void Server::OnPlatformEvent(const DeviceLayer::ChipDeviceEvent & event)
449449
// We trigger Check-In messages before resuming subscriptions to avoid doing both.
450450
if (!mFailSafeContext.IsFailSafeArmed())
451451
{
452-
std::function<chip::app::ICDManager::RegistrationVerificationFunction> verifier =
452+
std::function<chip::app::ICDManager::ShouldCheckInMsgsBeSentFunction> verifier =
453453
std::bind(&Server::CheckInWouldBeSentAtBootVerifier, this, std::placeholders::_1, std::placeholders::_2);
454454
mICDManager.TriggerCheckInMessages(verifier);
455455
}
@@ -525,7 +525,7 @@ void Server::RejoinExistingMulticastGroups()
525525
}
526526

527527
#if CHIP_CONFIG_ENABLE_ICD_CIP
528-
bool Server::CheckInWouldBeSentAtBootVerifier(FabricIndex aFabricIndex, NodeId subjectID)
528+
bool Server::ShouldCheckInMsgsBeSentAtBootFunction(FabricIndex aFabricIndex, NodeId subjectID)
529529
{
530530
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
531531
// If at least one registration has a persisted entry, do not send Check-In message.

src/app/tests/TestICDManager.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -624,72 +624,72 @@ class TestICDManager
624624

625625
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
626626
#if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
627-
static void TestCheckInWouldBeSentAtActiveModeVerifier(nlTestSuite * aSuite, void * aContext)
627+
static void TestShouldCheckInMsgsBeSentAtActiveModeFunction(nlTestSuite * aSuite, void * aContext)
628628
{
629629
TestContext * ctx = static_cast<TestContext *>(aContext);
630630

631631
// Test 1 - Has no ActiveSubscription & no persisted subscription
632632
ctx->mSubInfoProvider.SetHasActiveSubscription(false);
633633
ctx->mSubInfoProvider.SetHasPersistedSubscription(false);
634-
NL_TEST_ASSERT(aSuite, ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11));
634+
NL_TEST_ASSERT(aSuite, ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11));
635635

636636
// Test 2 - Has no active subscription & a persisted subscription
637637
ctx->mSubInfoProvider.SetHasActiveSubscription(false);
638638
ctx->mSubInfoProvider.SetHasPersistedSubscription(true);
639-
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11)));
639+
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11)));
640640

641641
// Test 3 - Has an active subscription & a persisted subscription
642642
ctx->mSubInfoProvider.SetHasActiveSubscription(true);
643643
ctx->mSubInfoProvider.SetHasPersistedSubscription(true);
644-
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11)));
644+
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11)));
645645
}
646646
#else
647-
static void TestCheckInWouldBeSentAtActiveModeVerifier(nlTestSuite * aSuite, void * aContext)
647+
static void TestShouldCheckInMsgsBeSentAtActiveModeFunction(nlTestSuite * aSuite, void * aContext)
648648
{
649649
TestContext * ctx = static_cast<TestContext *>(aContext);
650650

651651
// Test 1 - Has no active subscription and no persisted subscription at boot up
652652
ctx->mSubInfoProvider.SetHasActiveSubscription(false);
653653
ctx->mSubInfoProvider.SetHasPersistedSubscription(false);
654654
ctx->mICDManager.mIsBootUpResumeSubscriptionExecuted = false;
655-
NL_TEST_ASSERT(aSuite, ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11));
655+
NL_TEST_ASSERT(aSuite, ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11));
656656

657657
// Test 2 - Has no active subscription and a persisted subscription at boot up
658658
ctx->mSubInfoProvider.SetHasActiveSubscription(false);
659659
ctx->mSubInfoProvider.SetHasPersistedSubscription(true);
660660
ctx->mICDManager.mIsBootUpResumeSubscriptionExecuted = false;
661-
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11)));
661+
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11)));
662662

663663
// Test 3 - Has an active subscription and a persisted subscription during normal operations
664664
ctx->mSubInfoProvider.SetHasActiveSubscription(true);
665665
ctx->mSubInfoProvider.SetHasPersistedSubscription(true);
666666
ctx->mICDManager.mIsBootUpResumeSubscriptionExecuted = true;
667-
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11)));
667+
NL_TEST_ASSERT(aSuite, !(ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11)));
668668

669669
// Test 4 - Has no active subscription and a persisted subscription during normal operations
670670
ctx->mSubInfoProvider.SetHasActiveSubscription(false);
671671
ctx->mSubInfoProvider.SetHasPersistedSubscription(true);
672672
ctx->mICDManager.mIsBootUpResumeSubscriptionExecuted = true;
673-
NL_TEST_ASSERT(aSuite, ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11));
673+
NL_TEST_ASSERT(aSuite, ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11));
674674
}
675675
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
676676
#else
677-
static void TestCheckInWouldBeSentAtActiveModeVerifier(nlTestSuite * aSuite, void * aContext)
677+
static void TestShouldCheckInMsgsBeSentAtActiveModeFunction(nlTestSuite * aSuite, void * aContext)
678678
{
679679
TestContext * ctx = static_cast<TestContext *>(aContext);
680680

681681
// Test 1 - Has an active subscription
682682
ctx->mSubInfoProvider.SetHasActiveSubscription(true);
683683
NL_TEST_ASSERT(aSuite,
684-
ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11) == false);
684+
ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11) == false);
685685

686686
// Test 2 - Has no active subscription
687687
ctx->mSubInfoProvider.SetHasActiveSubscription(false);
688-
NL_TEST_ASSERT(aSuite, ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11));
688+
NL_TEST_ASSERT(aSuite, ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11));
689689

690690
// Test 3 - Make sure that the persisted subscription has no impact
691691
ctx->mSubInfoProvider.SetHasPersistedSubscription(true);
692-
NL_TEST_ASSERT(aSuite, ctx->mICDManager.CheckInWouldBeSentAtActiveModeVerifier(kTestFabricIndex1, kClientNodeId11));
692+
NL_TEST_ASSERT(aSuite, ctx->mICDManager.ShouldCheckInMsgsBeSentAtActiveModeFunction(kTestFabricIndex1, kClientNodeId11));
693693
}
694694
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
695695
};
@@ -709,7 +709,7 @@ static const nlTest sTests[] = {
709709
NL_TEST_DEF("TestICDMRegisterUnregisterEvents", TestICDManager::TestICDMRegisterUnregisterEvents),
710710
NL_TEST_DEF("TestICDCounter", TestICDManager::TestICDCounter),
711711
NL_TEST_DEF("TestICDStayActive", TestICDManager::TestICDMStayActive),
712-
NL_TEST_DEF("TestCheckInWouldBeSentAtActiveModeVerifier", TestICDManager::TestCheckInWouldBeSentAtActiveModeVerifier),
712+
NL_TEST_DEF("TestShouldCheckInMsgsBeSentAtActiveModeFunction", TestICDManager::TestShouldCheckInMsgsBeSentAtActiveModeFunction),
713713
NL_TEST_SENTINEL(),
714714
};
715715

0 commit comments

Comments
 (0)