23
23
#include < app/AttributeAccessInterface.h>
24
24
#include < app/AttributeAccessInterfaceRegistry.h>
25
25
#include < app/InteractionModelEngine.h>
26
+ #include < app/data-model-provider/MetadataList.h>
26
27
#include < app/data-model-provider/MetadataTypes.h>
28
+ #include < app/data-model/List.h>
27
29
#include < app/util/attribute-storage.h>
28
30
#include < app/util/endpoint-config-api.h>
29
31
#include < lib/core/CHIPError.h>
@@ -60,7 +62,7 @@ bool IsDescendantOf(const DataModel::EndpointEntry * __restrict__ childEndpoint,
60
62
childEndpoint = nullptr ; // we will look it up again
61
63
62
64
// find the requested value in the array to get its parent
63
- for (auto & ep : allEndpoints)
65
+ for (const auto & ep : allEndpoints)
64
66
{
65
67
if (ep.id == lookupId)
66
68
{
@@ -83,7 +85,8 @@ class DescriptorAttrAccess : public AttributeAccessInterface
83
85
CHIP_ERROR ReadTagListAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder);
84
86
CHIP_ERROR ReadPartsAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder);
85
87
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);
87
90
CHIP_ERROR ReadClusterRevision (EndpointId endpoint, AttributeValueEncoder & aEncoder);
88
91
CHIP_ERROR ReadFeatureMap (EndpointId endpoint, AttributeValueEncoder & aEncoder);
89
92
};
@@ -103,9 +106,11 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa
103
106
104
107
CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder)
105
108
{
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 ())
109
114
{
110
115
ReturnErrorOnFailure (encoder.Encode (tag));
111
116
}
@@ -115,11 +120,13 @@ CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, Attri
115
120
116
121
CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder)
117
122
{
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 ();
119
126
if (endpoint == 0x00 )
120
127
{
121
128
return aEncoder.EncodeList ([&endpoints](const auto & encoder) -> CHIP_ERROR {
122
- for (auto & ep : endpoints. GetSpanValidForLifetime () )
129
+ for (const auto & ep : endpoints)
123
130
{
124
131
if (ep.id == 0 )
125
132
{
@@ -133,15 +140,15 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
133
140
134
141
// find the given endpoint
135
142
unsigned idx = 0 ;
136
- while (idx < endpoints.Size ())
143
+ while (idx < endpoints.size ())
137
144
{
138
145
if (endpoints[idx].id == endpoint)
139
146
{
140
147
break ;
141
148
}
142
149
idx++;
143
150
}
144
- if (idx >= endpoints.Size ())
151
+ if (idx >= endpoints.size ())
145
152
{
146
153
// not found
147
154
return CHIP_ERROR_NOT_FOUND;
@@ -154,9 +161,9 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
154
161
case DataModel::EndpointCompositionPattern::kFullFamily :
155
162
// encodes ALL endpoints that have the specified endpoint as a descendant
156
163
return aEncoder.EncodeList ([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
157
- for (auto & ep : endpoints. GetSpanValidForLifetime () )
164
+ for (const auto & ep : endpoints)
158
165
{
159
- if (IsDescendantOf (&ep, endpoint, endpoints. GetSpanValidForLifetime () ))
166
+ if (IsDescendantOf (&ep, endpoint, endpoints))
160
167
{
161
168
ReturnErrorOnFailure (encoder.Encode (ep.id ));
162
169
}
@@ -166,7 +173,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
166
173
167
174
case DataModel::EndpointCompositionPattern::kTree :
168
175
return aEncoder.EncodeList ([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
169
- for (auto & ep : endpoints. GetSpanValidForLifetime () )
176
+ for (const auto & ep : endpoints)
170
177
{
171
178
if (ep.parentId != endpoint)
172
179
{
@@ -184,11 +191,14 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
184
191
185
192
CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder)
186
193
{
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)) ;
189
196
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)
192
202
{
193
203
deviceStruct.deviceType = type.deviceTypeId ;
194
204
deviceStruct.revision = type.deviceTypeRevision ;
@@ -201,30 +211,30 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
201
211
return err;
202
212
}
203
213
204
- CHIP_ERROR DescriptorAttrAccess::ReadClientServerAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server )
214
+ CHIP_ERROR DescriptorAttrAccess::ReadServerClusters (EndpointId endpoint, AttributeValueEncoder & aEncoder)
205
215
{
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 ())
208
220
{
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 ));
214
222
}
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 ())
216
233
{
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));
222
235
}
223
-
224
236
return CHIP_NO_ERROR;
225
237
});
226
-
227
- return err;
228
238
}
229
239
230
240
CHIP_ERROR DescriptorAttrAccess::ReadClusterRevision (EndpointId endpoint, AttributeValueEncoder & aEncoder)
@@ -244,10 +254,10 @@ CHIP_ERROR DescriptorAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
244
254
return ReadDeviceAttribute (aPath.mEndpointId , aEncoder);
245
255
}
246
256
case ServerList::Id: {
247
- return ReadClientServerAttribute (aPath.mEndpointId , aEncoder, true );
257
+ return ReadServerClusters (aPath.mEndpointId , aEncoder);
248
258
}
249
259
case ClientList::Id: {
250
- return ReadClientServerAttribute (aPath.mEndpointId , aEncoder, false );
260
+ return ReadClientClusters (aPath.mEndpointId , aEncoder);
251
261
}
252
262
case PartsList::Id: {
253
263
return ReadPartsAttribute (aPath.mEndpointId , aEncoder);
0 commit comments