Skip to content

Commit

Permalink
Expose public API on ReadClient to trigger a resubscribe attempt if n…
Browse files Browse the repository at this point in the history
…eeded. (#25709)

We did this already in OnUnsolicitedMessageFromPublisher but we'll want to more
explicitly do this for checkin messages and whatnot, so we should just factor
out the relevant part of the work into a separate function.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 9, 2023
1 parent f3fd3d9 commit 2b6438b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,8 @@ void ReadClient::HandleDeviceConnectionFailure(void * context, const ScopedNodeI
_this->Close(err);
}

void ReadClient::OnResubscribeTimerCallback(System::Layer * apSystemLayer, void * apAppState)
void ReadClient::OnResubscribeTimerCallback(System::Layer * /* If this starts being used, fix callers that pass nullptr */,
void * apAppState)
{
ReadClient * const _this = static_cast<ReadClient *>(apAppState);
VerifyOrDie(_this != nullptr);
Expand Down Expand Up @@ -1174,5 +1175,18 @@ CHIP_ERROR ReadClient::GetMinEventNumber(const ReadPrepareParams & aReadPrepareP
}
return CHIP_NO_ERROR;
}

void ReadClient::TriggerResubscribeIfScheduled(const char * reason)
{
if (!mIsResubscriptionScheduled)
{
return;
}

ChipLogDetail(DataManagement, "ReadClient[%p] triggering resubscribe, reason: %s", this, reason);
CancelResubscribeTimer();
OnResubscribeTimerCallback(nullptr, this);
}

} // namespace app
} // namespace chip
18 changes: 11 additions & 7 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,7 @@ class ReadClient : public Messaging::ExchangeDelegate

void OnUnsolicitedMessageFromPublisher()
{
// accelerate resubscription if scheduled
if (mIsResubscriptionScheduled)
{
ChipLogDetail(DataManagement, "%s ReadClient[%p] resubscribe on unsolicited message", __func__, this);
CancelResubscribeTimer();
OnResubscribeTimerCallback(nullptr, this);
}
TriggerResubscribeIfScheduled("unsolicited message");

// Then notify callbacks
mpCallback.OnUnsolicitedMessageFromPublisher(this);
Expand Down Expand Up @@ -421,6 +415,16 @@ class ReadClient : public Messaging::ExchangeDelegate
*/
void OverrideLivenessTimeout(System::Clock::Timeout aLivenessTimeout);

/**
* If the ReadClient currently has a resubscription attempt scheduled,
* trigger that attempt right now. This is generally useful when a consumer
* has some sort of indication that the server side is currently up and
* communicating, so right now is a good time to try to resubscribe.
*
* The reason string is used for logging if a resubscribe is triggered.
*/
void TriggerResubscribeIfScheduled(const char * reason);

private:
friend class TestReadInteraction;
friend class InteractionModelEngine;
Expand Down

0 comments on commit 2b6438b

Please sign in to comment.