From 1494319587a301765987faa5066e78a99c742098 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Wed, 15 Nov 2023 19:16:32 +0800 Subject: [PATCH 1/8] IM: Create ReadHandler after Session Establishment for Subscription Resumption --- src/app/BUILD.gn | 7 ++ src/app/InteractionModelEngine.cpp | 17 ++--- src/app/InteractionModelEngine.h | 2 + src/app/ReadHandler.cpp | 89 ++++++++-------------- src/app/ReadHandler.h | 21 ++---- src/app/SubscriptionResumptionHelper.cpp | 94 ++++++++++++++++++++++++ src/app/SubscriptionResumptionHelper.h | 61 +++++++++++++++ 7 files changed, 205 insertions(+), 86 deletions(-) create mode 100644 src/app/SubscriptionResumptionHelper.cpp create mode 100644 src/app/SubscriptionResumptionHelper.h diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 987bfdcaf2521f..95fcb2231f5eb9 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -235,6 +235,13 @@ static_library("app") { ] } + if (chip_persist_subscriptions) { + sources += [ + "SubscriptionResumptionHelper.cpp", + "SubscriptionResumptionHelper.h", + ] + } + if (chip_enable_read_client) { sources += [ "BufferedReadCallback.cpp", diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index d202dc7d07c062..38b6f676fbf0dc 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -1853,26 +1853,21 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap continue; } - auto requestedAttributePathCount = subscriptionInfo.mAttributePaths.AllocatedSize(); - auto requestedEventPathCount = subscriptionInfo.mEventPaths.AllocatedSize(); - if (!imEngine->EnsureResourceForSubscription(subscriptionInfo.mFabricIndex, requestedAttributePathCount, - requestedEventPathCount)) + auto subscriptionResumptionHelper = Platform::MakeUnique(); + if (subscriptionResumptionHelper == nullptr) { - ChipLogProgress(InteractionModel, "no resource for Subscription resumption"); + ChipLogProgress(InteractionModel, "Failed to create SubscriptionResumptionHelper"); iterator->Release(); return; } - ReadHandler * handler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); - if (handler == nullptr) + if (subscriptionResumptionHelper->ResumeSubscription(*imEngine->mpCASESessionMgr, subscriptionInfo) != CHIP_NO_ERROR) { - ChipLogProgress(InteractionModel, "no resource for ReadHandler creation"); + ChipLogProgress(InteractionModel, "Failed to ResumeSubscription 0x%" PRIx32, subscriptionInfo.mSubscriptionId); iterator->Release(); return; } - - ChipLogProgress(InteractionModel, "Resuming subscriptionId %" PRIu32, subscriptionInfo.mSubscriptionId); - handler->ResumeSubscription(*imEngine->mpCASESessionMgr, subscriptionInfo); + subscriptionResumptionHelper.release(); #if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION resumedSubscriptions = true; #endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index ca1fa92f240c58..450484c2e6e600 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -377,6 +378,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, friend class reporting::Engine; friend class TestCommandInteraction; friend class TestInteractionModelEngine; + friend class SubscriptionResumptionHelper; using Status = Protocols::InteractionModel::Status; void OnDone(CommandHandler & apCommandObj) override; diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 0f79c1a1d0d5f4..198567eb3235cd 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -55,10 +55,6 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeCon InteractionType aInteractionType, Observer * observer) : mExchangeCtx(*this), mManagementCallback(apCallback) -#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS - , - mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) -#endif { VerifyOrDie(apExchangeContext != nullptr); @@ -83,8 +79,7 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeCon #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : - mExchangeCtx(*this), mManagementCallback(apCallback), mOnConnectedCallback(HandleDeviceConnected, this), - mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) + mExchangeCtx(*this), mManagementCallback(apCallback) { mInteractionType = InteractionType::Subscribe; mFlags.ClearAll(); @@ -93,31 +88,28 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : mObserver = observer; } -void ReadHandler::ResumeSubscription(CASESessionManager & caseSessionManager, - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) +void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper) { - mSubscriptionId = subscriptionInfo.mSubscriptionId; - mMinIntervalFloorSeconds = subscriptionInfo.mMinInterval; - mMaxInterval = subscriptionInfo.mMaxInterval; - SetStateFlag(ReadHandlerFlags::FabricFiltered, subscriptionInfo.mFabricFiltered); + mSubscriptionId = helper.mSubscriptionId; + mMinIntervalFloorSeconds = helper.mMinIntervalFloorSeconds; + mMaxInterval = helper.mMaxInterval; + SetStateFlag(ReadHandlerFlags::FabricFiltered, helper.mFabricFiltered); // Move dynamically allocated attributes and events from the SubscriptionInfo struct into // the object pool managed by the IM engine - for (size_t i = 0; i < subscriptionInfo.mAttributePaths.AllocatedSize(); i++) + for (size_t i = 0; i < helper.mAttributePaths.AllocatedSize(); i++) { - AttributePathParams attributePathParams = subscriptionInfo.mAttributePaths[i].GetParams(); CHIP_ERROR err = - InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, attributePathParams); + InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, helper.mAttributePaths[i]); if (err != CHIP_NO_ERROR) { Close(); return; } } - for (size_t i = 0; i < subscriptionInfo.mEventPaths.AllocatedSize(); i++) + for (size_t i = 0; i < helper.mEventPaths.AllocatedSize(); i++) { - EventPathParams eventPathParams = subscriptionInfo.mEventPaths[i].GetParams(); - CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, eventPathParams); + CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, helper.mEventPaths[i]); if (err != CHIP_NO_ERROR) { Close(); @@ -125,9 +117,26 @@ void ReadHandler::ResumeSubscription(CASESessionManager & caseSessionManager, } } - // Ask IM engine to start CASE session with subscriber - ScopedNodeId peerNode = ScopedNodeId(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex); - caseSessionManager.FindOrEstablishSession(peerNode, &mOnConnectedCallback, &mOnConnectionFailureCallback); + mSessionHandle.Grab(sessionHandle); + + SetStateFlag(ReadHandlerFlags::ActiveSubscription); + + auto * appCallback = mManagementCallback.GetAppCallback(); + if (appCallback) + { + appCallback->OnSubscriptionEstablished(*this); + } + // Notify the observer that a subscription has been resumed + mObserver->OnSubscriptionEstablished(this); + + MoveToState(HandlerState::CanStartReporting); + + ObjectList * attributePath = mpAttributePathList; + while (attributePath) + { + InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(attributePath->mValue); + attributePath = attributePath->mpNext; + } } #endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS @@ -892,43 +901,5 @@ void ReadHandler::ClearStateFlag(ReadHandlerFlags aFlag) SetStateFlag(aFlag, false); } -void ReadHandler::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, - const SessionHandle & sessionHandle) -{ - ReadHandler * const _this = static_cast(context); - - _this->mSessionHandle.Grab(sessionHandle); - - _this->SetStateFlag(ReadHandlerFlags::ActiveSubscription); - - auto * appCallback = _this->mManagementCallback.GetAppCallback(); - if (appCallback) - { - appCallback->OnSubscriptionEstablished(*_this); - } - // Notify the observer that a subscription has been resumed - _this->mObserver->OnSubscriptionEstablished(_this); - - _this->MoveToState(HandlerState::CanStartReporting); - - ObjectList * attributePath = _this->mpAttributePathList; - while (attributePath) - { - InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(attributePath->mValue); - attributePath = attributePath->mpNext; - } -} - -void ReadHandler::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR err) -{ - ReadHandler * const _this = static_cast(context); - VerifyOrDie(_this != nullptr); - - // TODO: Have a retry mechanism tied to wake interval for IC devices - ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", - err.Format()); - _this->Close(); -} - } // namespace app } // namespace chip diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 4c9ad469c782eb..e9f724eee28fe6 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -305,13 +306,11 @@ class ReadHandler : public Messaging::ExchangeDelegate #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS /** * - * @brief Resume a persisted subscription + * @brief Initialize a ReadHandler for a resumed subsciption * - * Used after ReadHandler(ManagementCallback & apCallback). This will start a CASE session - * with the subscriber if one doesn't already exist, and send full priming report when connected. + * Used after the SubscriptionResumptionHelper establishs the CASE session */ - void ResumeSubscription(CASESessionManager & caseSessionManager, - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); + void OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper); #endif /** @@ -429,6 +428,7 @@ class ReadHandler : public Messaging::ExchangeDelegate // friend class chip::app::reporting::Engine; friend class chip::app::InteractionModelEngine; + friend class chip::app::SubscriptionResumptionHelper; // The report scheduler needs to be able to access StateFlag private functions ShouldStartReporting(), CanStartReporting(), // ForceDirtyState() and IsDirty() to know when to schedule a run so it is declared as a friend class. @@ -485,11 +485,6 @@ class ReadHandler : public Messaging::ExchangeDelegate /// @param aFlag Flag to clear void ClearStateFlag(ReadHandlerFlags aFlag); - // Helpers for continuing the subscription resumption - static void HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, - const SessionHandle & sessionHandle); - static void HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error); - AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr); // The current generation of the reporting engine dirty set the last time we were notified that a path we're interested in was @@ -571,12 +566,6 @@ class ReadHandler : public Messaging::ExchangeDelegate // TODO (#27675): Merge all observers into one and that one will dispatch the callbacks to the right place. Observer * mObserver = nullptr; - -#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS - // Callbacks to handle server-initiated session success/failure - chip::Callback::Callback mOnConnectedCallback; - chip::Callback::Callback mOnConnectionFailureCallback; -#endif }; } // namespace app } // namespace chip diff --git a/src/app/SubscriptionResumptionHelper.cpp b/src/app/SubscriptionResumptionHelper.cpp new file mode 100644 index 00000000000000..1a12e2bb67dce6 --- /dev/null +++ b/src/app/SubscriptionResumptionHelper.cpp @@ -0,0 +1,94 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace chip { +namespace app { +SubscriptionResumptionHelper::SubscriptionResumptionHelper() : + mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) +{} + +CHIP_ERROR SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) +{ + mNodeId = subscriptionInfo.mNodeId; + mFabricIndex = subscriptionInfo.mFabricIndex; + mSubscriptionId = subscriptionInfo.mSubscriptionId; + mMinIntervalFloorSeconds = subscriptionInfo.mMinInterval; + mMaxInterval = subscriptionInfo.mMaxInterval; + mFabricFiltered = subscriptionInfo.mFabricFiltered; + + if (subscriptionInfo.mAttributePaths.AllocatedSize() > 0) + { + mAttributePaths.Alloc(subscriptionInfo.mAttributePaths.AllocatedSize()); + ReturnErrorCodeIf(mAttributePaths.Get() == nullptr, CHIP_ERROR_NO_MEMORY); + for (size_t i = 0; i < subscriptionInfo.mAttributePaths.AllocatedSize(); i++) + { + mAttributePaths[i] = subscriptionInfo.mAttributePaths[i].GetParams(); + } + } + + if (subscriptionInfo.mEventPaths.AllocatedSize() > 0) + { + mEventPaths.Alloc(subscriptionInfo.mEventPaths.AllocatedSize()); + ReturnErrorCodeIf(mEventPaths.Get() == nullptr, CHIP_ERROR_NO_MEMORY); + for (size_t i = 0; i < subscriptionInfo.mEventPaths.AllocatedSize(); i++) + { + mEventPaths[i] = subscriptionInfo.mEventPaths[i].GetParams(); + } + } + ScopedNodeId peerNode = ScopedNodeId(mNodeId, mFabricIndex); + caseSessionManager.FindOrEstablishSession(peerNode, &mOnConnectedCallback, &mOnConnectionFailureCallback); + return CHIP_NO_ERROR; +} + +void SubscriptionResumptionHelper::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, + const SessionHandle & sessionHandle) +{ + Platform::UniquePtr _this(static_cast(context)); + InteractionModelEngine *imEngine = InteractionModelEngine::GetInstance(); + if (!imEngine->EnsureResourceForSubscription(_this->mFabricIndex, _this->mAttributePaths.AllocatedSize(), + _this->mEventPaths.AllocatedSize())) + { + ChipLogProgress(InteractionModel, "no resource for subscription resumption"); + return; + } + ReadHandler *readHandler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); + if (readHandler == nullptr) { + ChipLogProgress(InteractionModel, "no resource for ReadHandler creation"); + return; + } + readHandler->OnSubscriptionResumed(sessionHandle, *_this); +} + +void SubscriptionResumptionHelper::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) +{ + Platform::UniquePtr _this(static_cast(context)); + ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", + error.Format()); + // Delete the persistent subscription information + auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); + if (subscriptionResumptionStorage) + { + subscriptionResumptionStorage->Delete(_this->mNodeId, _this->mFabricIndex, _this->mSubscriptionId); + } +} + +} // namespace app +} // namespace chip diff --git a/src/app/SubscriptionResumptionHelper.h b/src/app/SubscriptionResumptionHelper.h new file mode 100644 index 00000000000000..803472fba68204 --- /dev/null +++ b/src/app/SubscriptionResumptionHelper.h @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace chip { +namespace app { +class InteractionModelEngine; +class ReadHandler; + +class SubscriptionResumptionHelper { +public: + SubscriptionResumptionHelper(); + + ~SubscriptionResumptionHelper() {} + +private: + friend class InteractionModelEngine; + friend class ReadHandler; + + CHIP_ERROR ResumeSubscription(CASESessionManager & caseSessionManager, + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); + + // Callback funstions for continuing the subscription resumption + static void HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, + const SessionHandle & sessionHandle); + static void HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error); + + NodeId mNodeId; + FabricIndex mFabricIndex; + SubscriptionId mSubscriptionId = 0; + uint16_t mMinIntervalFloorSeconds = 0; + uint16_t mMaxInterval = 0; + bool mFabricFiltered = false; + Platform::ScopedMemoryBufferWithSize mAttributePaths; + Platform::ScopedMemoryBufferWithSize mEventPaths; + + // Callbacks to handle server-initiated session success/failure + chip::Callback::Callback mOnConnectedCallback; + chip::Callback::Callback mOnConnectionFailureCallback; +}; +} // namespace app +} // namespace chip From 43c09a9d45ac4d874bcbeab2751247169a898a27 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 15 Nov 2023 12:19:46 +0000 Subject: [PATCH 2/8] Restyled by clang-format --- src/app/ReadHandler.cpp | 3 ++- src/app/SubscriptionResumptionHelper.cpp | 21 +++++++++++---------- src/app/SubscriptionResumptionHelper.h | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 198567eb3235cd..8c76598d11451f 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -109,7 +109,8 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, Sub } for (size_t i = 0; i < helper.mEventPaths.AllocatedSize(); i++) { - CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, helper.mEventPaths[i]); + CHIP_ERROR err = + InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, helper.mEventPaths[i]); if (err != CHIP_NO_ERROR) { Close(); diff --git a/src/app/SubscriptionResumptionHelper.cpp b/src/app/SubscriptionResumptionHelper.cpp index 1a12e2bb67dce6..645b4084a96d46 100644 --- a/src/app/SubscriptionResumptionHelper.cpp +++ b/src/app/SubscriptionResumptionHelper.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ -#include #include +#include namespace chip { namespace app { @@ -27,12 +27,12 @@ SubscriptionResumptionHelper::SubscriptionResumptionHelper() : CHIP_ERROR SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) { - mNodeId = subscriptionInfo.mNodeId; - mFabricIndex = subscriptionInfo.mFabricIndex; - mSubscriptionId = subscriptionInfo.mSubscriptionId; + mNodeId = subscriptionInfo.mNodeId; + mFabricIndex = subscriptionInfo.mFabricIndex; + mSubscriptionId = subscriptionInfo.mSubscriptionId; mMinIntervalFloorSeconds = subscriptionInfo.mMinInterval; - mMaxInterval = subscriptionInfo.mMaxInterval; - mFabricFiltered = subscriptionInfo.mFabricFiltered; + mMaxInterval = subscriptionInfo.mMaxInterval; + mFabricFiltered = subscriptionInfo.mFabricFiltered; if (subscriptionInfo.mAttributePaths.AllocatedSize() > 0) { @@ -62,15 +62,16 @@ void SubscriptionResumptionHelper::HandleDeviceConnected(void * context, Messagi const SessionHandle & sessionHandle) { Platform::UniquePtr _this(static_cast(context)); - InteractionModelEngine *imEngine = InteractionModelEngine::GetInstance(); + InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); if (!imEngine->EnsureResourceForSubscription(_this->mFabricIndex, _this->mAttributePaths.AllocatedSize(), _this->mEventPaths.AllocatedSize())) { ChipLogProgress(InteractionModel, "no resource for subscription resumption"); return; } - ReadHandler *readHandler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); - if (readHandler == nullptr) { + ReadHandler * readHandler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); + if (readHandler == nullptr) + { ChipLogProgress(InteractionModel, "no resource for ReadHandler creation"); return; } @@ -81,7 +82,7 @@ void SubscriptionResumptionHelper::HandleDeviceConnectionFailure(void * context, { Platform::UniquePtr _this(static_cast(context)); ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", - error.Format()); + error.Format()); // Delete the persistent subscription information auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); if (subscriptionResumptionStorage) diff --git a/src/app/SubscriptionResumptionHelper.h b/src/app/SubscriptionResumptionHelper.h index 803472fba68204..b5476602a25718 100644 --- a/src/app/SubscriptionResumptionHelper.h +++ b/src/app/SubscriptionResumptionHelper.h @@ -26,7 +26,8 @@ namespace app { class InteractionModelEngine; class ReadHandler; -class SubscriptionResumptionHelper { +class SubscriptionResumptionHelper +{ public: SubscriptionResumptionHelper(); From 0ae9c31e6182441563ce3915195c508c84097bbc Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Tue, 21 Nov 2023 15:04:36 +0800 Subject: [PATCH 3/8] Make SubscriptionResumptionHelper inherits from SubscriptionInfo --- src/app/ReadHandler.cpp | 10 +++---- src/app/SubscriptionResumptionHelper.cpp | 37 +++++++----------------- src/app/SubscriptionResumptionHelper.h | 11 +------ 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 8c76598d11451f..bd16d88081768d 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -91,7 +91,7 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper) { mSubscriptionId = helper.mSubscriptionId; - mMinIntervalFloorSeconds = helper.mMinIntervalFloorSeconds; + mMinIntervalFloorSeconds = helper.mMinInterval; mMaxInterval = helper.mMaxInterval; SetStateFlag(ReadHandlerFlags::FabricFiltered, helper.mFabricFiltered); @@ -99,8 +99,8 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, Sub // the object pool managed by the IM engine for (size_t i = 0; i < helper.mAttributePaths.AllocatedSize(); i++) { - CHIP_ERROR err = - InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, helper.mAttributePaths[i]); + AttributePathParams params = helper.mAttributePaths[i].GetParams(); + CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, params); if (err != CHIP_NO_ERROR) { Close(); @@ -109,8 +109,8 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, Sub } for (size_t i = 0; i < helper.mEventPaths.AllocatedSize(); i++) { - CHIP_ERROR err = - InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, helper.mEventPaths[i]); + EventPathParams params = helper.mEventPaths[i].GetParams(); + CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, params); if (err != CHIP_NO_ERROR) { Close(); diff --git a/src/app/SubscriptionResumptionHelper.cpp b/src/app/SubscriptionResumptionHelper.cpp index 645b4084a96d46..446f0e26adca61 100644 --- a/src/app/SubscriptionResumptionHelper.cpp +++ b/src/app/SubscriptionResumptionHelper.cpp @@ -27,32 +27,15 @@ SubscriptionResumptionHelper::SubscriptionResumptionHelper() : CHIP_ERROR SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) { - mNodeId = subscriptionInfo.mNodeId; - mFabricIndex = subscriptionInfo.mFabricIndex; - mSubscriptionId = subscriptionInfo.mSubscriptionId; - mMinIntervalFloorSeconds = subscriptionInfo.mMinInterval; - mMaxInterval = subscriptionInfo.mMaxInterval; - mFabricFiltered = subscriptionInfo.mFabricFiltered; + mNodeId = subscriptionInfo.mNodeId; + mFabricIndex = subscriptionInfo.mFabricIndex; + mSubscriptionId = subscriptionInfo.mSubscriptionId; + mMinInterval = subscriptionInfo.mMinInterval; + mMaxInterval = subscriptionInfo.mMaxInterval; + mFabricFiltered = subscriptionInfo.mFabricFiltered; + mAttributePaths = std::move(subscriptionInfo.mAttributePaths); + mEventPaths = std::move(subscriptionInfo.mEventPaths); - if (subscriptionInfo.mAttributePaths.AllocatedSize() > 0) - { - mAttributePaths.Alloc(subscriptionInfo.mAttributePaths.AllocatedSize()); - ReturnErrorCodeIf(mAttributePaths.Get() == nullptr, CHIP_ERROR_NO_MEMORY); - for (size_t i = 0; i < subscriptionInfo.mAttributePaths.AllocatedSize(); i++) - { - mAttributePaths[i] = subscriptionInfo.mAttributePaths[i].GetParams(); - } - } - - if (subscriptionInfo.mEventPaths.AllocatedSize() > 0) - { - mEventPaths.Alloc(subscriptionInfo.mEventPaths.AllocatedSize()); - ReturnErrorCodeIf(mEventPaths.Get() == nullptr, CHIP_ERROR_NO_MEMORY); - for (size_t i = 0; i < subscriptionInfo.mEventPaths.AllocatedSize(); i++) - { - mEventPaths[i] = subscriptionInfo.mEventPaths[i].GetParams(); - } - } ScopedNodeId peerNode = ScopedNodeId(mNodeId, mFabricIndex); caseSessionManager.FindOrEstablishSession(peerNode, &mOnConnectedCallback, &mOnConnectionFailureCallback); return CHIP_NO_ERROR; @@ -83,7 +66,9 @@ void SubscriptionResumptionHelper::HandleDeviceConnectionFailure(void * context, Platform::UniquePtr _this(static_cast(context)); ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", error.Format()); - // Delete the persistent subscription information + // If the device fails to establish the session, the subscriber might be offline and its subscription read client will + // be deleted after the device reconnect to the subscriber. This subscription will be never used again. So clean up + // the persistent subscription information storage. auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); if (subscriptionResumptionStorage) { diff --git a/src/app/SubscriptionResumptionHelper.h b/src/app/SubscriptionResumptionHelper.h index b5476602a25718..dd865a018a8fdb 100644 --- a/src/app/SubscriptionResumptionHelper.h +++ b/src/app/SubscriptionResumptionHelper.h @@ -26,7 +26,7 @@ namespace app { class InteractionModelEngine; class ReadHandler; -class SubscriptionResumptionHelper +class SubscriptionResumptionHelper : private SubscriptionResumptionStorage::SubscriptionInfo { public: SubscriptionResumptionHelper(); @@ -45,15 +45,6 @@ class SubscriptionResumptionHelper const SessionHandle & sessionHandle); static void HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error); - NodeId mNodeId; - FabricIndex mFabricIndex; - SubscriptionId mSubscriptionId = 0; - uint16_t mMinIntervalFloorSeconds = 0; - uint16_t mMaxInterval = 0; - bool mFabricFiltered = false; - Platform::ScopedMemoryBufferWithSize mAttributePaths; - Platform::ScopedMemoryBufferWithSize mEventPaths; - // Callbacks to handle server-initiated session success/failure chip::Callback::Callback mOnConnectedCallback; chip::Callback::Callback mOnConnectionFailureCallback; From cc0c6411bd4e9cd69ba94b8ace37dcb8b1204120 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Wed, 29 Nov 2023 11:47:04 +0800 Subject: [PATCH 4/8] review changes --- src/app/ReadHandler.cpp | 16 +++--- src/app/ReadHandler.h | 21 ++++---- src/app/SubscriptionResumptionHelper.cpp | 67 +++++++++++++++++------- src/app/SubscriptionResumptionHelper.h | 20 ++++--- 4 files changed, 79 insertions(+), 45 deletions(-) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index bd16d88081768d..420a02ed55c0db 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -90,16 +90,16 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper) { - mSubscriptionId = helper.mSubscriptionId; - mMinIntervalFloorSeconds = helper.mMinInterval; - mMaxInterval = helper.mMaxInterval; - SetStateFlag(ReadHandlerFlags::FabricFiltered, helper.mFabricFiltered); + mSubscriptionId = helper.mSubscriptionInfo.mSubscriptionId; + mMinIntervalFloorSeconds = helper.mSubscriptionInfo.mMinInterval; + mMaxInterval = helper.mSubscriptionInfo.mMaxInterval; + SetStateFlag(ReadHandlerFlags::FabricFiltered, helper.mSubscriptionInfo.mFabricFiltered); // Move dynamically allocated attributes and events from the SubscriptionInfo struct into // the object pool managed by the IM engine - for (size_t i = 0; i < helper.mAttributePaths.AllocatedSize(); i++) + for (size_t i = 0; i < helper.mSubscriptionInfo.mAttributePaths.AllocatedSize(); i++) { - AttributePathParams params = helper.mAttributePaths[i].GetParams(); + AttributePathParams params = helper.mSubscriptionInfo.mAttributePaths[i].GetParams(); CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, params); if (err != CHIP_NO_ERROR) { @@ -107,9 +107,9 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, Sub return; } } - for (size_t i = 0; i < helper.mEventPaths.AllocatedSize(); i++) + for (size_t i = 0; i < helper.mSubscriptionInfo.mEventPaths.AllocatedSize(); i++) { - EventPathParams params = helper.mEventPaths[i].GetParams(); + EventPathParams params = helper.mSubscriptionInfo.mEventPaths[i].GetParams(); CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, params); if (err != CHIP_NO_ERROR) { diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index e9f724eee28fe6..c4816d9a822eb4 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -254,6 +254,16 @@ class ReadHandler : public Messaging::ExchangeDelegate return CHIP_NO_ERROR; } +#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS + /** + * + * @brief Initialize a ReadHandler for a resumed subsciption + * + * Used after the SubscriptionResumptionHelper establishs the CASE session + */ + void OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper); +#endif + private: PriorityLevel GetCurrentPriority() const { return mCurrentPriority; } EventNumber & GetEventMin() { return mEventMin; } @@ -303,16 +313,6 @@ class ReadHandler : public Messaging::ExchangeDelegate */ void OnInitialRequest(System::PacketBufferHandle && aPayload); -#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS - /** - * - * @brief Initialize a ReadHandler for a resumed subsciption - * - * Used after the SubscriptionResumptionHelper establishs the CASE session - */ - void OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper); -#endif - /** * Send ReportData to initiator * @@ -428,7 +428,6 @@ class ReadHandler : public Messaging::ExchangeDelegate // friend class chip::app::reporting::Engine; friend class chip::app::InteractionModelEngine; - friend class chip::app::SubscriptionResumptionHelper; // The report scheduler needs to be able to access StateFlag private functions ShouldStartReporting(), CanStartReporting(), // ForceDirtyState() and IsDirty() to know when to schedule a run so it is declared as a friend class. diff --git a/src/app/SubscriptionResumptionHelper.cpp b/src/app/SubscriptionResumptionHelper.cpp index 446f0e26adca61..77d71345c31206 100644 --- a/src/app/SubscriptionResumptionHelper.cpp +++ b/src/app/SubscriptionResumptionHelper.cpp @@ -24,19 +24,43 @@ SubscriptionResumptionHelper::SubscriptionResumptionHelper() : mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) {} -CHIP_ERROR SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) +CHIP_ERROR +SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, + const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) { - mNodeId = subscriptionInfo.mNodeId; - mFabricIndex = subscriptionInfo.mFabricIndex; - mSubscriptionId = subscriptionInfo.mSubscriptionId; - mMinInterval = subscriptionInfo.mMinInterval; - mMaxInterval = subscriptionInfo.mMaxInterval; - mFabricFiltered = subscriptionInfo.mFabricFiltered; - mAttributePaths = std::move(subscriptionInfo.mAttributePaths); - mEventPaths = std::move(subscriptionInfo.mEventPaths); + mSubscriptionInfo.mNodeId = subscriptionInfo.mNodeId; + mSubscriptionInfo.mFabricIndex = subscriptionInfo.mFabricIndex; + mSubscriptionInfo.mSubscriptionId = subscriptionInfo.mSubscriptionId; + mSubscriptionInfo.mMinInterval = subscriptionInfo.mMinInterval; + mSubscriptionInfo.mMaxInterval = subscriptionInfo.mMaxInterval; + mSubscriptionInfo.mFabricFiltered = subscriptionInfo.mFabricFiltered; + // Copy the Attribute Paths and Event Paths + if (subscriptionInfo.mAttributePaths.AllocatedSize() > 0) + { + mSubscriptionInfo.mAttributePaths.Alloc(subscriptionInfo.mAttributePaths.AllocatedSize()); + if (!mSubscriptionInfo.mAttributePaths.Get()) + { + return CHIP_ERROR_NO_MEMORY; + } + for (size_t i = 0; i < mSubscriptionInfo.mAttributePaths.AllocatedSize(); ++i) + { + mSubscriptionInfo.mAttributePaths[i] = subscriptionInfo.mAttributePaths[i]; + } + } + if (subscriptionInfo.mEventPaths.AllocatedSize() > 0) + { + mSubscriptionInfo.mEventPaths.Alloc(subscriptionInfo.mEventPaths.AllocatedSize()); + if (!mSubscriptionInfo.mEventPaths.Get()) + { + return CHIP_ERROR_NO_MEMORY; + } + for (size_t i = 0; i < mSubscriptionInfo.mEventPaths.AllocatedSize(); ++i) + { + mSubscriptionInfo.mEventPaths[i] = subscriptionInfo.mEventPaths[i]; + } + } - ScopedNodeId peerNode = ScopedNodeId(mNodeId, mFabricIndex); + ScopedNodeId peerNode = ScopedNodeId(mSubscriptionInfo.mNodeId, mSubscriptionInfo.mFabricIndex); caseSessionManager.FindOrEstablishSession(peerNode, &mOnConnectedCallback, &mOnConnectionFailureCallback); return CHIP_NO_ERROR; } @@ -44,36 +68,43 @@ CHIP_ERROR SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & void SubscriptionResumptionHelper::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle) { - Platform::UniquePtr _this(static_cast(context)); - InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); - if (!imEngine->EnsureResourceForSubscription(_this->mFabricIndex, _this->mAttributePaths.AllocatedSize(), - _this->mEventPaths.AllocatedSize())) + SubscriptionResumptionHelper * _this = static_cast(context); + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; + InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); + if (!imEngine->EnsureResourceForSubscription(subscriptionInfo.mFabricIndex, subscriptionInfo.mAttributePaths.AllocatedSize(), + subscriptionInfo.mEventPaths.AllocatedSize())) { ChipLogProgress(InteractionModel, "no resource for subscription resumption"); + delete _this; return; } ReadHandler * readHandler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); if (readHandler == nullptr) { ChipLogProgress(InteractionModel, "no resource for ReadHandler creation"); + delete _this; return; } readHandler->OnSubscriptionResumed(sessionHandle, *_this); + delete _this; } void SubscriptionResumptionHelper::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) { - Platform::UniquePtr _this(static_cast(context)); + SubscriptionResumptionHelper * _this = static_cast(context); + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", error.Format()); // If the device fails to establish the session, the subscriber might be offline and its subscription read client will - // be deleted after the device reconnect to the subscriber. This subscription will be never used again. So clean up + // be deleted when the device reconnect to the subscriber. This subscription will be never used again. So clean up // the persistent subscription information storage. auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); if (subscriptionResumptionStorage) { - subscriptionResumptionStorage->Delete(_this->mNodeId, _this->mFabricIndex, _this->mSubscriptionId); + subscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex, + subscriptionInfo.mSubscriptionId); } + delete _this; } } // namespace app diff --git a/src/app/SubscriptionResumptionHelper.h b/src/app/SubscriptionResumptionHelper.h index dd865a018a8fdb..700e9aab4045d7 100644 --- a/src/app/SubscriptionResumptionHelper.h +++ b/src/app/SubscriptionResumptionHelper.h @@ -23,23 +23,27 @@ namespace chip { namespace app { -class InteractionModelEngine; -class ReadHandler; -class SubscriptionResumptionHelper : private SubscriptionResumptionStorage::SubscriptionInfo +/** + * Helper to resume persistent subscription. A CASE session will be established upon invoking ResumeSubscription(), + * followed by the creation and intialization of a ReadHandler. This class helps prevent a scenario where all + * ReadHandlers in the pool grab the invalid session handle. In such scenario, if the device receives a new + * subscription request, it will crash as there is no evictable ReadHandler. + */ + +class SubscriptionResumptionHelper { public: SubscriptionResumptionHelper(); ~SubscriptionResumptionHelper() {} -private: - friend class InteractionModelEngine; - friend class ReadHandler; - CHIP_ERROR ResumeSubscription(CASESessionManager & caseSessionManager, - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); + const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); + + SubscriptionResumptionStorage::SubscriptionInfo mSubscriptionInfo; +private: // Callback funstions for continuing the subscription resumption static void HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle); From 8ab71f3a3cc85bc122995cb560f805609d356d7a Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Wed, 6 Dec 2023 11:54:20 +0800 Subject: [PATCH 5/8] Rename Helper to SessionEstablisher --- src/app/BUILD.gn | 4 ++-- src/app/InteractionModelEngine.cpp | 10 +++++----- src/app/InteractionModelEngine.h | 4 ++-- src/app/ReadHandler.cpp | 2 +- src/app/ReadHandler.h | 7 ++++--- ...> SubscriptionResumptionSessionEstablisher.cpp} | 14 +++++++------- ... => SubscriptionResumptionSessionEstablisher.h} | 14 +++++++------- 7 files changed, 28 insertions(+), 27 deletions(-) rename src/app/{SubscriptionResumptionHelper.cpp => SubscriptionResumptionSessionEstablisher.cpp} (85%) rename src/app/{SubscriptionResumptionHelper.h => SubscriptionResumptionSessionEstablisher.h} (74%) diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 95fcb2231f5eb9..9d29ed52e23623 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -237,8 +237,8 @@ static_library("app") { if (chip_persist_subscriptions) { sources += [ - "SubscriptionResumptionHelper.cpp", - "SubscriptionResumptionHelper.h", + "SubscriptionResumptionSessionEstablisher.cpp", + "SubscriptionResumptionSessionEstablisher.h", ] } diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 38b6f676fbf0dc..45f865e22635a7 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -1853,21 +1853,21 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap continue; } - auto subscriptionResumptionHelper = Platform::MakeUnique(); - if (subscriptionResumptionHelper == nullptr) + auto subscriptionResumptionSessionEstablisher = Platform::New(); + if (subscriptionResumptionSessionEstablisher == nullptr) { - ChipLogProgress(InteractionModel, "Failed to create SubscriptionResumptionHelper"); + ChipLogProgress(InteractionModel, "Failed to create SubscriptionResumptionSessionEstablisher"); iterator->Release(); return; } - if (subscriptionResumptionHelper->ResumeSubscription(*imEngine->mpCASESessionMgr, subscriptionInfo) != CHIP_NO_ERROR) + if (subscriptionResumptionSessionEstablisher->ResumeSubscription(*imEngine->mpCASESessionMgr, subscriptionInfo) != CHIP_NO_ERROR) { ChipLogProgress(InteractionModel, "Failed to ResumeSubscription 0x%" PRIx32, subscriptionInfo.mSubscriptionId); iterator->Release(); + Platform::Delete(subscriptionResumptionSessionEstablisher); return; } - subscriptionResumptionHelper.release(); #if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION resumedSubscriptions = true; #endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index 450484c2e6e600..1d69f3f2e305e4 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -378,7 +378,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, friend class reporting::Engine; friend class TestCommandInteraction; friend class TestInteractionModelEngine; - friend class SubscriptionResumptionHelper; + friend class SubscriptionResumptionSessionEstablisher; using Status = Protocols::InteractionModel::Status; void OnDone(CommandHandler & apCommandObj) override; diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 420a02ed55c0db..ca3b042253ca4a 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -88,7 +88,7 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : mObserver = observer; } -void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper) +void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionSessionEstablisher & helper) { mSubscriptionId = helper.mSubscriptionInfo.mSubscriptionId; mMinIntervalFloorSeconds = helper.mSubscriptionInfo.mMinInterval; diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index c4816d9a822eb4..52f200d0c27bfc 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -259,9 +259,10 @@ class ReadHandler : public Messaging::ExchangeDelegate * * @brief Initialize a ReadHandler for a resumed subsciption * - * Used after the SubscriptionResumptionHelper establishs the CASE session + * Used after the SubscriptionResumptionSessionEstablisher establishs the CASE session */ - void OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionHelper & helper); + void OnSubscriptionResumed(const SessionHandle & sessionHandle, + SubscriptionResumptionSessionEstablisher & sessionEstablisher); #endif private: diff --git a/src/app/SubscriptionResumptionHelper.cpp b/src/app/SubscriptionResumptionSessionEstablisher.cpp similarity index 85% rename from src/app/SubscriptionResumptionHelper.cpp rename to src/app/SubscriptionResumptionSessionEstablisher.cpp index 77d71345c31206..a27a55a53d04d6 100644 --- a/src/app/SubscriptionResumptionHelper.cpp +++ b/src/app/SubscriptionResumptionSessionEstablisher.cpp @@ -16,16 +16,16 @@ */ #include -#include +#include namespace chip { namespace app { -SubscriptionResumptionHelper::SubscriptionResumptionHelper() : +SubscriptionResumptionSessionEstablisher::SubscriptionResumptionSessionEstablisher() : mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) {} CHIP_ERROR -SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessionManager, +SubscriptionResumptionSessionEstablisher::ResumeSubscription(CASESessionManager & caseSessionManager, const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) { mSubscriptionInfo.mNodeId = subscriptionInfo.mNodeId; @@ -65,10 +65,10 @@ SubscriptionResumptionHelper::ResumeSubscription(CASESessionManager & caseSessio return CHIP_NO_ERROR; } -void SubscriptionResumptionHelper::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, +void SubscriptionResumptionSessionEstablisher::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle) { - SubscriptionResumptionHelper * _this = static_cast(context); + SubscriptionResumptionSessionEstablisher * _this = static_cast(context); SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); if (!imEngine->EnsureResourceForSubscription(subscriptionInfo.mFabricIndex, subscriptionInfo.mAttributePaths.AllocatedSize(), @@ -89,9 +89,9 @@ void SubscriptionResumptionHelper::HandleDeviceConnected(void * context, Messagi delete _this; } -void SubscriptionResumptionHelper::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) +void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) { - SubscriptionResumptionHelper * _this = static_cast(context); + SubscriptionResumptionSessionEstablisher * _this = static_cast(context); SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", error.Format()); diff --git a/src/app/SubscriptionResumptionHelper.h b/src/app/SubscriptionResumptionSessionEstablisher.h similarity index 74% rename from src/app/SubscriptionResumptionHelper.h rename to src/app/SubscriptionResumptionSessionEstablisher.h index 700e9aab4045d7..d89a1b11fa40b7 100644 --- a/src/app/SubscriptionResumptionHelper.h +++ b/src/app/SubscriptionResumptionSessionEstablisher.h @@ -25,18 +25,18 @@ namespace chip { namespace app { /** - * Helper to resume persistent subscription. A CASE session will be established upon invoking ResumeSubscription(), - * followed by the creation and intialization of a ReadHandler. This class helps prevent a scenario where all - * ReadHandlers in the pool grab the invalid session handle. In such scenario, if the device receives a new - * subscription request, it will crash as there is no evictable ReadHandler. + * Session Esatblisher to resume persistent subscription. A CASE session will be established upon invoking + * ResumeSubscription(), followed by the creation and intialization of a ReadHandler. This class helps prevent + * a scenario where all ReadHandlers in the pool grab the invalid session handle. In such scenario, if the device + * receives a new subscription request, it will crash as there is no evictable ReadHandler. */ -class SubscriptionResumptionHelper +class SubscriptionResumptionSessionEstablisher { public: - SubscriptionResumptionHelper(); + SubscriptionResumptionSessionEstablisher(); - ~SubscriptionResumptionHelper() {} + ~SubscriptionResumptionSessionEstablisher() {} CHIP_ERROR ResumeSubscription(CASESessionManager & caseSessionManager, const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); From d03d9f3f55ebc54887ca3be43a917eaf56e7ae7e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 6 Dec 2023 03:55:23 +0000 Subject: [PATCH 6/8] Restyled by clang-format --- src/app/InteractionModelEngine.cpp | 3 ++- src/app/ReadHandler.h | 3 +-- src/app/SubscriptionResumptionSessionEstablisher.cpp | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 45f865e22635a7..16814cfb6eadc8 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -1861,7 +1861,8 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap return; } - if (subscriptionResumptionSessionEstablisher->ResumeSubscription(*imEngine->mpCASESessionMgr, subscriptionInfo) != CHIP_NO_ERROR) + if (subscriptionResumptionSessionEstablisher->ResumeSubscription(*imEngine->mpCASESessionMgr, subscriptionInfo) != + CHIP_NO_ERROR) { ChipLogProgress(InteractionModel, "Failed to ResumeSubscription 0x%" PRIx32, subscriptionInfo.mSubscriptionId); iterator->Release(); diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 52f200d0c27bfc..28097868c2f79a 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -261,8 +261,7 @@ class ReadHandler : public Messaging::ExchangeDelegate * * Used after the SubscriptionResumptionSessionEstablisher establishs the CASE session */ - void OnSubscriptionResumed(const SessionHandle & sessionHandle, - SubscriptionResumptionSessionEstablisher & sessionEstablisher); + void OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionSessionEstablisher & sessionEstablisher); #endif private: diff --git a/src/app/SubscriptionResumptionSessionEstablisher.cpp b/src/app/SubscriptionResumptionSessionEstablisher.cpp index a27a55a53d04d6..48a4cc4fab4a16 100644 --- a/src/app/SubscriptionResumptionSessionEstablisher.cpp +++ b/src/app/SubscriptionResumptionSessionEstablisher.cpp @@ -25,8 +25,8 @@ SubscriptionResumptionSessionEstablisher::SubscriptionResumptionSessionEstablish {} CHIP_ERROR -SubscriptionResumptionSessionEstablisher::ResumeSubscription(CASESessionManager & caseSessionManager, - const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) +SubscriptionResumptionSessionEstablisher::ResumeSubscription( + CASESessionManager & caseSessionManager, const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) { mSubscriptionInfo.mNodeId = subscriptionInfo.mNodeId; mSubscriptionInfo.mFabricIndex = subscriptionInfo.mFabricIndex; @@ -66,7 +66,7 @@ SubscriptionResumptionSessionEstablisher::ResumeSubscription(CASESessionManager } void SubscriptionResumptionSessionEstablisher::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, - const SessionHandle & sessionHandle) + const SessionHandle & sessionHandle) { SubscriptionResumptionSessionEstablisher * _this = static_cast(context); SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; @@ -89,7 +89,8 @@ void SubscriptionResumptionSessionEstablisher::HandleDeviceConnected(void * cont delete _this; } -void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) +void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, + CHIP_ERROR error) { SubscriptionResumptionSessionEstablisher * _this = static_cast(context); SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; From 4192753b38bf69f3cc5f5d52fa85a29f54e191f8 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 15 Dec 2023 11:11:52 +0800 Subject: [PATCH 7/8] RAII changes --- src/app/InteractionModelEngine.cpp | 26 ++++++++++--- src/app/ReadHandler.cpp | 18 ++++----- ...bscriptionResumptionSessionEstablisher.cpp | 38 ++++++++++++++----- ...SubscriptionResumptionSessionEstablisher.h | 4 +- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 16814cfb6eadc8..742d0422ffd85a 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -41,6 +41,23 @@ namespace chip { namespace app { +class AutoReleaseSubscriptionInfoIterator +{ +public: + AutoReleaseSubscriptionInfoIterator(SubscriptionResumptionStorage::SubscriptionInfoIterator *iterator) : mIterator(iterator) {}; + ~AutoReleaseSubscriptionInfoIterator() + { + mIterator->Release(); + } + + SubscriptionResumptionStorage::SubscriptionInfoIterator *operator->() const + { + return mIterator; + } +private: + SubscriptionResumptionStorage::SubscriptionInfoIterator *mIterator; +}; + using Protocols::InteractionModel::Status; Global sInteractionModelEngine; @@ -1835,7 +1852,7 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap bool resumedSubscriptions = false; #endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo; - auto * iterator = imEngine->mpSubscriptionResumptionStorage->IterateSubscriptions(); + AutoReleaseSubscriptionInfoIterator iterator(imEngine->mpSubscriptionResumptionStorage->IterateSubscriptions()); while (iterator->Next(subscriptionInfo)) { // If subscription happens between reboot and this timer callback, it's already live and should skip resumption @@ -1853,11 +1870,10 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap continue; } - auto subscriptionResumptionSessionEstablisher = Platform::New(); + auto subscriptionResumptionSessionEstablisher = Platform::MakeUnique(); if (subscriptionResumptionSessionEstablisher == nullptr) { ChipLogProgress(InteractionModel, "Failed to create SubscriptionResumptionSessionEstablisher"); - iterator->Release(); return; } @@ -1865,15 +1881,13 @@ void InteractionModelEngine::ResumeSubscriptionsTimerCallback(System::Layer * ap CHIP_NO_ERROR) { ChipLogProgress(InteractionModel, "Failed to ResumeSubscription 0x%" PRIx32, subscriptionInfo.mSubscriptionId); - iterator->Release(); - Platform::Delete(subscriptionResumptionSessionEstablisher); return; } + subscriptionResumptionSessionEstablisher.release(); #if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION resumedSubscriptions = true; #endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION } - iterator->Release(); #if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION // If no persisted subscriptions needed resumption then all resumption retries are done diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index ca3b042253ca4a..55824b70374b33 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -88,18 +88,18 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : mObserver = observer; } -void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionSessionEstablisher & helper) +void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionSessionEstablisher & resumptionSessionEstablisher) { - mSubscriptionId = helper.mSubscriptionInfo.mSubscriptionId; - mMinIntervalFloorSeconds = helper.mSubscriptionInfo.mMinInterval; - mMaxInterval = helper.mSubscriptionInfo.mMaxInterval; - SetStateFlag(ReadHandlerFlags::FabricFiltered, helper.mSubscriptionInfo.mFabricFiltered); + mSubscriptionId = resumptionSessionEstablisher.mSubscriptionInfo.mSubscriptionId; + mMinIntervalFloorSeconds = resumptionSessionEstablisher.mSubscriptionInfo.mMinInterval; + mMaxInterval = resumptionSessionEstablisher.mSubscriptionInfo.mMaxInterval; + SetStateFlag(ReadHandlerFlags::FabricFiltered, resumptionSessionEstablisher.mSubscriptionInfo.mFabricFiltered); // Move dynamically allocated attributes and events from the SubscriptionInfo struct into // the object pool managed by the IM engine - for (size_t i = 0; i < helper.mSubscriptionInfo.mAttributePaths.AllocatedSize(); i++) + for (size_t i = 0; i < resumptionSessionEstablisher.mSubscriptionInfo.mAttributePaths.AllocatedSize(); i++) { - AttributePathParams params = helper.mSubscriptionInfo.mAttributePaths[i].GetParams(); + AttributePathParams params = resumptionSessionEstablisher.mSubscriptionInfo.mAttributePaths[i].GetParams(); CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, params); if (err != CHIP_NO_ERROR) { @@ -107,9 +107,9 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, Sub return; } } - for (size_t i = 0; i < helper.mSubscriptionInfo.mEventPaths.AllocatedSize(); i++) + for (size_t i = 0; i < resumptionSessionEstablisher.mSubscriptionInfo.mEventPaths.AllocatedSize(); i++) { - EventPathParams params = helper.mSubscriptionInfo.mEventPaths[i].GetParams(); + EventPathParams params = resumptionSessionEstablisher.mSubscriptionInfo.mEventPaths[i].GetParams(); CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, params); if (err != CHIP_NO_ERROR) { diff --git a/src/app/SubscriptionResumptionSessionEstablisher.cpp b/src/app/SubscriptionResumptionSessionEstablisher.cpp index 48a4cc4fab4a16..e94bf3a65fe40d 100644 --- a/src/app/SubscriptionResumptionSessionEstablisher.cpp +++ b/src/app/SubscriptionResumptionSessionEstablisher.cpp @@ -20,6 +20,30 @@ namespace chip { namespace app { + +class AutoDeleteEstablisher +{ +public: + AutoDeleteEstablisher(SubscriptionResumptionSessionEstablisher * sessionEstablisher) : mSessionEstablisher(sessionEstablisher) {} + ~AutoDeleteEstablisher() + { + chip::Platform::Delete(mSessionEstablisher); + } + + SubscriptionResumptionSessionEstablisher * operator->() const + { + return mSessionEstablisher; + } + + SubscriptionResumptionSessionEstablisher & operator*() const + { + return *mSessionEstablisher; + } + +private: + SubscriptionResumptionSessionEstablisher * mSessionEstablisher; +}; + SubscriptionResumptionSessionEstablisher::SubscriptionResumptionSessionEstablisher() : mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) {} @@ -68,32 +92,29 @@ SubscriptionResumptionSessionEstablisher::ResumeSubscription( void SubscriptionResumptionSessionEstablisher::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle) { - SubscriptionResumptionSessionEstablisher * _this = static_cast(context); - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; + AutoDeleteEstablisher establisher(static_cast(context)); + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = establisher->mSubscriptionInfo; InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); if (!imEngine->EnsureResourceForSubscription(subscriptionInfo.mFabricIndex, subscriptionInfo.mAttributePaths.AllocatedSize(), subscriptionInfo.mEventPaths.AllocatedSize())) { ChipLogProgress(InteractionModel, "no resource for subscription resumption"); - delete _this; return; } ReadHandler * readHandler = imEngine->mReadHandlers.CreateObject(*imEngine, imEngine->GetReportScheduler()); if (readHandler == nullptr) { ChipLogProgress(InteractionModel, "no resource for ReadHandler creation"); - delete _this; return; } - readHandler->OnSubscriptionResumed(sessionHandle, *_this); - delete _this; + readHandler->OnSubscriptionResumed(sessionHandle, *establisher); } void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) { - SubscriptionResumptionSessionEstablisher * _this = static_cast(context); - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = _this->mSubscriptionInfo; + AutoDeleteEstablisher establisher(static_cast(context)); + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = establisher->mSubscriptionInfo; ChipLogError(DataManagement, "Failed to establish CASE for subscription-resumption with error '%" CHIP_ERROR_FORMAT "'", error.Format()); // If the device fails to establish the session, the subscriber might be offline and its subscription read client will @@ -105,7 +126,6 @@ void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(voi subscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex, subscriptionInfo.mSubscriptionId); } - delete _this; } } // namespace app diff --git a/src/app/SubscriptionResumptionSessionEstablisher.h b/src/app/SubscriptionResumptionSessionEstablisher.h index d89a1b11fa40b7..a66c403c1c11ab 100644 --- a/src/app/SubscriptionResumptionSessionEstablisher.h +++ b/src/app/SubscriptionResumptionSessionEstablisher.h @@ -25,7 +25,7 @@ namespace chip { namespace app { /** - * Session Esatblisher to resume persistent subscription. A CASE session will be established upon invoking + * Session Establisher to resume persistent subscription. A CASE session will be established upon invoking * ResumeSubscription(), followed by the creation and intialization of a ReadHandler. This class helps prevent * a scenario where all ReadHandlers in the pool grab the invalid session handle. In such scenario, if the device * receives a new subscription request, it will crash as there is no evictable ReadHandler. @@ -36,8 +36,6 @@ class SubscriptionResumptionSessionEstablisher public: SubscriptionResumptionSessionEstablisher(); - ~SubscriptionResumptionSessionEstablisher() {} - CHIP_ERROR ResumeSubscription(CASESessionManager & caseSessionManager, const SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); From 8a2aa22275e2bd353d7c6e69ebc8a9cee16b2742 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Dec 2023 03:13:06 +0000 Subject: [PATCH 8/8] Restyled by clang-format --- src/app/InteractionModelEngine.cpp | 15 +++++---------- src/app/ReadHandler.cpp | 3 ++- ...ubscriptionResumptionSessionEstablisher.cpp | 18 +++++------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 742d0422ffd85a..31d5c10b7e0809 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -44,18 +44,13 @@ namespace app { class AutoReleaseSubscriptionInfoIterator { public: - AutoReleaseSubscriptionInfoIterator(SubscriptionResumptionStorage::SubscriptionInfoIterator *iterator) : mIterator(iterator) {}; - ~AutoReleaseSubscriptionInfoIterator() - { - mIterator->Release(); - } + AutoReleaseSubscriptionInfoIterator(SubscriptionResumptionStorage::SubscriptionInfoIterator * iterator) : mIterator(iterator){}; + ~AutoReleaseSubscriptionInfoIterator() { mIterator->Release(); } + + SubscriptionResumptionStorage::SubscriptionInfoIterator * operator->() const { return mIterator; } - SubscriptionResumptionStorage::SubscriptionInfoIterator *operator->() const - { - return mIterator; - } private: - SubscriptionResumptionStorage::SubscriptionInfoIterator *mIterator; + SubscriptionResumptionStorage::SubscriptionInfoIterator * mIterator; }; using Protocols::InteractionModel::Status; diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 55824b70374b33..5ff5576a930300 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -88,7 +88,8 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) : mObserver = observer; } -void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, SubscriptionResumptionSessionEstablisher & resumptionSessionEstablisher) +void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, + SubscriptionResumptionSessionEstablisher & resumptionSessionEstablisher) { mSubscriptionId = resumptionSessionEstablisher.mSubscriptionInfo.mSubscriptionId; mMinIntervalFloorSeconds = resumptionSessionEstablisher.mSubscriptionInfo.mMinInterval; diff --git a/src/app/SubscriptionResumptionSessionEstablisher.cpp b/src/app/SubscriptionResumptionSessionEstablisher.cpp index e94bf3a65fe40d..f0d53566ad6b28 100644 --- a/src/app/SubscriptionResumptionSessionEstablisher.cpp +++ b/src/app/SubscriptionResumptionSessionEstablisher.cpp @@ -24,21 +24,13 @@ namespace app { class AutoDeleteEstablisher { public: - AutoDeleteEstablisher(SubscriptionResumptionSessionEstablisher * sessionEstablisher) : mSessionEstablisher(sessionEstablisher) {} - ~AutoDeleteEstablisher() - { - chip::Platform::Delete(mSessionEstablisher); - } + AutoDeleteEstablisher(SubscriptionResumptionSessionEstablisher * sessionEstablisher) : mSessionEstablisher(sessionEstablisher) + {} + ~AutoDeleteEstablisher() { chip::Platform::Delete(mSessionEstablisher); } - SubscriptionResumptionSessionEstablisher * operator->() const - { - return mSessionEstablisher; - } + SubscriptionResumptionSessionEstablisher * operator->() const { return mSessionEstablisher; } - SubscriptionResumptionSessionEstablisher & operator*() const - { - return *mSessionEstablisher; - } + SubscriptionResumptionSessionEstablisher & operator*() const { return *mSessionEstablisher; } private: SubscriptionResumptionSessionEstablisher * mSessionEstablisher;