diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 06f3014e21ccf8..d526784770219e 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -1598,14 +1598,15 @@ CHIP_ERROR InteractionModelEngine::ResumeSubscriptions() err = mpSubscriptionResumptionStorage->FindByScopedNodeId(subscriberIndex.mNodes[currentNodeIndex], subscriptions); ReturnLogErrorOnFailure(err); - ChipLogProgress( - InteractionModel, "\tNode " ChipLogFormatScopedNodeId ": Loaded %u subscriptions..", - ChipLogValueScopedNodeId(subscriberIndex.mNodes[currentNodeIndex]), static_cast(subscriptions.mSize)); + ChipLogProgress(InteractionModel, "\tNode " ChipLogFormatScopedNodeId ": Loaded %u subscriptions..", + ChipLogValueScopedNodeId(subscriberIndex.mNodes[currentNodeIndex]), + static_cast(subscriptions.mSize)); for (size_t currentSubscriptionIndex = 0; currentSubscriptionIndex < subscriptions.mSize; currentSubscriptionIndex++) { - SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = subscriptions.mSubscriptions[currentSubscriptionIndex]; - auto requestedAttributePathCount = subscriptionInfo.mAttributePaths.AllocatedCount(); - auto requestedEventPathCount = subscriptionInfo.mEventPaths.AllocatedCount(); + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo = + subscriptions.mSubscriptions[currentSubscriptionIndex]; + auto requestedAttributePathCount = subscriptionInfo.mAttributePaths.AllocatedCount(); + auto requestedEventPathCount = subscriptionInfo.mEventPaths.AllocatedCount(); if (!EnsureResourceForSubscription(subscriptionInfo.mFabricIndex, requestedAttributePathCount, requestedEventPathCount)) { ChipLogProgress(InteractionModel, "no resource for Subscription resumption"); diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index aae5446c389ddc..babeca9e6f0635 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -67,18 +67,20 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback) : mExchangeCtx(*this), mManagementCallback(apCallback), mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this) { - mInteractionType = InteractionType::Subscribe; + mInteractionType = InteractionType::Subscribe; mFlags.ClearAll(); } -void ReadHandler::ResumeSubscription(CASESessionManager *caseSessionManager, SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) +void ReadHandler::ResumeSubscription(CASESessionManager * caseSessionManager, + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo) { mSubscriptionId = subscriptionInfo.mSubscriptionId; mMinIntervalFloorSeconds = subscriptionInfo.mMinInterval; mMaxInterval = subscriptionInfo.mMaxInterval; SetStateFlag(ReadHandlerFlags::FabricFiltered, subscriptionInfo.mFabricFiltered); - // Move dynamically allocated attributes and events from the SubscriptionInfo struct into the object pool managed by the IM engine + // Move dynamically allocated attributes and events from the SubscriptionInfo struct into the object pool managed by the IM + // engine CHIP_ERROR err; for (size_t i = 0; i < subscriptionInfo.mAttributePaths.AllocatedCount(); i++) { diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index fb3281e766baee..04d2f58da7e79f 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -262,7 +263,8 @@ class ReadHandler : public Messaging::ExchangeDelegate * Resume a persisted subscription * */ - void ResumeSubscription(CASESessionManager *caseSessionManager, SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); + void ResumeSubscription(CASESessionManager * caseSessionManager, + SubscriptionResumptionStorage::SubscriptionInfo & subscriptionInfo); #endif /** diff --git a/src/app/SimpleSubscriptionResumptionStorage.cpp b/src/app/SimpleSubscriptionResumptionStorage.cpp index f22efc628d8f4e..2fbccaeedb2e25 100644 --- a/src/app/SimpleSubscriptionResumptionStorage.cpp +++ b/src/app/SimpleSubscriptionResumptionStorage.cpp @@ -81,14 +81,14 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::SaveIndex(const SubscriptionInde return CHIP_NO_ERROR; } -#define DeleteIndexAndReturnLogErrorOnFailure(expr) \ +#define DeleteIndexAndReturnLogErrorOnFailure(expr) \ do \ { \ auto __err = (expr); \ if (!::chip::ChipError::IsSuccess(__err)) \ { \ -mStorage->SyncDeleteKeyValue(DefaultStorageKeyAllocator::SubscriptionResumptionIndex().KeyName()); \ -ChipLogError(DataManagement, "%s at %s:%d", ErrorStr(__err), __FILE__, __LINE__); \ + mStorage->SyncDeleteKeyValue(DefaultStorageKeyAllocator::SubscriptionResumptionIndex().KeyName()); \ + ChipLogError(DataManagement, "%s at %s:%d", ErrorStr(__err), __FILE__, __LINE__); \ return __err; \ } \ } while (false) @@ -132,7 +132,7 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::LoadIndex(SubscriptionIndex & in return CHIP_ERROR_NO_MEMORY; } - index.mNodes = std::unique_ptr(new(std::nothrow) ScopedNodeId[nodeCount + allocateExtraSpace]); + index.mNodes = std::unique_ptr(new (std::nothrow) ScopedNodeId[nodeCount + allocateExtraSpace]); if (!index.mNodes) { mStorage->SyncDeleteKeyValue(DefaultStorageKeyAllocator::SubscriptionResumptionIndex().KeyName()); @@ -166,14 +166,14 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::LoadIndex(SubscriptionIndex & in return CHIP_NO_ERROR; } -#define DeleteSubscriptionsAndReturnLogErrorOnFailure(expr) \ +#define DeleteSubscriptionsAndReturnLogErrorOnFailure(expr) \ do \ { \ auto __err = (expr); \ if (!::chip::ChipError::IsSuccess(__err)) \ { \ -mStorage->SyncDeleteKeyValue(GetStorageKey(node).KeyName()); \ -ChipLogError(DataManagement, "%s at %s:%d", ErrorStr(__err), __FILE__, __LINE__); \ + mStorage->SyncDeleteKeyValue(GetStorageKey(node).KeyName()); \ + ChipLogError(DataManagement, "%s at %s:%d", ErrorStr(__err), __FILE__, __LINE__); \ return __err; \ } \ } while (false) @@ -182,7 +182,8 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::FindByScopedNodeId(ScopedNodeId { return FindByScopedNodeId(node, subscriptions, 0); } -CHIP_ERROR SimpleSubscriptionResumptionStorage::FindByScopedNodeId(ScopedNodeId node, SubscriptionList & subscriptions, size_t allocateExtraSpace) +CHIP_ERROR SimpleSubscriptionResumptionStorage::FindByScopedNodeId(ScopedNodeId node, SubscriptionList & subscriptions, + size_t allocateExtraSpace) { Platform::ScopedMemoryBuffer backingBuffer; backingBuffer.Calloc(MaxStateSize()); @@ -215,7 +216,8 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::FindByScopedNodeId(ScopedNodeId return CHIP_ERROR_NO_MEMORY; } - subscriptions.mSubscriptions = std::unique_ptr(new(std::nothrow) SubscriptionInfo[subscriptionCount + allocateExtraSpace]); + subscriptions.mSubscriptions = + std::unique_ptr(new (std::nothrow) SubscriptionInfo[subscriptionCount + allocateExtraSpace]); if (!subscriptions.mSubscriptions) { mStorage->SyncDeleteKeyValue(GetStorageKey(node).KeyName()); @@ -261,13 +263,16 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::FindByScopedNodeId(ScopedNodeId for (uint16_t currentPathIndex = 0; currentPathIndex < pathCount; currentPathIndex++) { DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kEndpointIdTag)); - DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mEndpointId)); + DeleteSubscriptionsAndReturnLogErrorOnFailure( + reader.Get(subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mEndpointId)); DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kClusterIdTag)); - DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mClusterId)); + DeleteSubscriptionsAndReturnLogErrorOnFailure( + reader.Get(subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mClusterId)); DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kAttributeIdTag)); - DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mAttributeId)); + DeleteSubscriptionsAndReturnLogErrorOnFailure( + reader.Get(subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mAttributeId)); } } @@ -286,16 +291,20 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::FindByScopedNodeId(ScopedNodeId DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kPathTypeTag)); DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(eventPathType)); - subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mIsUrgentEvent = (eventPathType == EventPathType::kUrgent); + subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mIsUrgentEvent = + (eventPathType == EventPathType::kUrgent); DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kEndpointIdTag)); - DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEndpointId)); + DeleteSubscriptionsAndReturnLogErrorOnFailure( + reader.Get(subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEndpointId)); DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kClusterIdTag)); - DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mClusterId)); + DeleteSubscriptionsAndReturnLogErrorOnFailure( + reader.Get(subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mClusterId)); DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Next(kEventIdTag)); - DeleteSubscriptionsAndReturnLogErrorOnFailure(reader.Get(subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEventId)); + DeleteSubscriptionsAndReturnLogErrorOnFailure( + reader.Get(subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEventId)); } } @@ -328,18 +337,23 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::SaveSubscriptions(const ScopedNo ReturnErrorOnFailure(writer.Put(kMaxIntervalTag, subscriptions[currentSubscriptionIndex].mMaxInterval)); ReturnErrorOnFailure(writer.Put(kFabricFilteredTag, subscriptions[currentSubscriptionIndex].mFabricFiltered)); - ReturnErrorOnFailure( - writer.Put(kPathCountTag, static_cast(subscriptions[currentSubscriptionIndex].mAttributePaths.AllocatedCount()))); - for (size_t currentPathIndex = 0; currentPathIndex < subscriptions[currentSubscriptionIndex].mAttributePaths.AllocatedCount(); currentPathIndex++) + ReturnErrorOnFailure(writer.Put( + kPathCountTag, static_cast(subscriptions[currentSubscriptionIndex].mAttributePaths.AllocatedCount()))); + for (size_t currentPathIndex = 0; + currentPathIndex < subscriptions[currentSubscriptionIndex].mAttributePaths.AllocatedCount(); currentPathIndex++) { - ReturnErrorOnFailure(writer.Put(kEndpointIdTag, subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mEndpointId)); - ReturnErrorOnFailure(writer.Put(kClusterIdTag, subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mClusterId)); - ReturnErrorOnFailure(writer.Put(kAttributeIdTag, subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mAttributeId)); + ReturnErrorOnFailure( + writer.Put(kEndpointIdTag, subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mEndpointId)); + ReturnErrorOnFailure( + writer.Put(kClusterIdTag, subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mClusterId)); + ReturnErrorOnFailure(writer.Put( + kAttributeIdTag, subscriptions[currentSubscriptionIndex].mAttributePaths[currentPathIndex].mAttributeId)); } ReturnErrorOnFailure( writer.Put(kPathCountTag, static_cast(subscriptions[currentSubscriptionIndex].mEventPaths.AllocatedCount()))); - for (size_t currentPathIndex = 0; currentPathIndex < subscriptions[currentSubscriptionIndex].mEventPaths.AllocatedCount(); currentPathIndex++) + for (size_t currentPathIndex = 0; currentPathIndex < subscriptions[currentSubscriptionIndex].mEventPaths.AllocatedCount(); + currentPathIndex++) { if (subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mIsUrgentEvent) { @@ -349,9 +363,12 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::SaveSubscriptions(const ScopedNo { ReturnErrorOnFailure(writer.Put(kPathTypeTag, EventPathType::kNonUrgent)); } - ReturnErrorOnFailure(writer.Put(kEndpointIdTag, subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEndpointId)); - ReturnErrorOnFailure(writer.Put(kClusterIdTag, subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mClusterId)); - ReturnErrorOnFailure(writer.Put(kAttributeIdTag, subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEventId)); + ReturnErrorOnFailure( + writer.Put(kEndpointIdTag, subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEndpointId)); + ReturnErrorOnFailure( + writer.Put(kClusterIdTag, subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mClusterId)); + ReturnErrorOnFailure( + writer.Put(kAttributeIdTag, subscriptions[currentSubscriptionIndex].mEventPaths[currentPathIndex].mEventId)); } ReturnErrorOnFailure(writer.EndContainer(subscriptionContainerType)); @@ -388,7 +405,7 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::Save(SubscriptionInfo & subscrip { if (!subscriptionIndex.mSize) { - subscriptionIndex.mNodes = std::unique_ptr(new(std::nothrow) ScopedNodeId[1]); + subscriptionIndex.mNodes = std::unique_ptr(new (std::nothrow) ScopedNodeId[1]); if (!subscriptionIndex.mNodes) { return CHIP_ERROR_NO_MEMORY; @@ -405,7 +422,7 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::Save(SubscriptionInfo & subscrip // Load existing subscriptions for node, then combine and save state SubscriptionList subscriptions; - CHIP_ERROR err = FindByScopedNodeId(subscriptionNode, subscriptions, 1); // ask to allocate 1 extra space for new subscription + CHIP_ERROR err = FindByScopedNodeId(subscriptionNode, subscriptions, 1); // ask to allocate 1 extra space for new subscription if (err != CHIP_NO_ERROR) { return err; @@ -414,7 +431,7 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::Save(SubscriptionInfo & subscrip // if this is the first subscription, allocate space for 1 if (!subscriptions.mSize) { - subscriptions.mSubscriptions = std::unique_ptr(new(std::nothrow) SubscriptionInfo[1]); + subscriptions.mSubscriptions = std::unique_ptr(new (std::nothrow) SubscriptionInfo[1]); if (!subscriptions.mSubscriptions) { return CHIP_ERROR_NO_MEMORY; @@ -547,7 +564,7 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::DeleteAll(FabricIndex fabricInde // Move the last element into this hole and keep looping subscriptionIndex[i] = subscriptionIndex[subscriptionIndex.mSize]; - indexChanged = true; + indexChanged = true; } else { diff --git a/src/app/SubscriptionResumptionStorage.h b/src/app/SubscriptionResumptionStorage.h index 8d857f64d3fb3e..378571585a924e 100644 --- a/src/app/SubscriptionResumptionStorage.h +++ b/src/app/SubscriptionResumptionStorage.h @@ -93,8 +93,8 @@ class SubscriptionResumptionStorage { size_t mSize; std::unique_ptr mSubscriptions; - SubscriptionInfo &operator[](size_t index) { return mSubscriptions[index]; } - const SubscriptionInfo &operator[](size_t index) const { return mSubscriptions[index]; } + SubscriptionInfo & operator[](size_t index) { return mSubscriptions[index]; } + const SubscriptionInfo & operator[](size_t index) const { return mSubscriptions[index]; } }; /** @@ -104,8 +104,8 @@ class SubscriptionResumptionStorage { size_t mSize; std::unique_ptr mNodes; - ScopedNodeId &operator[](size_t index) { return mNodes[index]; } - const ScopedNodeId &operator[](size_t index) const { return mNodes[index]; } + ScopedNodeId & operator[](size_t index) { return mNodes[index]; } + const ScopedNodeId & operator[](size_t index) const { return mNodes[index]; } }; virtual ~SubscriptionResumptionStorage(){}; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 449a987fef1363..fc6665deb552e5 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -487,8 +487,7 @@ void Server::ResumeSubscriptions() CHIP_ERROR err = chip::app::InteractionModelEngine::GetInstance()->ResumeSubscriptions(); if (err != CHIP_NO_ERROR) { - ChipLogError(AppServer, "Error when trying to resume subscriptions : %" CHIP_ERROR_FORMAT, - err.Format()); + ChipLogError(AppServer, "Error when trying to resume subscriptions : %" CHIP_ERROR_FORMAT, err.Format()); } #endif }