Skip to content

Commit 3665129

Browse files
Remove AttributeList from Device Layer
It was only used in a single place and probably didn't belong in the device layer in the first place. Use a Span instead for DeviceInforProvider::SetUserLabelList. Also simplify DeviceInforProvider::ClearUserLabelList().
1 parent c1f377d commit 3665129

File tree

8 files changed

+17
-344
lines changed

8 files changed

+17
-344
lines changed

src/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ if (chip_build_tests) {
8383
"${chip_root}/src/crypto/tests",
8484
"${chip_root}/src/data-model-providers/codedriven/endpoint/tests",
8585
"${chip_root}/src/inet/tests",
86-
"${chip_root}/src/include/platform/tests",
8786
"${chip_root}/src/lib/address_resolve/tests",
8887
"${chip_root}/src/app/server-cluster/tests",
8988
"${chip_root}/src/lib/asn1/tests",

src/app/clusters/user-label-server/user-label-cluster.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <app/server/Server.h>
2020
#include <clusters/UserLabel/Metadata.h>
2121

22+
#include <array>
23+
2224
namespace chip::app::Clusters {
2325

2426
using namespace UserLabel;
@@ -73,19 +75,6 @@ bool IsValidLabelEntry(const Structs::LabelStruct::Type & entry)
7375
return (entry.label.size() <= kMaxLabelSize) && (entry.value.size() <= kMaxValueSize);
7476
}
7577

76-
bool IsValidLabelEntryList(const LabelList::TypeInfo::DecodableType & list)
77-
{
78-
auto iter = list.begin();
79-
while (iter.Next())
80-
{
81-
if (!IsValidLabelEntry(iter.GetValue()))
82-
{
83-
return false;
84-
}
85-
}
86-
return true;
87-
}
88-
8978
CHIP_ERROR WriteLabelList(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder)
9079
{
9180
DeviceLayer::DeviceInfoProvider * provider = DeviceLayer::GetDeviceInfoProvider();
@@ -96,20 +85,22 @@ CHIP_ERROR WriteLabelList(const ConcreteDataAttributePath & path, AttributeValue
9685

9786
if (!path.IsListItemOperation())
9887
{
99-
DeviceLayer::AttributeList<Structs::LabelStruct::Type, DeviceLayer::kMaxUserLabelListLength> labelList;
88+
size_t numLabels = 0;
89+
std::array<Structs::LabelStruct::Type, DeviceLayer::kMaxUserLabelListLength> labels;
10090
LabelList::TypeInfo::DecodableType decodablelist;
10191

10292
ReturnErrorOnFailure(decoder.Decode(decodablelist));
103-
VerifyOrReturnError(IsValidLabelEntryList(decodablelist), CHIP_IM_GLOBAL_STATUS(ConstraintError));
104-
10593
auto iter = decodablelist.begin();
10694
while (iter.Next())
10795
{
108-
ReturnErrorOnFailure(labelList.add(iter.GetValue()));
96+
auto & label = iter.GetValue();
97+
VerifyOrReturnError(IsValidLabelEntry(label), CHIP_IM_GLOBAL_STATUS(ConstraintError));
98+
VerifyOrReturnError(numLabels < labels.size(), CHIP_ERROR_NO_MEMORY);
99+
labels[numLabels++] = label;
109100
}
110101
ReturnErrorOnFailure(iter.GetStatus());
111102

112-
return provider->SetUserLabelList(endpoint, labelList);
103+
return provider->SetUserLabelList(endpoint, Span(labels.data(), numLabels));
113104
}
114105

115106
if (path.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)

src/include/platform/AttributeList.h

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/include/platform/DeviceInfoProvider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <app/util/basic-types.h>
2525
#include <lib/core/CHIPError.h>
2626
#include <lib/core/CHIPPersistentStorageDelegate.h>
27-
#include <platform/AttributeList.h>
27+
#include <lib/support/Span.h>
2828

2929
namespace chip {
3030
namespace DeviceLayer {
@@ -101,7 +101,7 @@ class DeviceInfoProvider
101101
* @return CHIP_NO_ERROR on success.
102102
* @return CHIP_ERROR if an error occurs.
103103
*/
104-
CHIP_ERROR SetUserLabelList(EndpointId endpoint, const AttributeList<UserLabelType, kMaxUserLabelListLength> & labelList);
104+
CHIP_ERROR SetUserLabelList(EndpointId endpoint, Span<const UserLabelType> labelList);
105105

106106
/**
107107
* @brief Clears the user label list for a specified endpoint.

src/include/platform/PlatformManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#pragma once
2525

26-
#include <platform/AttributeList.h>
2726
#include <platform/CHIPDeviceConfig.h>
2827
#include <platform/CHIPDeviceEvent.h>
2928
#include <system/PlatformEventSupport.h>

src/include/platform/tests/BUILD.gn

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/include/platform/tests/TestAttributeList.cpp

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)