Skip to content

Commit e14c2e4

Browse files
zenghuchen-ggrestyled-commitsandy31415bzbarsky-applesoares-sergio
committed
[*ChangeListener] replace AttributesChangedListener with ProviderChan… (project-chip#41518)
* [*ChangeListener] replace AttributesChangedListener with ProviderChangeListener AttributesChangedListener is a duplicate of ProviderChangeListener and there is no need to keep both. Since AttributesChangedListener is for ember and ProviderChangeListener is from DataModel, it makes more sense to keep ProviderChangeListener. * Restyled by clang-format * Restyled by gn * add direct dependency on data-model-provider * Update comment to reflect the correct usage * Remove ContextAttributesChangeListener, which is a wrapper of ProviderChangeListener now * Remove ContextAttributesChangeListener in server-cluster-shim * Restyled by clang-format * Replace AttributesChangedListener with ProviderChangedListener in ember functions * Restyled by clang-format * include header needed for Providerchangedlistener * Apply suggestions from code review chip::app:: prefix is redundant because the function is defined inside chip::app namespace Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * [no-ccache] * [no-ccache] --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andy314@gmail.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> Co-authored-by: Sergio Soares <sergiosoares@google.com>
1 parent 4c15b47 commit e14c2e4

File tree

13 files changed

+28
-102
lines changed

13 files changed

+28
-102
lines changed

examples/common/server-cluster-shim/ServerClusterShim.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ using namespace chip::app::DataModel;
4848
using namespace chip::app::Compatibility::Internal;
4949
using Protocols::InteractionModel::Status;
5050

51-
class ContextAttributesChangeListener : public AttributesChangedListener
52-
{
53-
public:
54-
ContextAttributesChangeListener(const DataModel::InteractionModelContext & context) : mListener(context.dataModelChangeListener)
55-
{}
56-
void MarkDirty(const AttributePathParams & path) override { mListener.MarkDirty(path); }
57-
58-
private:
59-
DataModel::ProviderChangeListener & mListener;
60-
};
61-
6251
/// Attempts to read via an attribute access interface (AAI)
6352
///
6453
/// If it returns a CHIP_ERROR, then this is a FINAL result (i.e. either failure or success).
@@ -330,8 +319,6 @@ ActionReturnStatus ServerClusterShim::WriteAttribute(const WriteAttributeRequest
330319
}
331320
}
332321

333-
ContextAttributesChangeListener changeListener(mContext->interactionContext);
334-
335322
AttributeAccessInterface * aai =
336323
AttributeAccessInterfaceRegistry::Instance().Get(request.path.mEndpointId, request.path.mClusterId);
337324
std::optional<CHIP_ERROR> aai_result = TryWriteViaAccessInterface(request.path, aai, decoder);
@@ -341,7 +328,8 @@ ActionReturnStatus ServerClusterShim::WriteAttribute(const WriteAttributeRequest
341328
{
342329
// TODO: this is awkward since it provides AAI no control over this, specifically
343330
// AAI may not want to increase versions for some attributes that are Q
344-
emberAfAttributeChanged(request.path.mEndpointId, request.path.mClusterId, request.path.mAttributeId, &changeListener);
331+
emberAfAttributeChanged(request.path.mEndpointId, request.path.mClusterId, request.path.mAttributeId,
332+
&mContext->interactionContext.dataModelChangeListener);
345333
}
346334
return *aai_result;
347335
}
@@ -360,7 +348,7 @@ ActionReturnStatus ServerClusterShim::WriteAttribute(const WriteAttributeRequest
360348

361349
Protocols::InteractionModel::Status status;
362350
EmberAfWriteDataInput dataInput(dataBuffer.data(), attributeMetadata->attributeType);
363-
dataInput.SetChangeListener(&changeListener);
351+
dataInput.SetChangeListener(&mContext->interactionContext.dataModelChangeListener);
364352
// TODO: dataInput.SetMarkDirty() should be according to `ChangesOmmited`
365353

366354
if (request.operationFlags.Has(DataModel::OperationFlags::kInternal))

examples/common/server-cluster-shim/ServerClusterShim.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <app/ConcreteClusterPath.h>
2020
#include <app/server-cluster/ServerClusterInterface.h>
21-
#include <app/util/AttributesChangedListener.h>
2221
#include <lib/support/ReadOnlyBuffer.h>
2322
#include <lib/support/Span.h>
2423
#include <optional>

src/app/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ static_library("interaction-model") {
279279
"${chip_root}/src/app:required-privileges",
280280
"${chip_root}/src/app/clusters/ota-provider",
281281
"${chip_root}/src/app/common:attribute-type",
282+
"${chip_root}/src/app/data-model-provider",
282283
]
283284

284285
public_configs += [ ":config-controller-dynamic-server" ]

src/app/chip_data_model.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ template("chip_data_model") {
289289
"${chip_root}/src/app/common:attribute-type",
290290
"${chip_root}/src/app/common:cluster-objects",
291291
"${chip_root}/src/app/common:enums",
292+
"${chip_root}/src/app/data-model-provider",
292293
"${chip_root}/src/app/persistence",
293294
"${chip_root}/src/app/persistence:default",
294295
"${chip_root}/src/app/server",

src/app/dynamic_server/DynamicDispatcher.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <app/MessageDef/StatusIB.h>
3333
#include <app/WriteHandler.h>
3434
#include <app/clusters/ota-provider/ota-provider-cluster.h>
35+
#include <app/data-model-provider/ProviderChangeListener.h>
3536
#include <app/data-model/Decode.h>
3637
#include <app/util/attribute-storage.h>
3738
#include <app/util/attribute-table.h>
@@ -313,13 +314,13 @@ CHIP_ERROR GetSemanticTagForEndpointAtIndex(EndpointId endpoint, size_t index,
313314
}
314315

315316
void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
316-
AttributesChangedListener * listener)
317+
DataModel::ProviderChangeListener * listener)
317318
{
318319
gMockDataVersion++;
319320
listener->MarkDirty(AttributePathParams(endpoint, clusterId, attributeId));
320321
}
321322

