Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions examples/common/server-cluster-shim/ServerClusterShim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ using namespace chip::app::DataModel;
using namespace chip::app::Compatibility::Internal;
using Protocols::InteractionModel::Status;

class ContextAttributesChangeListener : public AttributesChangedListener
{
public:
ContextAttributesChangeListener(const DataModel::InteractionModelContext & context) : mListener(context.dataModelChangeListener)
{}
void MarkDirty(const AttributePathParams & path) override { mListener.MarkDirty(path); }

private:
DataModel::ProviderChangeListener & mListener;
};

/// Attempts to read via an attribute access interface (AAI)
///
/// If it returns a CHIP_ERROR, then this is a FINAL result (i.e. either failure or success).
Expand Down Expand Up @@ -330,8 +319,6 @@ ActionReturnStatus ServerClusterShim::WriteAttribute(const WriteAttributeRequest
}
}

ContextAttributesChangeListener changeListener(mContext->interactionContext);

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

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

if (request.operationFlags.Has(DataModel::OperationFlags::kInternal))
Expand Down
1 change: 0 additions & 1 deletion examples/common/server-cluster-shim/ServerClusterShim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <app/ConcreteClusterPath.h>
#include <app/server-cluster/ServerClusterInterface.h>
#include <app/util/AttributesChangedListener.h>
#include <lib/support/ReadOnlyBuffer.h>
#include <lib/support/Span.h>
#include <optional>
Expand Down
1 change: 1 addition & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ static_library("interaction-model") {
"${chip_root}/src/app:required-privileges",
"${chip_root}/src/app/clusters/ota-provider",
"${chip_root}/src/app/common:attribute-type",
"${chip_root}/src/app/data-model-provider",
]

public_configs += [ ":config-controller-dynamic-server" ]
Expand Down
1 change: 1 addition & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ template("chip_data_model") {
"${chip_root}/src/app/common:attribute-type",
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/app/common:enums",
"${chip_root}/src/app/data-model-provider",
"${chip_root}/src/app/persistence",
"${chip_root}/src/app/persistence:default",
"${chip_root}/src/app/server",
Expand Down
5 changes: 3 additions & 2 deletions src/app/dynamic_server/DynamicDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <app/MessageDef/StatusIB.h>
#include <app/WriteHandler.h>
#include <app/clusters/ota-provider/ota-provider-cluster.h>
#include <app/data-model-provider/ProviderChangeListener.h>
#include <app/data-model/Decode.h>
#include <app/util/attribute-storage.h>
#include <app/util/attribute-table.h>
Expand Down Expand Up @@ -313,13 +314,13 @@ CHIP_ERROR GetSemanticTagForEndpointAtIndex(EndpointId endpoint, size_t index,
}

void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
AttributesChangedListener * listener)
DataModel::ProviderChangeListener * listener)
{
gMockDataVersion++;
listener->MarkDirty(AttributePathParams(endpoint, clusterId, attributeId));
}

void emberAfEndpointChanged(EndpointId endpoint, AttributesChangedListener * listener)
void emberAfEndpointChanged(EndpointId endpoint, DataModel::ProviderChangeListener * listener)
{
listener->MarkDirty(AttributePathParams(endpoint));
}
Expand Down
35 changes: 0 additions & 35 deletions src/app/util/AttributesChangedListener.h

This file was deleted.

