Skip to content

Commit f952564

Browse files
Allow setting up an auto-resubscribe ReadClient with just a peer id. (#27941)
* Allow setting up an auto-resubscribe ReadClient with just a peer id. This delegates all the work of setting up the CASE session, and the attendant retries, to the ReadClient. Fixes #23983 * Address review comment.
1 parent 01116da commit f952564

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/app/ReadClient.cpp

+23-5
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,19 @@ CHIP_ERROR ReadClient::SendAutoResubscribeRequest(ReadPrepareParams && aReadPrep
940940
return err;
941941
}
942942

943+
CHIP_ERROR ReadClient::SendAutoResubscribeRequest(const ScopedNodeId & aPublisherId, ReadPrepareParams && aReadPrepareParams)
944+
{
945+
mPeer = aPublisherId;
946+
mReadPrepareParams = std::move(aReadPrepareParams);
947+
CHIP_ERROR err = EstablishSessionToPeer();
948+
if (err != CHIP_NO_ERROR)
949+
{
950+
// Make sure we call our callback's OnDeallocatePaths.
951+
StopResubscription();
952+
}
953+
return err;
954+
}
955+
943956
CHIP_ERROR ReadClient::SendSubscribeRequest(const ReadPrepareParams & aReadPrepareParams)
944957
{
945958
VerifyOrReturnError(aReadPrepareParams.mMinIntervalFloorSeconds <= aReadPrepareParams.mMaxIntervalCeilingSeconds,
@@ -1118,12 +1131,8 @@ void ReadClient::OnResubscribeTimerCallback(System::Layer * /* If this starts be
11181131
{
11191132
// We don't have an active CASE session. We need to go ahead and set
11201133
// one up, if we can.
1121-
ChipLogProgress(DataManagement, "Trying to establish a CASE session");
1122-
auto * caseSessionManager = InteractionModelEngine::GetInstance()->GetCASESessionManager();
1123-
if (caseSessionManager)
1134+
if (_this->EstablishSessionToPeer() == CHIP_NO_ERROR)
11241135
{
1125-
caseSessionManager->FindOrEstablishSession(_this->mPeer, &_this->mOnConnectedCallback,
1126-
&_this->mOnConnectionFailureCallback);
11271136
return;
11281137
}
11291138

@@ -1209,5 +1218,14 @@ Optional<System::Clock::Timeout> ReadClient::GetSubscriptionTimeout()
12091218
return MakeOptional(timeout);
12101219
}
12111220

1221+
CHIP_ERROR ReadClient::EstablishSessionToPeer()
1222+
{
1223+
ChipLogProgress(DataManagement, "Trying to establish a CASE session for subscription");
1224+
auto * caseSessionManager = InteractionModelEngine::GetInstance()->GetCASESessionManager();
1225+
VerifyOrReturnError(caseSessionManager != nullptr, CHIP_ERROR_INCORRECT_STATE);
1226+
caseSessionManager->FindOrEstablishSession(mPeer, &mOnConnectedCallback, &mOnConnectionFailureCallback);
1227+
return CHIP_NO_ERROR;
1228+
}
1229+
12121230
} // namespace app
12131231
} // namespace chip

src/app/ReadClient.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,22 @@ class ReadClient : public Messaging::ExchangeDelegate
352352
* OnDeallocatePaths. Note: At a given time in the system, you can either have a single subscription with re-sub enabled that
353353
* has mKeepSubscriptions = false, OR, multiple subs with re-sub enabled with mKeepSubscriptions = true. You shall not
354354
* have a mix of both simultaneously. If SendAutoResubscribeRequest is called at all, it guarantees that it will call
355-
* OnDeallocatePaths when OnDone is called. SendAutoResubscribeRequest is the only case that calls OnDeallocatePaths, since
356-
* that's the only case when the consumer moved a ReadParams into the client.
355+
* OnDeallocatePaths (either befor returning error, or when OnDone is called). SendAutoResubscribeRequest is the only case
356+
* that calls OnDeallocatePaths, since that's the only case when the consumer moved a ReadParams into the client.
357357
*
358358
*/
359359
CHIP_ERROR SendAutoResubscribeRequest(ReadPrepareParams && aReadPrepareParams);
360360

361+
/**
362+
* Like SendAutoResubscribeRequest above, but without a session being
363+
* available in the ReadPrepareParams. When this is used, the ReadClient is
364+
* responsible for setting up the CASE session itself.
365+
*
366+
* When using this version of SendAutoResubscribeRequest, any session to
367+
* which ReadPrepareParams has a reference will be ignored.
368+
*/
369+
CHIP_ERROR SendAutoResubscribeRequest(const ScopedNodeId & aPublisherId, ReadPrepareParams && aReadPrepareParams);
370+
361371
/**
362372
* This provides a standard re-subscription policy implementation that given a termination cause, does the following:
363373
* - Calculates the time till next subscription with fibonacci back-off (implemented by ComputeTimeTillNextSubscription()).
@@ -538,6 +548,13 @@ class ReadClient : public Messaging::ExchangeDelegate
538548

539549
CHIP_ERROR GetMinEventNumber(const ReadPrepareParams & aReadPrepareParams, Optional<EventNumber> & aEventMin);
540550

551+
/**
552+
* Start setting up a CASE session to our peer, if we can locate a
553+
* CASESessionManager. Returns error if we did not even manage to kick off
554+
* a CASE attempt.
555+
*/
556+
CHIP_ERROR EstablishSessionToPeer();
557+
541558
Messaging::ExchangeManager * mpExchangeMgr = nullptr;
542559
Messaging::ExchangeHolder mExchange;
543560
Callback & mpCallback;

0 commit comments

Comments
 (0)