|
40 | 40 | #include <app/util/persistence/AttributePersistenceProvider.h>
|
41 | 41 | #include <app/util/persistence/DefaultAttributePersistenceProvider.h>
|
42 | 42 | #include <data-model-providers/codegen/EmberMetadata.h>
|
| 43 | +#include <iterator> |
43 | 44 | #include <lib/core/CHIPError.h>
|
44 | 45 | #include <lib/core/DataModelTypes.h>
|
45 | 46 | #include <lib/support/CodeUtils.h>
|
46 | 47 | #include <lib/support/ScopedBuffer.h>
|
47 | 48 | #include <lib/support/SpanSearchValue.h>
|
48 | 49 |
|
49 | 50 | #include <cstdint>
|
| 51 | +#include <iterator> |
50 | 52 | #include <optional>
|
51 | 53 |
|
52 | 54 | namespace chip {
|
@@ -262,25 +264,21 @@ CHIP_ERROR CodegenDataModelProvider::ServerClusters(EndpointId endpointId,
|
262 | 264 | VerifyOrReturnValue(endpoint->clusterCount > 0, CHIP_NO_ERROR);
|
263 | 265 | VerifyOrReturnValue(endpoint->cluster != nullptr, CHIP_NO_ERROR);
|
264 | 266 |
|
265 |
| - // We have 2 managed lists: |
266 |
| - // - ember clusters, that have ember metadata AND ember version |
267 |
| - // - `ServerClusterInterfaceRegistry` clusters which MAY have an ember version |
268 |
| - // however may also not have one (we should accept server clusters registered |
269 |
| - // completely outside ember). |
| 267 | + // We build the cluster list by merging two lists: |
| 268 | + // - mRegistry items from ServerClusterInterfaces |
| 269 | + // - ember metadata clusters |
270 | 270 | //
|
271 |
| - // As a result, we are merging the lists here. The first list is the registry |
272 |
| - // as the cluster version from that is authoritative (regardless of what ember |
273 |
| - // claims). Secondly we add any additional ember clusters. |
| 271 | + // This is done because `ServerClusterInterface` allows full control for all its metadata, |
| 272 | + // in particular `data version` and `flags`. |
274 | 273 | //
|
275 |
| - // This uses some RAM, however we assume clusters are in the 10s of items only. |
276 |
| - // so this overflow seems ok. |
| 274 | + // To allow cluster implementations to be incrementally converted to storing their own data versions, |
| 275 | + // instead of relying on the out-of-band emberAfDataVersionStorage, first check for clusters that are |
| 276 | + // using the new data version storage and are registered via ServerClusterInterfaceRegistry, then fill |
| 277 | + // in the data versions for the rest via the out-of-band mechanism. |
277 | 278 |
|
278 | 279 | // assume the clusters on endpoint does not change in between these two loops
|
279 |
| - size_t registryClusterCount = 0; |
280 |
| - for (auto * _ : mRegistry.ClustersOnEndpoint(endpointId)) |
281 |
| - { |
282 |
| - registryClusterCount++; |
283 |
| - } |
| 280 | + auto clusters = mRegistry.ClustersOnEndpoint(endpointId); |
| 281 | + size_t registryClusterCount = std::distance(clusters.begin(), clusters.end()); |
284 | 282 |
|
285 | 283 | ReturnErrorOnFailure(builder.EnsureAppendCapacity(registryClusterCount));
|
286 | 284 |
|
|
0 commit comments