From c79b062f4acd8a69163d3a14c07178035125cf5f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 16 Mar 2023 14:00:44 -0400 Subject: [PATCH] Expose public API on ReadClient to trigger a resubscribe attempt if needed. (#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. --- src/app/ReadClient.cpp | 16 +++++++++++++++- src/app/ReadClient.h | 18 +++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 939c599704724d..1875251e511df3 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -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(apAppState); VerifyOrDie(_this != nullptr); @@ -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 diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 1d6487ebd65c13..a4d2b087dd967d 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -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); @@ -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;