Skip to content

Commit edaca08

Browse files
committed
Update comment and clarity for clusters on endpoint usage
1 parent 366eb23 commit edaca08

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/data-model-providers/codegen/CodegenDataModelProvider.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@
4040
#include <app/util/persistence/AttributePersistenceProvider.h>
4141
#include <app/util/persistence/DefaultAttributePersistenceProvider.h>
4242
#include <data-model-providers/codegen/EmberMetadata.h>
43+
#include <iterator>
4344
#include <lib/core/CHIPError.h>
4445
#include <lib/core/DataModelTypes.h>
4546
#include <lib/support/CodeUtils.h>
4647
#include <lib/support/ScopedBuffer.h>
4748
#include <lib/support/SpanSearchValue.h>
4849

4950
#include <cstdint>
51+
#include <iterator>
5052
#include <optional>
5153

5254
namespace chip {
@@ -262,25 +264,21 @@ CHIP_ERROR CodegenDataModelProvider::ServerClusters(EndpointId endpointId,
262264
VerifyOrReturnValue(endpoint->clusterCount > 0, CHIP_NO_ERROR);
263265
VerifyOrReturnValue(endpoint->cluster != nullptr, CHIP_NO_ERROR);
264266

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
270270
//
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`.
274273
//
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.
277278

278279
// 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());
284282

285283
ReturnErrorOnFailure(builder.EnsureAppendCapacity(registryClusterCount));
286284

src/data-model-providers/codegen/ServerClusterInterfaceRegistry.h

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <lib/core/CHIPError.h>
2222
#include <lib/core/DataModelTypes.h>
2323

24+
#include <iterator>
25+
2426
namespace chip {
2527
namespace app {
2628

@@ -55,6 +57,12 @@ class ServerClusterInterfaceRegistry
5557
class Iterator
5658
{
5759
public:
60+
using difference_type = size_t;
61+
using value_type = ServerClusterInterface *;
62+
using pointer = ServerClusterInterface **;
63+
using reference = ServerClusterInterface *&;
64+
using iterator_category = std::forward_iterator_tag;
65+
5866
Iterator(ServerClusterRegistration * interface, EndpointId endpoint) : mRegistration(interface), mEndpointId(endpoint)
5967
{
6068
AdvanceUntilMatchingEndpoint();

0 commit comments

Comments
 (0)