14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
+ #include " app/data-model-provider/MetadataSearch.h"
17
18
#include < app/AttributePathExpandIterator.h>
18
19
19
20
#include < app/GlobalAttributes.h>
@@ -119,34 +120,58 @@ bool AttributePathExpandIterator::IsValidAttributeId(AttributeId attributeId)
119
120
break ;
120
121
}
121
122
123
+ DataModel::AttributeFinder finder (mDataModelProvider );
124
+
122
125
const ConcreteAttributePath attributePath (mPosition .mOutputPath .mEndpointId , mPosition .mOutputPath .mClusterId , attributeId);
123
- return mDataModelProvider -> GetAttributeInfo (attributePath).has_value ();
126
+ return finder. Find (attributePath).has_value ();
124
127
}
125
128
126
129
std::optional<AttributeId> AttributePathExpandIterator::NextAttributeId ()
127
130
{
128
- if (mPosition .mOutputPath .mAttributeId == kInvalidAttributeId )
131
+ if (mPosition .mOutputPath .mAttributeId == kInvalidClusterId )
132
+ {
133
+ mAttributeIndex = kInvalidIndex ;
134
+ }
135
+
136
+ if (mAttributeIndex == kInvalidIndex )
129
137
{
130
- if (mPosition .mAttributePath ->mValue .HasWildcardAttributeId ())
138
+ // start a new iteration on the current endpoint
139
+ mAttributes = mDataModelProvider ->Attributes (mPosition .mOutputPath );
140
+
141
+ if (mPosition .mOutputPath .mAttributeId != kInvalidAttributeId )
131
142
{
132
- AttributeEntry entry = mDataModelProvider ->FirstAttribute (mPosition .mOutputPath );
133
- return entry.IsValid () //
134
- ? entry.path .mAttributeId //
135
- : Clusters::Globals::Attributes::GeneratedCommandList::Id; //
143
+ // Position on the correct cluster if we have a start point
144
+ mAttributeIndex = 0 ;
145
+ while ((mAttributeIndex < mAttributes .size ()) &&
146
+ (mAttributes [mAttributeIndex ].attributeId != mPosition .mOutputPath .mAttributeId ))
147
+ {
148
+ mAttributeIndex ++;
149
+ }
136
150
}
151
+ }
137
152
138
- // At this point, the attributeID is NOT a wildcard (i.e. it is fixed).
139
- //
140
- // For wildcard expansion, we validate that this is a valid attribute for the given
141
- // cluster on the given endpoint. If not a wildcard expansion, return it as-is.
142
- if (mPosition .mAttributePath ->mValue .IsWildcardPath ())
153
+ if (mPosition .mOutputPath .mAttributeId == kInvalidAttributeId )
154
+ {
155
+ if (!mPosition .mAttributePath ->mValue .HasWildcardAttributeId ())
143
156
{
144
- if (!IsValidAttributeId (mPosition .mAttributePath ->mValue .mAttributeId ))
157
+ // The attributeID is NOT a wildcard (i.e. it is fixed).
158
+ //
159
+ // For wildcard expansion, we validate that this is a valid attribute for the given
160
+ // cluster on the given endpoint. If not a wildcard expansion, return it as-is.
161
+ if (mPosition .mAttributePath ->mValue .IsWildcardPath ())
145
162
{
146
- return std::nullopt;
163
+ if (!IsValidAttributeId (mPosition .mAttributePath ->mValue .mAttributeId ))
164
+ {
165
+ return std::nullopt;
166
+ }
147
167
}
168
+ return mPosition .mAttributePath ->mValue .mAttributeId ;
148
169
}
149
- return mPosition .mAttributePath ->mValue .mAttributeId ;
170
+ mAttributeIndex = 0 ;
171
+ }
172
+ else
173
+ {
174
+ mAttributeIndex ++;
150
175
}
151
176
152
177
// Advance the existing attribute id if it can be advanced.
@@ -171,10 +196,9 @@ std::optional<AttributeId> AttributePathExpandIterator::NextAttributeId()
171
196
return std::nullopt;
172
197
}
173
198
174
- AttributeEntry entry = mDataModelProvider ->NextAttribute (mPosition .mOutputPath );
175
- if (entry.IsValid ())
199
+ if (mAttributeIndex < mAttributes .size ())
176
200
{
177
- return entry. path . mAttributeId ;
201
+ return mAttributes [ mAttributeIndex ]. attributeId ;
178
202
}
179
203
180
204
// Finished the data model, start with global attributes
0 commit comments