1 change: 0 additions & 1 deletion src/app/util/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ source_set("types") {
# This source set also depends on data-model
source_set("af-types") {
sources = [
"AttributesChangedListener.h",
"MarkAttributeDirty.h",
"af-types.h",
]
Expand Down
1 change: 0 additions & 1 deletion src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <stdbool.h> // For bool
#include <stdint.h> // For various uint*_t types

#include <app/util/AttributesChangedListener.h>
#include <app/util/MarkAttributeDirty.h>
#include <app/util/basic-types.h>
#include <app/util/types_stub.h> // For various types.
Expand Down
24 changes: 5 additions & 19 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/CommandHandlerInterfaceRegistry.h>
#include <app/InteractionModelEngine.h>
#include <app/data-model-provider/ProviderChangeListener.h>
#include <app/persistence/AttributePersistenceProvider.h>
#include <app/persistence/AttributePersistenceProviderInstance.h>
#include <app/persistence/PascalString.h>
Expand Down Expand Up @@ -1589,28 +1590,13 @@ DataVersion * emberAfDataVersionStorage(const ConcreteClusterPath & aConcreteClu
return ep.dataVersions + clusterIndex;
}

namespace {
class GlobalInteractionModelEngineChangedpathListener : public AttributesChangedListener
{
public:
~GlobalInteractionModelEngineChangedpathListener() = default;

void MarkDirty(const AttributePathParams & path) override
{
InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(path);
}
};

} // namespace

AttributesChangedListener * emberAfGlobalInteractionModelAttributesChangedListener()
DataModel::ProviderChangeListener * emberAfGlobalInteractionModelAttributesChangedListener()
{
static GlobalInteractionModelEngineChangedpathListener listener;
return &listener;
return &InteractionModelEngine::GetInstance()->GetReportingEngine();
}

void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
AttributesChangedListener * listener)
DataModel::ProviderChangeListener * listener)
{
// Increase cluster data path
DataVersion * version = emberAfDataVersionStorage(ConcreteClusterPath(endpoint, clusterId));
Expand All @@ -1629,7 +1615,7 @@ void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, Attribute
listener->MarkDirty(AttributePathParams(endpoint, clusterId, attributeId));
}

void emberAfEndpointChanged(EndpointId endpoint, AttributesChangedListener * listener)
void emberAfEndpointChanged(EndpointId endpoint, DataModel::ProviderChangeListener * listener)
{
listener->MarkDirty(AttributePathParams(endpoint));
}
9 changes: 5 additions & 4 deletions src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

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

/// Returns a change listener that uses the global InteractionModelEngine
/// instance to report dirty paths
chip::app::AttributesChangedListener * emberAfGlobalInteractionModelAttributesChangedListener();
chip::app::DataModel::ProviderChangeListener * emberAfGlobalInteractionModelAttributesChangedListener();

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

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

/// Maintains a increasing index of structural changes within ember
/// that determine if existing "indexes" and metadata pointers within ember
Expand Down
6 changes: 3 additions & 3 deletions src/app/util/attribute-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma once

#include <app/ConcreteAttributePath.h>
#include <app/util/AttributesChangedListener.h>
#include <app/data-model-provider/ProviderChangeListener.h>
#include <app/util/MarkAttributeDirty.h>
#include <app/util/attribute-metadata.h>
#include <lib/core/DataModelTypes.h>
Expand Down Expand Up @@ -50,7 +50,7 @@ struct EmberAfWriteDataInput
// Listener called when when the written data is consided changed/dirty.
// This being called depends on settings of `markDirty` combined with the actual contents of dataPtr
// vs the contents of the current attribute storage.
chip::app::AttributesChangedListener * changeListener = nullptr;
chip::app::DataModel::ProviderChangeListener * changeListener = nullptr;

EmberAfWriteDataInput(uint8_t * data, EmberAfAttributeType type) : dataPtr(data), dataType(type) {}

Expand All @@ -60,7 +60,7 @@ struct EmberAfWriteDataInput
return *this;
}

EmberAfWriteDataInput & SetChangeListener(chip::app::AttributesChangedListener * listener)
EmberAfWriteDataInput & SetChangeListener(chip::app::DataModel::ProviderChangeListener * listener)
{
changeListener = listener;
return *this;
Expand Down
5 changes: 3 additions & 2 deletions src/app/util/mock/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <app/MessageDef/AttributeDataIB.h>
#include <app/MessageDef/AttributeReportIB.h>
#include <app/MessageDef/AttributeStatusIB.h>
#include <app/data-model-provider/ProviderChangeListener.h>
#include <app/util/attribute-storage.h>
#include <app/util/endpoint-config-api.h>
#include <app/util/mock/Constants.h>
Expand Down Expand Up @@ -391,13 +392,13 @@ chip::Span<const EmberAfDeviceType> emberAfDeviceTypeListFromEndpointIndex(unsig
}

void emberAfAttributeChanged(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
AttributesChangedListener * listener)
DataModel::ProviderChangeListener * listener)
{
dataVersion++;
listener->MarkDirty(AttributePathParams(endpoint, clusterId, attributeId));
}

