From 154230102141917f4da776717c55213d77a720ed Mon Sep 17 00:00:00 2001 From: mideayanghui <106149377+mideayanghui@users.noreply.github.com> Date: Mon, 28 Aug 2023 23:18:17 +0800 Subject: [PATCH] [fix] optimize tag list api in descriptor cluster (#28907) * optimize tag list api in descriptor cluster * Restyled by clang-format * Update src/app/clusters/descriptor/descriptor.cpp Co-authored-by: Boris Zbarsky * Update attribute-storage.cpp * Update attribute-storage.h * fix build error * Restyled by clang-format --------- Co-authored-by: Restyled.io Co-authored-by: Boris Zbarsky --- src/app/clusters/descriptor/descriptor.cpp | 11 +++++------ src/app/util/af-types.h | 2 +- src/app/util/attribute-storage.cpp | 4 ++-- src/app/util/attribute-storage.h | 10 +++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app/clusters/descriptor/descriptor.cpp b/src/app/clusters/descriptor/descriptor.cpp index 9d530b4f0f6df2..8b7880745591be 100644 --- a/src/app/clusters/descriptor/descriptor.cpp +++ b/src/app/clusters/descriptor/descriptor.cpp @@ -20,7 +20,6 @@ * @brief Implementation for the Descriptor Server Cluster ***************************************************************************/ -#include #include #include #include @@ -48,7 +47,7 @@ class DescriptorAttrAccess : public AttributeAccessInterface private: static constexpr uint16_t ClusterRevision = 2; - CHIP_ERROR ReadTagAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder); + CHIP_ERROR ReadTagListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadPartsAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadDeviceAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadClientServerAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server); @@ -64,20 +63,20 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa size_t index = 0; BitFlags featureFlags; - if (GetTagListFromEndpointAtIndex(endpoint, index, tag) == CHIP_NO_ERROR) + if (GetSemanticTagForEndpointAtIndex(endpoint, index, tag) == CHIP_NO_ERROR) { featureFlags.Set(Feature::kTagList); } return aEncoder.Encode(featureFlags); } -CHIP_ERROR DescriptorAttrAccess::ReadTagAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder) +CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder) { return aEncoder.EncodeList([&endpoint](const auto & encoder) -> CHIP_ERROR { Clusters::Descriptor::Structs::SemanticTagStruct::Type tag; size_t index = 0; CHIP_ERROR err = CHIP_NO_ERROR; - while ((err = GetTagListFromEndpointAtIndex(endpoint, index, tag)) == CHIP_NO_ERROR) + while ((err = GetSemanticTagForEndpointAtIndex(endpoint, index, tag)) == CHIP_NO_ERROR) { ReturnErrorOnFailure(encoder.Encode(tag)); index++; @@ -227,7 +226,7 @@ CHIP_ERROR DescriptorAttrAccess::Read(const ConcreteReadAttributePath & aPath, A return ReadPartsAttribute(aPath.mEndpointId, aEncoder); } case TagList::Id: { - return ReadTagAttribute(aPath.mEndpointId, aEncoder); + return ReadTagListAttribute(aPath.mEndpointId, aEncoder); } case ClusterRevision::Id: { return ReadClusterRevision(aPath.mEndpointId, aEncoder); diff --git a/src/app/util/af-types.h b/src/app/util/af-types.h index 7f0a785493c264..d154399a6973a6 100644 --- a/src/app/util/af-types.h +++ b/src/app/util/af-types.h @@ -224,7 +224,7 @@ struct EmberAfDefinedEndpoint chip::EndpointId parentEndpointId = chip::kInvalidEndpointId; /** - * Span pointing to a list of tag. Lifetime has to outlive usage, and data is owned by callers. + * Span pointing to a list of tags. Lifetime has to outlive usage, and data is owned by callers. */ chip::Span tagList; }; diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index f124f74583b6fa..0662ddcaa008b2 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -1088,8 +1088,8 @@ chip::Span emberAfDeviceTypeListFromEndpoint(chip::Endp return emAfEndpoints[endpointIndex].deviceTypeList; } -CHIP_ERROR GetTagListFromEndpointAtIndex(EndpointId endpoint, size_t index, - Clusters::Descriptor::Structs::SemanticTagStruct::Type & tag) +CHIP_ERROR GetSemanticTagForEndpointAtIndex(EndpointId endpoint, size_t index, + Clusters::Descriptor::Structs::SemanticTagStruct::Type & tag) { uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint); diff --git a/src/app/util/attribute-storage.h b/src/app/util/attribute-storage.h index c33103de7443bd..16003affa26a95 100644 --- a/src/app/util/attribute-storage.h +++ b/src/app/util/attribute-storage.h @@ -202,7 +202,7 @@ const EmberAfCluster * emberAfGetClusterByIndex(chip::EndpointId endpoint, uint8 chip::Span emberAfDeviceTypeListFromEndpoint(chip::EndpointId endpoint, CHIP_ERROR & err); /** - * Get the tag list of endpoint. + * Get the semantic tags of the endpoint. * Fills in the provided SemanticTagStruct with tag at index `index` if there is one, * or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of tag, * or returns CHIP_ERROR_NOT_FOUND if the endpoint is invalid. @@ -210,11 +210,11 @@ chip::Span emberAfDeviceTypeListFromEndpoint(chip::Endp * @param index The index of the tag, with 0 representing the first tag. * @param tag The SemanticTagStruct is filled. */ -CHIP_ERROR GetTagListFromEndpointAtIndex(chip::EndpointId endpoint, size_t index, - chip::app::Clusters::Descriptor::Structs::SemanticTagStruct::Type & tag); +CHIP_ERROR GetSemanticTagForEndpointAtIndex(chip::EndpointId endpoint, size_t index, + chip::app::Clusters::Descriptor::Structs::SemanticTagStruct::Type & tag); // -// Over-ride the device type list current associated with an endpoint with a user-provided list. The buffers backing +// Override the device type list current associated with an endpoint with a user-provided list. The buffers backing // that list have to live as long as the endpoint is enabled. // // NOTE: It is the application's responsibility to free the existing list that is being replaced if needed. @@ -222,7 +222,7 @@ CHIP_ERROR GetTagListFromEndpointAtIndex(chip::EndpointId endpoint, size_t index CHIP_ERROR emberAfSetDeviceTypeList(chip::EndpointId endpoint, chip::Span deviceTypeList); // -// Over-ride the tag list current associated with an endpoint with a user-provided list. The buffers backing +// Override the tag list current associated with an endpoint with a user-provided list. The buffers backing // that list have to live as long as the endpoint is enabled. // // NOTE: It is the application's responsibility to free the existing list that is being replaced if needed.