Skip to content

Commit 43f37d1

Browse files
andy31415tcarmelveilleuxjmartinez-silabsandreilitvin
authored
Update metadata-tree from MetadaList Foo(path) to CHIP_ERROR Foo(path, ListBuilder &) (project-chip#37127)
* Append-only API update: use CHIP_ERROR and builders for MetadataTree * Fix includes * Remove odd comment * ScopedSpan == ReadOnlyBuffer and Build == TakeBuffer * Update src/app/InteractionModelEngine.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Update src/app/clusters/descriptor/descriptor.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Update src/app/clusters/descriptor/descriptor.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Update src/app/clusters/descriptor/descriptor.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Update src/app/clusters/descriptor/descriptor.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Update src/app/clusters/descriptor/descriptor.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Update src/app/data-model-provider/MetadataList.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Replaced a lot of auto with const auto for readability * Update src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Remove old comment * Fix some typos * Fix typo * Update src/app/data-model-provider/MetadataTypes.h Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> --------- Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent b2b6275 commit 43f37d1

17 files changed

+787
-891
lines changed

src/access/ProviderDeviceTypeResolver.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#pragma once
1717

1818
#include <access/AccessControl.h>
19+
#include <app/data-model-provider/MetadataList.h>
20+
#include <app/data-model-provider/MetadataTypes.h>
1921
#include <app/data-model-provider/Provider.h>
2022

2123
namespace chip {
@@ -31,8 +33,9 @@ class DynamicProviderDeviceTypeResolver : public chip::Access::AccessControl::De
3133

3234
bool IsDeviceTypeOnEndpoint(chip::DeviceTypeId deviceType, chip::EndpointId endpoint) override
3335
{
34-
auto deviceTypes = mModelGetter()->DeviceTypes(endpoint);
35-
for (auto & type : deviceTypes.GetSpanValidForLifetime())
36+
app::DataModel::ListBuilder<app::DataModel::DeviceTypeEntry> builder;
37+
(void) mModelGetter()->DeviceTypes(endpoint, builder);
38+
for (auto & type : builder.TakeBuffer())
3639
{
3740
if (type.deviceTypeId == deviceType)
3841
{

src/app/AttributePathExpandIterator.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <app/AttributePathExpandIterator.h>
1818

1919
#include <app/GlobalAttributes.h>
20+
#include <app/data-model-provider/MetadataList.h>
2021
#include <app/data-model-provider/MetadataLookup.h>
2122
#include <app/data-model-provider/MetadataTypes.h>
2223
#include <lib/core/DataModelTypes.h>
@@ -139,13 +140,13 @@ std::optional<AttributeId> AttributePathExpandIterator::NextAttributeId()
139140
if (mAttributeIndex == kInvalidIndex)
140141
{
141142
// start a new iteration of attributes on the current cluster path.
142-
mAttributes = mDataModelProvider->Attributes(mPosition.mOutputPath);
143+
mAttributes = mDataModelProvider->AttributesIgnoreError(mPosition.mOutputPath);
143144

144145
if (mPosition.mOutputPath.mAttributeId != kInvalidAttributeId)
145146
{
146147
// Position on the correct attribute if we have a start point
147148
mAttributeIndex = 0;
148-
while ((mAttributeIndex < mAttributes.Size()) &&
149+
while ((mAttributeIndex < mAttributes.size()) &&
149150
(mAttributes[mAttributeIndex].attributeId != mPosition.mOutputPath.mAttributeId))
150151
{
151152
mAttributeIndex++;
@@ -199,7 +200,7 @@ std::optional<AttributeId> AttributePathExpandIterator::NextAttributeId()
199200
return std::nullopt;
200201
}
201202

202-
if (mAttributeIndex < mAttributes.Size())
203+
if (mAttributeIndex < mAttributes.size())
203204
{
204205
return mAttributes[mAttributeIndex].attributeId;
205206
}
@@ -222,13 +223,13 @@ std::optional<ClusterId> AttributePathExpandIterator::NextClusterId()
222223
if (mClusterIndex == kInvalidIndex)
223224
{
224225
// start a new iteration on the current endpoint
225-
mClusters = mDataModelProvider->ServerClusters(mPosition.mOutputPath.mEndpointId);
226+
mClusters = mDataModelProvider->ServerClustersIgnoreError(mPosition.mOutputPath.mEndpointId);
226227

227228
if (mPosition.mOutputPath.mClusterId != kInvalidClusterId)
228229
{
229230
// Position on the correct cluster if we have a start point
230231
mClusterIndex = 0;
231-
while ((mClusterIndex < mClusters.Size()) && (mClusters[mClusterIndex].clusterId != mPosition.mOutputPath.mClusterId))
232+
while ((mClusterIndex < mClusters.size()) && (mClusters[mClusterIndex].clusterId != mPosition.mOutputPath.mClusterId))
232233
{
233234
mClusterIndex++;
234235
}
@@ -248,10 +249,8 @@ std::optional<ClusterId> AttributePathExpandIterator::NextClusterId()
248249
{
249250
const ClusterId clusterId = mPosition.mAttributePath->mValue.mClusterId;
250251

251-
auto span = mClusters.GetSpanValidForLifetime();
252-
253252
bool found = false;
254-
for (auto & entry : span)
253+
for (auto & entry : mClusters)
255254
{
256255
if (entry.clusterId == clusterId)
257256
{
@@ -276,7 +275,7 @@ std::optional<ClusterId> AttributePathExpandIterator::NextClusterId()
276275
}
277276

278277
VerifyOrReturnValue(mPosition.mAttributePath->mValue.HasWildcardClusterId(), std::nullopt);
279-
VerifyOrReturnValue(mClusterIndex < mClusters.Size(), std::nullopt);
278+
VerifyOrReturnValue(mClusterIndex < mClusters.size(), std::nullopt);
280279

281280
return mClusters[mClusterIndex].clusterId;
282281
}
@@ -286,13 +285,13 @@ std::optional<EndpointId> AttributePathExpandIterator::NextEndpointId()
286285
if (mEndpointIndex == kInvalidIndex)
287286
{
288287
// index is missing, have to start a new iteration
289-
mEndpoints = mDataModelProvider->Endpoints();
288+
mEndpoints = mDataModelProvider->EndpointsIgnoreError();
290289

291290
if (mPosition.mOutputPath.mEndpointId != kInvalidEndpointId)
292291
{
293292
// Position on the correct endpoint if we have a start point
294293
mEndpointIndex = 0;
295-
while ((mEndpointIndex < mEndpoints.Size()) && (mEndpoints[mEndpointIndex].id != mPosition.mOutputPath.mEndpointId))
294+
while ((mEndpointIndex < mEndpoints.size()) && (mEndpoints[mEndpointIndex].id != mPosition.mOutputPath.mEndpointId))
296295
{
297296
mEndpointIndex++;
298297
}
@@ -315,7 +314,7 @@ std::optional<EndpointId> AttributePathExpandIterator::NextEndpointId()
315314
}
316315

317316
VerifyOrReturnValue(mPosition.mAttributePath->mValue.HasWildcardEndpointId(), std::nullopt);
318-
VerifyOrReturnValue(mEndpointIndex < mEndpoints.Size(), std::nullopt);
317+
VerifyOrReturnValue(mEndpointIndex < mEndpoints.size(), std::nullopt);
319318

320319
return mEndpoints[mEndpointIndex].id;
321320
}

src/app/AttributePathExpandIterator.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ class AttributePathExpandIterator
121121
DataModel::Provider * mDataModelProvider;
122122
Position & mPosition;
123123

124-
DataModel::MetadataList<DataModel::EndpointEntry> mEndpoints; // all endpoints
124+
DataModel::ReadOnlyBuffer<DataModel::EndpointEntry> mEndpoints; // all endpoints
125125
size_t mEndpointIndex = kInvalidIndex;
126126

127-
DataModel::MetadataList<DataModel::ServerClusterEntry> mClusters; // all clusters ON THE CURRENT endpoint
127+
DataModel::ReadOnlyBuffer<DataModel::ServerClusterEntry> mClusters; // all clusters ON THE CURRENT endpoint
128128
size_t mClusterIndex = kInvalidIndex;
129129

130-
DataModel::MetadataList<DataModel::AttributeEntry> mAttributes; // all attributes ON THE CURRENT cluster
130+
DataModel::ReadOnlyBuffer<DataModel::AttributeEntry> mAttributes; // all attributes ON THE CURRENT cluster
131131
size_t mAttributeIndex = kInvalidIndex;
132132

133133
/// Move to the next endpoint/cluster/attribute triplet that is valid given

src/app/InteractionModelEngine.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
#include <app/EventPathParams.h>
3838
#include <app/RequiredPrivilege.h>
3939
#include <app/data-model-provider/ActionReturnStatus.h>
40+
#include <app/data-model-provider/MetadataList.h>
4041
#include <app/data-model-provider/MetadataLookup.h>
4142
#include <app/data-model-provider/MetadataTypes.h>
4243
#include <app/data-model-provider/OperationTypes.h>
44+
#include <app/data-model/List.h>
4345
#include <app/util/IMClusterCommandHandler.h>
4446
#include <app/util/af-types.h>
4547
#include <app/util/endpoint-config-api.h>
@@ -91,8 +93,7 @@ bool MayHaveAccessibleEventPathForEndpoint(DataModel::Provider * aProvider, Endp
9193
aSubjectDescriptor);
9294
}
9395

94-
auto serverClusters = aProvider->ServerClusters(aEventPath.mEndpointId);
95-
for (auto & cluster : serverClusters.GetSpanValidForLifetime())
96+
for (auto & cluster : aProvider->ServerClustersIgnoreError(aEventPath.mEndpointId))
9697
{
9798
if (MayHaveAccessibleEventPathForEndpointAndCluster(ConcreteClusterPath(aEventPath.mEndpointId, cluster.clusterId),
9899
aEventPath, aSubjectDescriptor))
@@ -114,8 +115,7 @@ bool MayHaveAccessibleEventPath(DataModel::Provider * aProvider, const EventPath
114115
return MayHaveAccessibleEventPathForEndpoint(aProvider, aEventPath.mEndpointId, aEventPath, subjectDescriptor);
115116
}
116117

117-
auto endpoints = aProvider->Endpoints();
118-
for (const DataModel::EndpointEntry & ep : endpoints.GetSpanValidForLifetime())
118+
for (const DataModel::EndpointEntry & ep : aProvider->EndpointsIgnoreError())
119119
{
120120
if (MayHaveAccessibleEventPathForEndpoint(aProvider, ep.id, aEventPath, subjectDescriptor))
121121
{
@@ -1790,8 +1790,9 @@ Protocols::InteractionModel::Status InteractionModelEngine::CheckCommandExistenc
17901790
{
17911791
auto provider = GetDataModelProvider();
17921792

1793-
DataModel::MetadataList<DataModel::AcceptedCommandEntry> acceptedCommands = provider->AcceptedCommands(aCommandPath);
1794-
for (auto & existing : acceptedCommands.GetSpanValidForLifetime())
1793+
DataModel::ListBuilder<DataModel::AcceptedCommandEntry> acceptedCommands;
1794+
(void) provider->AcceptedCommands(aCommandPath, acceptedCommands);
1795+
for (auto & existing : acceptedCommands.TakeBuffer())
17951796
{
17961797
if (existing.commandId == aCommandPath.mCommandId)
17971798
{

src/app/clusters/descriptor/descriptor.cpp

+45-35
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#include <app/AttributeAccessInterface.h>
2424
#include <app/AttributeAccessInterfaceRegistry.h>
2525
#include <app/InteractionModelEngine.h>
26+
#include <app/data-model-provider/MetadataList.h>
2627
#include <app/data-model-provider/MetadataTypes.h>
28+
#include <app/data-model/List.h>
2729
#include <app/util/attribute-storage.h>
2830
#include <app/util/endpoint-config-api.h>
2931
#include <lib/core/CHIPError.h>
@@ -60,7 +62,7 @@ bool IsDescendantOf(const DataModel::EndpointEntry * __restrict__ childEndpoint,
6062
childEndpoint = nullptr; // we will look it up again
6163

6264
// find the requested value in the array to get its parent
63-
for (auto & ep : allEndpoints)
65+
for (const auto & ep : allEndpoints)
6466
{
6567
if (ep.id == lookupId)
6668
{
@@ -83,7 +85,8 @@ class DescriptorAttrAccess : public AttributeAccessInterface
8385
CHIP_ERROR ReadTagListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder);
8486
CHIP_ERROR ReadPartsAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder);
8587
CHIP_ERROR ReadDeviceAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder);
86-
CHIP_ERROR ReadClientServerAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server);
88+
CHIP_ERROR ReadClientClusters(EndpointId endpoint, AttributeValueEncoder & aEncoder);
89+
CHIP_ERROR ReadServerClusters(EndpointId endpoint, AttributeValueEncoder & aEncoder);
8790
CHIP_ERROR ReadClusterRevision(EndpointId endpoint, AttributeValueEncoder & aEncoder);
8891
CHIP_ERROR ReadFeatureMap(EndpointId endpoint, AttributeValueEncoder & aEncoder);
8992
};
@@ -103,9 +106,11 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa
103106

104107
CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
105108
{
106-
return aEncoder.EncodeList([&endpoint](const auto & encoder) -> CHIP_ERROR {
107-
auto tags = InteractionModelEngine::GetInstance()->GetDataModelProvider()->SemanticTags(endpoint);
108-
for (auto & tag : tags.GetSpanValidForLifetime())
109+
DataModel::ListBuilder<DataModel::Provider::SemanticTag> semanticTagsList;
110+
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->SemanticTags(endpoint, semanticTagsList));
111+
112+
return aEncoder.EncodeList([&semanticTagsList](const auto & encoder) -> CHIP_ERROR {
113+
for (const auto & tag : semanticTagsList.TakeBuffer())
109114
{
110115
ReturnErrorOnFailure(encoder.Encode(tag));
111116
}
@@ -115,11 +120,13 @@ CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, Attri
115120

116121
CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
117122
{
118-
auto endpoints = InteractionModelEngine::GetInstance()->GetDataModelProvider()->Endpoints();
123+
DataModel::ListBuilder<DataModel::EndpointEntry> endpointsList;
124+
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->Endpoints(endpointsList));
125+
auto endpoints = endpointsList.TakeBuffer();
119126
if (endpoint == 0x00)
120127
{
121128
return aEncoder.EncodeList([&endpoints](const auto & encoder) -> CHIP_ERROR {
122-
for (auto & ep : endpoints.GetSpanValidForLifetime())
129+
for (const auto & ep : endpoints)
123130
{
124131
if (ep.id == 0)
125132
{
@@ -133,15 +140,15 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
133140

134141
// find the given endpoint
135142
unsigned idx = 0;
136-
while (idx < endpoints.Size())
143+
while (idx < endpoints.size())
137144
{
138145
if (endpoints[idx].id == endpoint)
139146
{
140147
break;
141148
}
142149
idx++;
143150
}
144-
if (idx >= endpoints.Size())
151+
if (idx >= endpoints.size())
145152
{
146153
// not found
147154
return CHIP_ERROR_NOT_FOUND;
@@ -154,9 +161,9 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
154161
case DataModel::EndpointCompositionPattern::kFullFamily:
155162
// encodes ALL endpoints that have the specified endpoint as a descendant
156163
return aEncoder.EncodeList([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
157-
for (auto & ep : endpoints.GetSpanValidForLifetime())
164+
for (const auto & ep : endpoints)
158165
{
159-
if (IsDescendantOf(&ep, endpoint, endpoints.GetSpanValidForLifetime()))
166+
if (IsDescendantOf(&ep, endpoint, endpoints))
160167
{
161168
ReturnErrorOnFailure(encoder.Encode(ep.id));
162169
}
@@ -166,7 +173,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
166173

167174
case DataModel::EndpointCompositionPattern::kTree:
168175
return aEncoder.EncodeList([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
169-
for (auto & ep : endpoints.GetSpanValidForLifetime())
176+
for (const auto & ep : endpoints)
170177
{
171178
if (ep.parentId != endpoint)
172179
{
@@ -184,11 +191,14 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
184191

185192
CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
186193
{
187-
CHIP_ERROR err = aEncoder.EncodeList([&endpoint](const auto & encoder) -> CHIP_ERROR {
188-
Descriptor::Structs::DeviceTypeStruct::Type deviceStruct;
194+
DataModel::ListBuilder<DataModel::DeviceTypeEntry> deviceTypesList;
195+
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->DeviceTypes(endpoint, deviceTypesList));
189196

190-
auto deviceTypes = InteractionModelEngine::GetInstance()->GetDataModelProvider()->DeviceTypes(endpoint);
191-
for (auto & type : deviceTypes.GetSpanValidForLifetime())
197+
auto deviceTypes = deviceTypesList.TakeBuffer();
198+
199+
CHIP_ERROR err = aEncoder.EncodeList([&deviceTypes](const auto & encoder) -> CHIP_ERROR {
200+
Descriptor::Structs::DeviceTypeStruct::Type deviceStruct;
201+
for (const auto & type : deviceTypes)
192202
{
193203
deviceStruct.deviceType = type.deviceTypeId;
194204
deviceStruct.revision = type.deviceTypeRevision;
@@ -201,30 +211,30 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
201211
return err;
202212
}
203213

204-
CHIP_ERROR DescriptorAttrAccess::ReadClientServerAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server)
214+
CHIP_ERROR DescriptorAttrAccess::ReadServerClusters(EndpointId endpoint, AttributeValueEncoder & aEncoder)
205215
{
206-
CHIP_ERROR err = aEncoder.EncodeList([&endpoint, server](const auto & encoder) -> CHIP_ERROR {
207-
if (server)
216+
DataModel::ListBuilder<DataModel::ServerClusterEntry> builder;
217+
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->ServerClusters(endpoint, builder));
218+
return aEncoder.EncodeList([&builder](const auto & encoder) -> CHIP_ERROR {
219+
for (const auto & cluster : builder.TakeBuffer())
208220
{
209-
auto clusters = InteractionModelEngine::GetInstance()->GetDataModelProvider()->ServerClusters(endpoint);
210-
for (auto & cluster : clusters.GetSpanValidForLifetime())
211-
{
212-
ReturnErrorOnFailure(encoder.Encode(cluster.clusterId));
213-
}
221+
ReturnErrorOnFailure(encoder.Encode(cluster.clusterId));
214222
}
215-
else
223+
return CHIP_NO_ERROR;
224+
});
225+
}
226+
227+
CHIP_ERROR DescriptorAttrAccess::ReadClientClusters(EndpointId endpoint, AttributeValueEncoder & aEncoder)
228+
{
229+
DataModel::ListBuilder<ClusterId> clusterIdList;
230+
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->ClientClusters(endpoint, clusterIdList));
231+
return aEncoder.EncodeList([&clusterIdList](const auto & encoder) -> CHIP_ERROR {
232+
for (const auto & id : clusterIdList.TakeBuffer())
216233
{
217-
auto clusters = InteractionModelEngine::GetInstance()->GetDataModelProvider()->ClientClusters(endpoint);
218-
for (auto & id : clusters.GetSpanValidForLifetime())
219-
{
220-
ReturnErrorOnFailure(encoder.Encode(id));
221-
}
234+
ReturnErrorOnFailure(encoder.Encode(id));
222235
}
223-
224236
return CHIP_NO_ERROR;
225237
});
226-
227-
return err;
228238
}
229239

230240
CHIP_ERROR DescriptorAttrAccess::ReadClusterRevision(EndpointId endpoint, AttributeValueEncoder & aEncoder)
@@ -244,10 +254,10 @@ CHIP_ERROR DescriptorAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
244254
return ReadDeviceAttribute(aPath.mEndpointId, aEncoder);
245255
}
246256
case ServerList::Id: {
247-
return ReadClientServerAttribute(aPath.mEndpointId, aEncoder, true);
257+
return ReadServerClusters(aPath.mEndpointId, aEncoder);
248258
}
249259
case ClientList::Id: {
250-
return ReadClientServerAttribute(aPath.mEndpointId, aEncoder, false);
260+
return ReadClientClusters(aPath.mEndpointId, aEncoder);
251261
}
252262
case PartsList::Id: {
253263
return ReadPartsAttribute(aPath.mEndpointId, aEncoder);

src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818

19+
#include "app/data-model-provider/MetadataList.h"
1920
#include <app-common/zap-generated/attributes/Accessors.h>
2021
#include <app/AttributeAccessInterfaceRegistry.h>
2122
#include <app/CommandHandlerInterfaceRegistry.h>
@@ -249,15 +250,17 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
249250

250251
if (startAfterSetting.HasValue())
251252
{
252-
DataModel::MetadataList<DataModel::AcceptedCommandEntry> acceptedCommands =
253-
InteractionModelEngine::GetInstance()->GetDataModelProvider()->AcceptedCommands(
254-
ConcreteClusterPath(mEndpointId, OperationalState::Id));
255-
Span<const DataModel::AcceptedCommandEntry> acceptedCommandsSpan = acceptedCommands.GetSpanValidForLifetime();
256-
257-
bool commandExists = std::find_if(acceptedCommandsSpan.begin(), acceptedCommandsSpan.end(),
258-
[](const DataModel::AcceptedCommandEntry & entry) {
259-
return entry.commandId == OperationalState::Commands::Start::Id;
260-
}) != acceptedCommandsSpan.end();
253+
254+
DataModel::ListBuilder<DataModel::AcceptedCommandEntry> acceptedCommandsList;
255+
256+
InteractionModelEngine::GetInstance()->GetDataModelProvider()->AcceptedCommands(
257+
ConcreteClusterPath(mEndpointId, OperationalState::Id), acceptedCommandsList);
258+
auto acceptedCommands = acceptedCommandsList.TakeBuffer();
259+
260+
bool commandExists =
261+
std::find_if(acceptedCommands.begin(), acceptedCommands.end(), [](const DataModel::AcceptedCommandEntry & entry) {
262+
return entry.commandId == OperationalState::Commands::Start::Id;
263+
}) != acceptedCommands.end();
261264

262265
VerifyOrExit(
263266
commandExists, status = Status::InvalidCommand; ChipLogError(

src/app/data-model-provider/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ source_set("data-model-provider") {
2525
"MetadataList.h",
2626
"MetadataLookup.cpp",
2727
"MetadataLookup.h",
28+
"MetadataTypes.cpp",
2829
"MetadataTypes.h",
2930
"OperationTypes.h",
3031
"Provider.h",

0 commit comments

Comments
 (0)