From 1017152ac5604f5112795c0f6569a8b9b7bf4f36 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 21 Jul 2023 11:54:37 -0400 Subject: [PATCH] Add a way to update ReadPrepareParams based on CASE session. (#28078) If the ReadClient is doing the CASE establishment itself, it should give the client a way to modify the ReadPrepareParams based on the session information. --- src/app/BufferedReadCallback.h | 5 +++++ src/app/ClusterStateCache.h | 5 +++++ src/app/ReadClient.cpp | 2 ++ src/app/ReadClient.h | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/src/app/BufferedReadCallback.h b/src/app/BufferedReadCallback.h index 747855be1d6ea7..7779446f5a78fd 100644 --- a/src/app/BufferedReadCallback.h +++ b/src/app/BufferedReadCallback.h @@ -113,6 +113,11 @@ class BufferedReadCallback : public ReadClient::Callback return mCallback.OnUnsolicitedMessageFromPublisher(apReadClient); } + void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) override + { + return mCallback.OnCASESessionEstablished(aSession, aSubscriptionParams); + } + /* * Given a reader positioned at a list element, allocate a packet buffer, copy the list item where * the reader is positioned into that buffer and add it to our buffered list for tracking. diff --git a/src/app/ClusterStateCache.h b/src/app/ClusterStateCache.h index e773dcb4e55ea6..e0d5d98d72a5ec 100644 --- a/src/app/ClusterStateCache.h +++ b/src/app/ClusterStateCache.h @@ -631,6 +631,11 @@ class ClusterStateCache : protected ReadClient::Callback return mCallback.OnUnsolicitedMessageFromPublisher(apReadClient); } + void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) override + { + return mCallback.OnCASESessionEstablished(aSession, aSubscriptionParams); + } + // Commit the pending cluster data version, if there is one. void CommitPendingDataVersion(); diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 93b6448f56f774..23b57df99ddbcf 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -1095,6 +1095,8 @@ void ReadClient::HandleDeviceConnected(void * context, Messaging::ExchangeManage _this->mReadPrepareParams.mSessionHolder.Grab(sessionHandle); _this->mpExchangeMgr = &exchangeMgr; + _this->mpCallback.OnCASESessionEstablished(sessionHandle, _this->mReadPrepareParams); + auto err = _this->SendSubscribeRequest(_this->mReadPrepareParams); if (err != CHIP_NO_ERROR) { diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 4b0868c98798ef..502e08eaa65a6a 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -249,6 +249,16 @@ class ReadClient : public Messaging::ExchangeDelegate * @param[in] apReadClient the ReadClient for the subscription. */ virtual void OnUnsolicitedMessageFromPublisher(ReadClient * apReadClient) {} + + /** + * OnCASESessionEstablished will be called for a subscription ReadClient when + * it finishes setting up a CASE session, as part of either automatic + * re-subscription or doing an initial subscribe based on ScopedNodeId. + * + * The callee is allowed to modify the ReadPrepareParams (e.g. to change + * things like min/max intervals based on the session parameters). + */ + virtual void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) {} }; enum class InteractionType : uint8_t