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
104107CHIP_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
116121CHIP_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
185192CHIP_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
230240CHIP_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);
0 commit comments