Skip to content

Commit

Permalink
[fix] optimize tag list api in descriptor cluster (#28907)
Browse files Browse the repository at this point in the history
* optimize tag list api in descriptor cluster

* Restyled by clang-format

* Update src/app/clusters/descriptor/descriptor.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update attribute-storage.cpp

* Update attribute-storage.h

* fix build error

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Apr 9, 2024
1 parent 98a09b0 commit 76fa5e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* @brief Implementation for the Descriptor Server Cluster
***************************************************************************/

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
Expand Down Expand Up @@ -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);
Expand All @@ -64,20 +63,20 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa
size_t index = 0;
BitFlags<Feature> 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++;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const chip::app::Clusters::Descriptor::Structs::SemanticTagStruct::Type> tagList;
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,8 @@ chip::Span<const EmberAfDeviceType> 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);

Expand Down
10 changes: 5 additions & 5 deletions src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,27 @@ const EmberAfCluster * emberAfGetClusterByIndex(chip::EndpointId endpoint, uint8
chip::Span<const EmberAfDeviceType> 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.
* @param endpoint The target endpoint.
* @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.
//
CHIP_ERROR emberAfSetDeviceTypeList(chip::EndpointId endpoint, chip::Span<const EmberAfDeviceType> 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.
Expand Down

0 comments on commit 76fa5e4

Please sign in to comment.