25
25
#include < app-common/zap-generated/ids/Clusters.h>
26
26
#include < app/AttributeAccessInterface.h>
27
27
#include < app/AttributeAccessInterfaceRegistry.h>
28
+ #include < app/InteractionModelEngine.h>
29
+ #include < app/data-model-provider/MetadataTypes.h>
28
30
#include < app/util/attribute-storage.h>
29
31
#include < app/util/endpoint-config-api.h>
30
32
#include < lib/support/CodeUtils.h>
@@ -73,87 +75,77 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa
73
75
CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder)
74
76
{
75
77
return aEncoder.EncodeList ([&endpoint](const auto & encoder) -> CHIP_ERROR {
76
- Clusters::Descriptor::Structs::SemanticTagStruct::Type tag;
77
- size_t index = 0 ;
78
- CHIP_ERROR err = CHIP_NO_ERROR;
79
- while ((err = GetSemanticTagForEndpointAtIndex (endpoint, index , tag)) == CHIP_NO_ERROR)
78
+ auto tag = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->GetFirstSemanticTag (endpoint);
79
+ while (tag.has_value ())
80
80
{
81
- ReturnErrorOnFailure (encoder.Encode (tag));
82
- index ++ ;
81
+ ReturnErrorOnFailure (encoder.Encode (tag. value () ));
82
+ tag = InteractionModelEngine::GetInstance ()-> GetDataModelProvider ()-> GetNextSemanticTag (endpoint, tag. value ()) ;
83
83
}
84
- if (err == CHIP_ERROR_NOT_FOUND)
85
- {
86
- return CHIP_NO_ERROR;
87
- }
88
- return err;
84
+ return CHIP_NO_ERROR;
89
85
});
90
86
}
91
87
92
88
CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder)
93
89
{
94
90
CHIP_ERROR err = CHIP_NO_ERROR;
95
91
92
+ auto endpointInfo = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->GetEndpointInfo (endpoint);
96
93
if (endpoint == 0x00 )
97
94
{
98
95
err = aEncoder.EncodeList ([](const auto & encoder) -> CHIP_ERROR {
99
- for (uint16_t index = 0 ; index < emberAfEndpointCount (); index ++)
96
+ auto endpointEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->FirstEndpoint ();
97
+ while (endpointEntry.IsValid ())
100
98
{
101
- if (emberAfEndpointIndexIsEnabled ( index ) )
99
+ if (endpointEntry. id != 0 )
102
100
{
103
- EndpointId endpointId = emberAfEndpointFromIndex (index );
104
- if (endpointId == 0 )
105
- continue ;
106
-
107
- ReturnErrorOnFailure (encoder.Encode (endpointId));
101
+ ReturnErrorOnFailure (encoder.Encode (endpointEntry.id ));
108
102
}
103
+ endpointEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->NextEndpoint (endpointEntry.id );
109
104
}
110
-
111
105
return CHIP_NO_ERROR;
112
106
});
113
107
}
114
- else if (IsFlatCompositionForEndpoint (endpoint))
108
+ else if (endpointInfo.has_value () &&
109
+ endpointInfo->compositionPattern == DataModel::EndpointCompositionPattern::kFullFamilyPattern )
115
110
{
116
111
err = aEncoder.EncodeList ([endpoint](const auto & encoder) -> CHIP_ERROR {
117
- for (uint16_t index = 0 ; index < emberAfEndpointCount (); index ++)
112
+ auto endpointEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->FirstEndpoint ();
113
+ while (endpointEntry.IsValid ())
118
114
{
119
- if (!emberAfEndpointIndexIsEnabled (index ))
120
- continue ;
121
-
122
- uint16_t childIndex = index ;
123
- while (childIndex != chip::kInvalidListIndex )
115
+ EndpointId parentEndpointId = endpointEntry.info .parentId ;
116
+ while (parentEndpointId != chip::kInvalidEndpointId )
124
117
{
125
- EndpointId parentEndpointId = emberAfParentEndpointFromIndex (childIndex);
126
- if (parentEndpointId == chip::kInvalidEndpointId )
127
- break ;
128
-
129
118
if (parentEndpointId == endpoint)
130
119
{
131
- ReturnErrorOnFailure (encoder.Encode (emberAfEndpointFromIndex ( index ) ));
120
+ ReturnErrorOnFailure (encoder.Encode (endpointEntry. id ));
132
121
break ;
133
122
}
134
-
135
- childIndex = emberAfIndexFromEndpoint (parentEndpointId);
123
+ auto parentEndpointInfo =
124
+ InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->GetEndpointInfo (parentEndpointId);
125
+ if (!parentEndpointInfo.has_value ())
126
+ {
127
+ break ;
128
+ }
129
+ parentEndpointId = parentEndpointInfo->parentId ;
136
130
}
131
+ endpointEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->NextEndpoint (endpointEntry.id );
137
132
}
138
133
139
134
return CHIP_NO_ERROR;
140
135
});
141
136
}
142
- else if (IsTreeCompositionForEndpoint (endpoint) )
137
+ else if (endpointInfo. has_value () && endpointInfo-> compositionPattern == DataModel::EndpointCompositionPattern:: kTreePattern )
143
138
{
144
139
err = aEncoder.EncodeList ([endpoint](const auto & encoder) -> CHIP_ERROR {
145
- for (uint16_t index = 0 ; index < emberAfEndpointCount (); index ++)
140
+ auto endpointEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->FirstEndpoint ();
141
+ while (endpointEntry.IsValid ())
146
142
{
147
- if (!emberAfEndpointIndexIsEnabled (index ))
148
- continue ;
149
-
150
- EndpointId parentEndpointId = emberAfParentEndpointFromIndex (index );
151
- if (parentEndpointId == endpoint)
143
+ if (endpointEntry.info .parentId == endpoint)
152
144
{
153
- ReturnErrorOnFailure (encoder.Encode (emberAfEndpointFromIndex ( index ) ));
145
+ ReturnErrorOnFailure (encoder.Encode (endpointEntry. id ));
154
146
}
147
+ endpointEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->NextEndpoint (endpointEntry.id );
155
148
}
156
-
157
149
return CHIP_NO_ERROR;
158
150
});
159
151
}
@@ -165,16 +157,15 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
165
157
{
166
158
CHIP_ERROR err = aEncoder.EncodeList ([&endpoint](const auto & encoder) -> CHIP_ERROR {
167
159
Descriptor::Structs::DeviceTypeStruct::Type deviceStruct;
168
- CHIP_ERROR err2;
169
160
170
- auto deviceTypeList = emberAfDeviceTypeListFromEndpoint (endpoint, err2);
171
- ReturnErrorOnFailure (err2);
161
+ auto deviceType = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->FirstDeviceType (endpoint);
172
162
173
- for ( auto & deviceType : deviceTypeList )
163
+ while ( deviceType. has_value () )
174
164
{
175
- deviceStruct.deviceType = deviceType. deviceId ;
176
- deviceStruct.revision = deviceType. deviceVersion ;
165
+ deviceStruct.deviceType = deviceType-> deviceTypeId ;
166
+ deviceStruct.revision = deviceType-> deviceTypeRevision ;
177
167
ReturnErrorOnFailure (encoder.Encode (deviceStruct));
168
+ deviceType = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->NextDeviceType (endpoint, *deviceType);
178
169
}
179
170
180
171
return CHIP_NO_ERROR;
@@ -186,12 +177,24 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
186
177
CHIP_ERROR DescriptorAttrAccess::ReadClientServerAttribute (EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server)
187
178
{
188
179
CHIP_ERROR err = aEncoder.EncodeList ([&endpoint, server](const auto & encoder) -> CHIP_ERROR {
189
- uint8_t clusterCount = emberAfClusterCount (endpoint, server);
190
-
191
- for (uint8_t clusterIndex = 0 ; clusterIndex < clusterCount; clusterIndex++)
180
+ if (server)
192
181
{
193
- const EmberAfCluster * cluster = emberAfGetNthCluster (endpoint, clusterIndex, server);
194
- ReturnErrorOnFailure (encoder.Encode (cluster->clusterId ));
182
+ auto clusterEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->FirstServerCluster (endpoint);
183
+ while (clusterEntry.IsValid ())
184
+ {
185
+ ReturnErrorOnFailure (encoder.Encode (clusterEntry.path .mClusterId ));
186
+ clusterEntry = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->NextServerCluster (clusterEntry.path );
187
+ }
188
+ }
189
+ else
190
+ {
191
+ ConcreteClusterPath clusterPath =
192
+ InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->FirstClientCluster (endpoint);
193
+ while (clusterPath.HasValidIds ())
194
+ {
195
+ ReturnErrorOnFailure (encoder.Encode (clusterPath.mClusterId ));
196
+ clusterPath = InteractionModelEngine::GetInstance ()->GetDataModelProvider ()->NextClientCluster (clusterPath);
197
+ }
195
198
}
196
199
197
200
return CHIP_NO_ERROR;
0 commit comments