322-
void emberAfEndpointChanged(EndpointId endpoint, AttributesChangedListener * listener)
323+
void emberAfEndpointChanged(EndpointId endpoint, DataModel::ProviderChangeListener * listener)
323324
{
324325
listener->MarkDirty(AttributePathParams(endpoint));
325326
}

src/app/util/AttributesChangedListener.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/app/util/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ source_set("types") {
5555
# This source set also depends on data-model
5656
source_set("af-types") {
5757
sources = [
58-
"AttributesChangedListener.h",
5958
"MarkAttributeDirty.h",
6059
"af-types.h",
6160
]

src/app/util/af-types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <stdbool.h> // For bool
2727
#include <stdint.h> // For various uint*_t types
2828

29-
#include <app/util/AttributesChangedListener.h>
3029
#include <app/util/MarkAttributeDirty.h>
3130
#include <app/util/basic-types.h>
3231
#include <app/util/types_stub.h> // For various types.

src/app/util/attribute-storage.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <app/AttributeAccessInterfaceRegistry.h>
2121
#include <app/CommandHandlerInterfaceRegistry.h>
2222
#include <app/InteractionModelEngine.h>
23+
#include <app/data-model-provider/ProviderChangeListener.h>
2324
#include <app/persistence/AttributePersistenceProvider.h>
2425
#include <app/persistence/AttributePersistenceProviderInstance.h>
2526
#include <app/persistence/PascalString.h>
@@ -1589,28 +1590,13 @@ DataVersion * emberAfDataVersionStorage(const ConcreteClusterPath & aConcreteClu
15891590
return ep.dataVersions + clusterIndex;
15901591
}
15911592

1592-
namespace {
1593-
class GlobalInteractionModelEngineChangedpathListener : public AttributesChangedListener
1594-
{
1595-
public:
1596-
~GlobalInteractionModelEngineChangedpathListener() = default;
1597-
1598-
void MarkDirty(const AttributePathParams & path) override
1599-
{
1600-
InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(path);
1601-
}
1602-
};
1603-
1604-
} // namespace
1605-
1606-
AttributesChangedListener * emberAfGlobalInteractionModelAttributesChangedListener()
1593+
DataModel::ProviderChangeListener * emberAfGlobalInteractionModelAttributesChangedListener()
16071594
{
1608-
static GlobalInteractionModelEngineChangedpathListener listener;
1609-
return &listener;
1595+
return &InteractionModelEngine::GetInstance()->GetReportingEngine();
16101596
}
16111597

16121598
void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
1613-
AttributesChangedListener * listener)
1599+
DataModel::ProviderChangeListener * listener)
16141600
{
16151601
// Increase cluster data path
16161602
DataVersion * version = emberAfDataVersionStorage(ConcreteClusterPath(endpoint, clusterId));
@@ -1629,7 +1615,7 @@ void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, Attribute
16291615
listener->MarkDirty(AttributePathParams(endpoint, clusterId, attributeId));
16301616
}
16311617

1632-
void emberAfEndpointChanged(EndpointId endpoint, AttributesChangedListener * listener)
1618+
void emberAfEndpointChanged(EndpointId endpoint, DataModel::ProviderChangeListener * listener)
16331619
{
16341620
listener->MarkDirty(AttributePathParams(endpoint));
16351621
}

src/app/util/attribute-storage.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#pragma once
1919

20+
#include <app/data-model-provider/ProviderChangeListener.h>
2021
#include <app/util/af-types.h>
2122
#include <app/util/attribute-metadata.h>
2223
#include <app/util/config.h>
@@ -345,7 +346,7 @@ CHIP_ERROR emberAfSetDeviceTypeList(chip::EndpointId endpoint, chip::Span<const
345346

346347
/// Returns a change listener that uses the global InteractionModelEngine
347348
/// instance to report dirty paths
348-
chip::app::AttributesChangedListener * emberAfGlobalInteractionModelAttributesChangedListener();
349+
chip::app::DataModel::ProviderChangeListener * emberAfGlobalInteractionModelAttributesChangedListener();
349350

350351
/// Mark the given attribute as having changed:
351352
/// - increases the cluster data version for the given cluster
@@ -354,15 +355,15 @@ chip::app::AttributesChangedListener * emberAfGlobalInteractionModelAttributesCh
354355
/// receive updated attribute values for a cluster.
355356
///
356357
/// This is a convenience function to make it clear when a `emberAfDataVersionStorage` increase
357-
/// and a `AttributesChangeListener::MarkDirty` always occur in lock-step.
358+
/// and a `ProviderChangeListener::MarkDirty` always occur in lock-step.
358359
void emberAfAttributeChanged(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId,
359-
chip::app::AttributesChangedListener * listener);
360+
chip::app::DataModel::ProviderChangeListener * listener);
360361

361362
/// Mark attributes on the given endpoint as having changed.
362363
///
363364
/// Schedules reporting engine to consider the endpoint dirty, however does NOT increase/alter
364365
/// any cluster data versions.
365-
void emberAfEndpointChanged(chip::EndpointId endpoint, chip::app::AttributesChangedListener * listener);
366+
void emberAfEndpointChanged(chip::EndpointId endpoint, chip::app::DataModel::ProviderChangeListener * listener);
366367

367368
/// Maintains a increasing index of structural changes within ember
368369
/// that determine if existing "indexes" and metadata pointers within ember

0 commit comments

Comments
 (0)