Skip to content

Commit cbe4e31

Browse files
address comments
1 parent 6da3d6e commit cbe4e31

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

src/app/InteractionModelEngine.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1069,14 +1069,15 @@ void InteractionModelEngine::OnResponseTimeout(Messaging::ExchangeContext * ec)
10691069
}
10701070

10711071
#if CHIP_CONFIG_ENABLE_READ_CLIENT
1072-
void InteractionModelEngine::OnActiveModeNotification(ScopedNodeId aPeer)
1072+
void InteractionModelEngine::OnActiveModeNotification(ScopedNodeId aCheckInNode, ScopedNodeId aPeer)
10731073
{
10741074
for (ReadClient * pListItem = mpActiveReadClientList; pListItem != nullptr;)
10751075
{
10761076
auto pNextItem = pListItem->GetNextClient();
10771077
// It is possible that pListItem is destroyed by the app in OnActiveModeNotification.
10781078
// Get the next item before invoking `OnActiveModeNotification`.
1079-
if (ScopedNodeId(pListItem->GetPeerNodeId(), pListItem->GetFabricIndex()) == aPeer)
1079+
if (ScopedNodeId(pListItem->GetPeerNodeId(), pListItem->GetFabricIndex()) == aPeer &&
1080+
aCheckInNode == pListItem->GetLocalScopedNodeId())
10801081
{
10811082
pListItem->OnActiveModeNotification();
10821083
}

src/app/InteractionModelEngine.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,9 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
236236
/**
237237
* Activate the idle subscriptions.
238238
*
239-
* When subscribing to ICD and liveness timeout reached, the read client will move to `InactiveICDSubscription` state and
240-
* resubscription can be triggered via OnActiveModeNotification().
239+
* See ReadClient::OnActiveModeNotification
241240
*/
242-
void OnActiveModeNotification(ScopedNodeId aPeer);
241+
void OnActiveModeNotification(ScopedNodeId aCheckInNode, ScopedNodeId aPeer);
243242

244243
/**
245244
* Used to notify when a peer becomes LIT ICD or vice versa.

src/app/ReadClient.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,12 @@ CHIP_ERROR ReadClient::GenerateDataVersionFilterList(DataVersionFilterIBs::Build
484484

485485
void ReadClient::OnActiveModeNotification()
486486
{
487-
// Note: this API only works when issuing subscription via SendAutoResubscribeRequest.
488487
VerifyOrDie(mpImEngine->InActiveReadClientList(this));
488+
489+
// Note: this API only works when issuing subscription via SendAutoResubscribeRequest, when SendAutoResubscribeRequest is called,
490+
// either mEventPathParamsListSize or mAttributePathParamsListSize is not 0.
491+
VerifyOrDie(mReadPrepareParams.mEventPathParamsListSize != 0 || mReadPrepareParams.mAttributePathParamsListSize != 0)
492+
489493
// When we reach here, the subscription definitely exceeded the liveness timeout. Just continue the unfinished resubscription
490494
// logic in `OnLivenessTimeoutCallback`.
491495
if (IsInactiveICDSubscription())

src/app/ReadClient.h

+15-3
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,16 @@ class ReadClient : public Messaging::ExchangeDelegate
351351
* Re-activate an inactive subscription.
352352
*
353353
* When subscribing to LIT-ICD and liveness timeout reached and OnResubscriptionNeeded returns
354-
* CHIP_ERROR_LIT_SUBSCRIBE_INACTIVE_TIMEOUT, the read client will move to the InactiveICDSubscription state and
355-
* resubscription can be triggered via OnActiveModeNotification().
354+
* CHIP_ERROR_LIT_SUBSCRIBE_INACTIVE_TIMEOUT, the read client will move to the InactiveICDSubscription state and
355+
* resubscription can be triggered via OnActiveModeNotification().
356356
*
357357
* If the subscription is not in the `InactiveICDSubscription` state, this function will do nothing. So it is always safe to
358-
* call this function when a check-in message is received.
358+
* call this function when a check-in message is received.
359+
*
360+
* If the server sends out check-in message, and there is no reschedule subscription yet in client side at the same time, it
361+
* means current client does not realize subscription has gone, and we should forcibly timeout current subscription, and schedule a new one.
362+
*
363+
* This API only works when issuing subscription via SendAutoResubscribeRequest.
359364
*/
360365
void OnActiveModeNotification();
361366

@@ -503,6 +508,13 @@ class ReadClient : public Messaging::ExchangeDelegate
503508
*/
504509
Optional<System::Clock::Timeout> GetSubscriptionTimeout();
505510

511+
512+
Optional<ScopedNodeId> GetLocalScopedNodeId() const
513+
{
514+
VerifyOrReturnValue(aReadPrepareParams.mSessionHolder, NullOptional);
515+
return MakeOptional(mReadPrepareParams.mSessionHolder->AsSecureSession()->GetLocalScopedNodeId());
516+
}
517+
506518
private:
507519
friend class TestReadInteraction;
508520
friend class InteractionModelEngine;

src/app/icd/client/CheckInHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CHIP_ERROR CheckInHandler::OnMessageReceived(Messaging::ExchangeContext * ec, co
138138
mpICDClientStorage->StoreEntry(clientInfo);
139139
mpCheckInDelegate->OnCheckInComplete(clientInfo);
140140
#if CHIP_CONFIG_ENABLE_READ_CLIENT
141-
mpImEngine->OnActiveModeNotification(clientInfo.peer_node);
141+
mpImEngine->OnActiveModeNotification(clientInfo.check_in_node, clientInfo.peer_node);
142142
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
143143
}
144144

src/controller/tests/data_model/TestRead.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@ TEST_F(TestRead, TestSubscribe_OnActiveModeNotification)
23292329

23302330
GetLoopback().mNumMessagesToDrop = 0;
23312331
callback.ClearCounters();
2332-
InteractionModelEngine::GetInstance()->OnActiveModeNotification(
2332+
InteractionModelEngine::GetInstance()->OnActiveModeNotification(readClient.GetLocalScopedNodeId().Value(),
23332333
ScopedNodeId(readClient.GetPeerNodeId(), readClient.GetFabricIndex()));
23342334
EXPECT_EQ(callback.mOnResubscriptionsAttempted, 1);
23352335
EXPECT_EQ(callback.mLastError, CHIP_ERROR_TIMEOUT);

0 commit comments

Comments
 (0)