void emberAfEndpointChanged(EndpointId endpoint, AttributesChangedListener * listener)
void emberAfEndpointChanged(EndpointId endpoint, DataModel::ProviderChangeListener * listener)
{
listener->MarkDirty(AttributePathParams(endpoint));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ namespace {
using namespace chip::app::Compatibility::Internal;
using Protocols::InteractionModel::Status;

class ContextAttributesChangeListener : public AttributesChangedListener
{
public:
ContextAttributesChangeListener(DataModel::ProviderChangeListener & listener) : mListener(listener) {}
void MarkDirty(const AttributePathParams & path) override { mListener.MarkDirty(path); }

private:
DataModel::ProviderChangeListener & mListener;
};

/// Attempts to write via an attribute access interface (AAI)
///
/// If it returns a CHIP_ERROR, then this is a FINAL result (i.e. either failure or success)
Expand Down Expand Up @@ -94,10 +84,6 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
// we must be started up to accept writes (we make use of the context below)
VerifyOrReturnError(mContext.has_value(), CHIP_ERROR_INCORRECT_STATE);

// Codegen logic specific: we accept AAI writes BEFORE server cluster interface, so that we are backwards compatible
// in case some application installed AAI before Server Cluster Interfaces were supported
ContextAttributesChangeListener change_listener(mContext->dataModelChangeListener);

const EmberAfAttributeMetadata * attributeMetadata =
emberAfLocateAttributeMetadata(request.path.mEndpointId, request.path.mClusterId, request.path.mAttributeId);

Expand All @@ -114,7 +100,7 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
// TODO: this is awkward since it provides AAI no control over this, specifically
// AAI may not want to increase versions for some attributes that are Q
emberAfAttributeChanged(request.path.mEndpointId, request.path.mClusterId, request.path.mAttributeId,
&change_listener);
&mContext->dataModelChangeListener);
}
return *aai_result;
}
Expand Down Expand Up @@ -147,7 +133,7 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat

EmberAfWriteDataInput dataInput(dataBuffer.data(), attributeMetadata->attributeType);

dataInput.SetChangeListener(&change_listener);
dataInput.SetChangeListener(&mContext->dataModelChangeListener);
// TODO: dataInput.SetMarkDirty() should be according to `ChangesOmmited`

if (request.operationFlags.Has(DataModel::OperationFlags::kInternal))
Expand Down Expand Up @@ -213,17 +199,16 @@ void CodegenDataModelProvider::Temporary_ReportAttributeChanged(const AttributeP
// we must be started up to process changes since we use the context
VerifyOrReturn(mContext.has_value());

ContextAttributesChangeListener change_listener(mContext->dataModelChangeListener);
if (path.mClusterId != kInvalidClusterId)
{
emberAfAttributeChanged(path.mEndpointId, path.mClusterId, path.mAttributeId, &change_listener);
emberAfAttributeChanged(path.mEndpointId, path.mClusterId, path.mAttributeId, &mContext->dataModelChangeListener);
}
else
{
// When the path has wildcard cluster Id, call the emberAfEndpointChanged to mark attributes on the given endpoint
// as having changing, but do NOT increase/alter any cluster data versions, as this happens when a bridged endpoint is
// added or removed from a bridge and the cluster data is not changed during the process.
emberAfEndpointChanged(path.mEndpointId, &change_listener);
emberAfEndpointChanged(path.mEndpointId, &mContext->dataModelChangeListener);
}
}

Expand Down
Loading