From 68f693523a7805cabee6dcb993337cced36245cd Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Wed, 16 Feb 2022 10:39:25 -0800 Subject: [PATCH] Fix issue 15108 (#15230) --Apply ConccreteClusterPath to the IM data version-related APIs. --- src/app/InteractionModelEngine.h | 2 +- src/app/reporting/Engine.cpp | 3 +- src/app/tests/TestReadInteraction.cpp | 2 +- .../tests/integration/chip_im_initiator.cpp | 2 +- .../tests/integration/chip_im_responder.cpp | 2 +- src/app/util/af.h | 2 +- src/app/util/attribute-storage.cpp | 6 ++-- .../util/ember-compatibility-functions.cpp | 31 +++++++++---------- src/controller/tests/data_model/TestRead.cpp | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index 6a7aa18b09404e..4210eab1cbbc71 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -344,6 +344,6 @@ CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDesc /** * Check if the given cluster has the given DataVersion. */ -bool IsClusterDataVersionEqual(EndpointId aEndpointId, ClusterId aClusterId, DataVersion aRequiredVersion); +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion); } // namespace app } // namespace chip diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 5cdd5a8a77cd8b..b0e2da49ed8fc2 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -56,7 +56,8 @@ bool Engine::IsClusterDataVersionMatch(ClusterInfo * aDataVersionFilterList, con if (aPath.mEndpointId == filter->mEndpointId && aPath.mClusterId == filter->mClusterId) { existPathMatch = true; - if (!IsClusterDataVersionEqual(filter->mEndpointId, filter->mClusterId, filter->mDataVersion.Value())) + if (!IsClusterDataVersionEqual(ConcreteClusterPath(filter->mEndpointId, filter->mClusterId), + filter->mDataVersion.Value())) { existVersionMismatch = true; } diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index f5d4130cd3680d..666f598ac58e6a 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -238,7 +238,7 @@ CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescr return AttributeValueEncoder(aAttributeReports, 0, aPath, 0).Encode(kTestFieldValue1); } -bool IsClusterDataVersionEqual(EndpointId aEndpointId, ClusterId aClusterId, DataVersion aRequiredVersion) +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion) { if (kTestDataVersion1 == aRequiredVersion) { diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index 49c43d1f1cbed3..c4784b0b63eb6f 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -668,7 +668,7 @@ CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDesc return CHIP_NO_ERROR; } -bool IsClusterDataVersionEqual(EndpointId aEndpointId, ClusterId aClusterId, DataVersion aRequiredVersion) +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion) { return true; } diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index 8378feb7d9e97c..6efbb2f5e2d915 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -130,7 +130,7 @@ CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDesc return err; } -bool IsClusterDataVersionEqual(EndpointId aEndpointId, ClusterId aClusterId, DataVersion aRequiredVersion) +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion) { return true; } diff --git a/src/app/util/af.h b/src/app/util/af.h index 84e76f7147e713..b35fd63fe0275c 100644 --- a/src/app/util/af.h +++ b/src/app/util/af.h @@ -1401,7 +1401,7 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd); * 2) There is no such server cluster on the given endpoint. * 3) No storage for a data version was provided for the endpoint. */ -chip::DataVersion * emberAfDataVersionStorage(chip::EndpointId endpointId, chip::ClusterId clusterId); +chip::DataVersion * emberAfDataVersionStorage(const chip::app::ConcreteClusterPath & aConcreteClusterPath); namespace chip { namespace app { diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 30cde0131670b1..406307e7339870 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -1427,9 +1427,9 @@ Optional emberAfGetServerAttributeIdByIndex(EndpointId endpoint, Cl return Optional(clusterObj->attributes[attributeIndex].attributeId); } -DataVersion * emberAfDataVersionStorage(chip::EndpointId endpointId, chip::ClusterId clusterId) +DataVersion * emberAfDataVersionStorage(const chip::app::ConcreteClusterPath & aConcreteClusterPath) { - uint16_t index = emberAfIndexFromEndpoint(endpointId); + uint16_t index = emberAfIndexFromEndpoint(aConcreteClusterPath.mEndpointId); if (index == 0xFFFF) { // Unknown endpoint. @@ -1444,7 +1444,7 @@ DataVersion * emberAfDataVersionStorage(chip::EndpointId endpointId, chip::Clust // This does a second walk over endpoints to find the right one, but // probably worth it to avoid duplicating code. - auto clusterIndex = emberAfClusterIndex(endpointId, clusterId, CLUSTER_MASK_SERVER); + auto clusterIndex = emberAfClusterIndex(aConcreteClusterPath.mEndpointId, aConcreteClusterPath.mClusterId, CLUSTER_MASK_SERVER); if (clusterIndex == 0xFF) { // No such cluster on this endpoint. diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index 03b97fe0d4683a..0204d5c0c2dab6 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -278,32 +278,32 @@ Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCom namespace { -CHIP_ERROR ReadClusterDataVersion(const EndpointId & aEndpointId, const ClusterId & aClusterId, DataVersion & aDataVersion) +CHIP_ERROR ReadClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPath, DataVersion & aDataVersion) { - DataVersion * version = emberAfDataVersionStorage(aEndpointId, aClusterId); + DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath); if (version == nullptr) { ChipLogError(DataManagement, "Endpoint %" PRIx16 ", Cluster " ChipLogFormatMEI " not found in ReadClusterDataVersion!", - aEndpointId, ChipLogValueMEI(aClusterId)); + aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId)); return CHIP_ERROR_NOT_FOUND; } aDataVersion = *version; return CHIP_NO_ERROR; } -void IncreaseClusterDataVersion(const EndpointId & aEndpointId, const ClusterId & aClusterId) +void IncreaseClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPath) { - DataVersion * version = emberAfDataVersionStorage(aEndpointId, aClusterId); + DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath); if (version == nullptr) { ChipLogError(DataManagement, "Endpoint %" PRIx16 ", Cluster " ChipLogFormatMEI " not found in IncreaseClusterDataVersion!", - aEndpointId, ChipLogValueMEI(aClusterId)); + aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId)); } else { (*(version))++; - ChipLogDetail(DataManagement, "Endpoint %" PRIx16 ", Cluster " ChipLogFormatMEI " update version to %" PRIx32, aEndpointId, - ChipLogValueMEI(aClusterId), *(version)); + ChipLogDetail(DataManagement, "Endpoint %" PRIx16 ", Cluster " ChipLogFormatMEI " update version to %" PRIx32, + aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId), *(version)); } return; } @@ -416,7 +416,7 @@ CHIP_ERROR ReadViaAccessInterface(FabricIndex aAccessingFabricIndex, bool aIsFab AttributeValueEncoder::AttributeEncodeState state = (aEncoderState == nullptr ? AttributeValueEncoder::AttributeEncodeState() : *aEncoderState); DataVersion version = 0; - ReturnErrorOnFailure(ReadClusterDataVersion(aPath.mEndpointId, aPath.mClusterId, version)); + ReturnErrorOnFailure(ReadClusterDataVersion(aPath, version)); AttributeValueEncoder valueEncoder(aAttributeReports, aAccessingFabricIndex, aPath, version, aIsFabricFiltered, state); CHIP_ERROR err = aAccessInterface->Read(aPath, valueEncoder); @@ -549,7 +549,7 @@ CHIP_ERROR ReadSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, b ReturnErrorOnFailure(attributeDataIBBuilder.GetError()); DataVersion version = 0; - ReturnErrorOnFailure(ReadClusterDataVersion(aPath.mEndpointId, aPath.mClusterId, version)); + ReturnErrorOnFailure(ReadClusterDataVersion(aPath, version)); attributeDataIBBuilder.DataVersion(version); ReturnErrorOnFailure(attributeDataIBBuilder.GetError()); @@ -960,8 +960,7 @@ CHIP_ERROR WriteSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, return apWriteHandler->AddStatus(aPath, Protocols::InteractionModel::Status::NeedsTimedInteraction); } - if (aPath.mDataVersion.HasValue() && - !IsClusterDataVersionEqual(aPath.mEndpointId, aPath.mClusterId, aPath.mDataVersion.Value())) + if (aPath.mDataVersion.HasValue() && !IsClusterDataVersionEqual(aPath, aPath.mDataVersion.Value())) { ChipLogError(DataManagement, "Write Version mismatch for Endpoint %" PRIx16 ", Cluster " ChipLogFormatMEI, aPath.mEndpointId, ChipLogValueMEI(aPath.mClusterId)); @@ -1000,13 +999,13 @@ CHIP_ERROR WriteSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, return apWriteHandler->AddStatus(aPath, status); } -bool IsClusterDataVersionEqual(EndpointId aEndpointId, ClusterId aClusterId, DataVersion aRequiredVersion) +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion) { - DataVersion * version = emberAfDataVersionStorage(aEndpointId, aClusterId); + DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath); if (version == nullptr) { ChipLogError(DataManagement, "Endpoint %" PRIx16 ", Cluster " ChipLogFormatMEI " not found in IsClusterDataVersionEqual!", - aEndpointId, ChipLogValueMEI(aClusterId)); + aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId)); return false; } else @@ -1039,7 +1038,7 @@ void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clust info.mAttributeId = attributeId; info.mEndpointId = endpoint; - IncreaseClusterDataVersion(endpoint, clusterId); + IncreaseClusterDataVersion(ConcreteClusterPath(endpoint, clusterId)); InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info); // Schedule work to run asynchronously on the CHIP thread. The scheduled work won't execute until the current execution context diff --git a/src/controller/tests/data_model/TestRead.cpp b/src/controller/tests/data_model/TestRead.cpp index 5a6c223e0ea4a6..7799519a34001b 100644 --- a/src/controller/tests/data_model/TestRead.cpp +++ b/src/controller/tests/data_model/TestRead.cpp @@ -126,7 +126,7 @@ CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescr return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -bool IsClusterDataVersionEqual(EndpointId aEndpointId, ClusterId aClusterId, DataVersion aRequiredDataVersion) +bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredDataVersion) { if (aRequiredDataVersion == kDataVersion) {