Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting up an auto-resubscribe ReadClient with just a peer id. #27941

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,19 @@ CHIP_ERROR ReadClient::SendAutoResubscribeRequest(ReadPrepareParams && aReadPrep
return err;
}

CHIP_ERROR ReadClient::SendAutoResubscribeRequest(const ScopedNodeId & aPublisherId, ReadPrepareParams && aReadPrepareParams)
{
mPeer = aPublisherId;
mReadPrepareParams = std::move(aReadPrepareParams);
CHIP_ERROR err = EstablishSessionToPeer();
if (err != CHIP_NO_ERROR)
{
// Make sure we call our callback's OnDeallocatePaths.
StopResubscription();
}
return err;
}

CHIP_ERROR ReadClient::SendSubscribeRequest(const ReadPrepareParams & aReadPrepareParams)
{
VerifyOrReturnError(aReadPrepareParams.mMinIntervalFloorSeconds <= aReadPrepareParams.mMaxIntervalCeilingSeconds,
Expand Down Expand Up @@ -1118,12 +1131,8 @@ void ReadClient::OnResubscribeTimerCallback(System::Layer * /* If this starts be
{
// We don't have an active CASE session. We need to go ahead and set
// one up, if we can.
ChipLogProgress(DataManagement, "Trying to establish a CASE session");
auto * caseSessionManager = InteractionModelEngine::GetInstance()->GetCASESessionManager();
if (caseSessionManager)
if (_this->EstablishSessionToPeer() == CHIP_NO_ERROR)
{
caseSessionManager->FindOrEstablishSession(_this->mPeer, &_this->mOnConnectedCallback,
&_this->mOnConnectionFailureCallback);
return;
}

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

CHIP_ERROR ReadClient::EstablishSessionToPeer()
{
ChipLogProgress(DataManagement, "Trying to establish a CASE session for subscription");
auto * caseSessionManager = InteractionModelEngine::GetInstance()->GetCASESessionManager();
VerifyOrReturnError(caseSessionManager != nullptr, CHIP_ERROR_INCORRECT_STATE);
caseSessionManager->FindOrEstablishSession(mPeer, &mOnConnectedCallback, &mOnConnectionFailureCallback);
return CHIP_NO_ERROR;
}

} // namespace app
} // namespace chip
21 changes: 19 additions & 2 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,22 @@ class ReadClient : public Messaging::ExchangeDelegate
* OnDeallocatePaths. Note: At a given time in the system, you can either have a single subscription with re-sub enabled that
* has mKeepSubscriptions = false, OR, multiple subs with re-sub enabled with mKeepSubscriptions = true. You shall not
* have a mix of both simultaneously. If SendAutoResubscribeRequest is called at all, it guarantees that it will call
* OnDeallocatePaths when OnDone is called. SendAutoResubscribeRequest is the only case that calls OnDeallocatePaths, since
* that's the only case when the consumer moved a ReadParams into the client.
* OnDeallocatePaths (either befor returning error, or when OnDone is called). SendAutoResubscribeRequest is the only case
* that calls OnDeallocatePaths, since that's the only case when the consumer moved a ReadParams into the client.
*
*/
CHIP_ERROR SendAutoResubscribeRequest(ReadPrepareParams && aReadPrepareParams);

/**
* Like SendAutoResubscribeRequest above, but without a session being
* available in the ReadPrepareParams. When this is used, the ReadClient is
* responsible for setting up the CASE session itself.
*
* When using this version of SendAutoResubscribeRequest, any session to
* which ReadPrepareParams has a reference will be ignored.
*/
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
CHIP_ERROR SendAutoResubscribeRequest(const ScopedNodeId & aPublisherId, ReadPrepareParams && aReadPrepareParams);

/**
* This provides a standard re-subscription policy implementation that given a termination cause, does the following:
* - Calculates the time till next subscription with fibonacci back-off (implemented by ComputeTimeTillNextSubscription()).
Expand Down Expand Up @@ -538,6 +548,13 @@ class ReadClient : public Messaging::ExchangeDelegate

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

/**
* Start setting up a CASE session to our peer, if we can locate a
* CASESessionManager. Returns error if we did not even manage to kick off
* a CASE attempt.
*/
CHIP_ERROR EstablishSessionToPeer();

Messaging::ExchangeManager * mpExchangeMgr = nullptr;
Messaging::ExchangeHolder mExchange;
Callback & mpCallback;
Expand Down