Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing in a Path change listener to ember write functions #35455

Merged
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
81d9ca5
Cleaner usage: no need of a separate function that is used in one pla…
andreilitvin Sep 6, 2024
cbaba74
Attempt an API update
andreilitvin Sep 6, 2024
1182190
Fix typos in the Accessors src
andreilitvin Sep 6, 2024
011c793
Fix typo and regen
andreilitvin Sep 6, 2024
6470841
More fixes on accessors
andreilitvin Sep 6, 2024
9b0337c
Update signature for emAfWriteAttributeExternal
andreilitvin Sep 6, 2024
e4bece9
Add a comment about all the checks being vague
andreilitvin Sep 6, 2024
afc0b3f
Merge branch 'master' into ember_cluster_version_increase_decouple
andreilitvin Sep 6, 2024
322edf9
Update src/app/util/af-types.h
andy31415 Sep 9, 2024
4f0aed4
Update src/app/util/af-types.h
andy31415 Sep 9, 2024
71758d0
Update src/app/util/attribute-storage.cpp
andy31415 Sep 9, 2024
b83f33e
Update src/app/zap-templates/templates/app/attributes/Accessors-src.zapt
andy31415 Sep 9, 2024
b46930b
Update src/app/util/mock/CodegenEmberMocks.cpp
andy31415 Sep 9, 2024
24ecf40
Update src/app/zap-templates/templates/app/attributes/Accessors-src.zapt
andy31415 Sep 9, 2024
116e220
Update src/app/zap-templates/templates/app/attributes/Accessors-src.zapt
andy31415 Sep 9, 2024
65018ad
zap regen and restyle
andy31415 Sep 9, 2024
8407b63
Update src/app/zap-templates/templates/app/attributes/Accessors-src.zapt
andy31415 Sep 9, 2024
5397a81
Update src/app/util/attribute-table.cpp
andy31415 Sep 9, 2024
c6a843a
Update src/app/util/attribute-storage.cpp
andy31415 Sep 9, 2024
36a7a9e
Update src/app/util/attribute-storage.cpp
andy31415 Sep 9, 2024
fb03193
Update src/app/util/attribute-table.cpp
andy31415 Sep 9, 2024
21053a5
Update src/app/util/attribute-table.cpp
andy31415 Sep 9, 2024
5a841a2
Update src/app/util/attribute-storage.cpp
andy31415 Sep 9, 2024
25184e6
Update src/app/util/attribute-table.h
andy31415 Sep 9, 2024
0a64bf5
Rename ChangedPathListener to AttributesChangedListener
andy31415 Sep 9, 2024
acc5890
Remove chip:: and chip::app
andy31415 Sep 9, 2024
fbd1f13
Update constructors of AttributePathParams and add nodiscard accordin…
andy31415 Sep 9, 2024
5b1404f
Restyled by clang-format
restyled-commits Sep 9, 2024
b2b7353
Remove auto-inserted include
andy31415 Sep 9, 2024
39e9015
Update again and zap regen: removed extra namespace prefixes in acces…
andy31415 Sep 9, 2024
f448211
Add comment about uint8_t non-const usage...
andy31415 Sep 9, 2024
bb00408
Another rename given that the listener is now an attributes and not a…
andy31415 Sep 9, 2024
3ebc3be
Merge branch 'master' into ember_cluster_version_increase_decouple
andy31415 Sep 9, 2024
c2e80c2
Update src/app/util/attribute-table.h
andy31415 Sep 9, 2024
e87d063
Comment update to talk more about AttributesChangedListener
andy31415 Sep 9, 2024
574edce
Merge branch 'ember_cluster_version_increase_decouple' of github.com:…
andy31415 Sep 9, 2024
6969378
Restyle
andy31415 Sep 9, 2024
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
27 changes: 17 additions & 10 deletions src/app/AttributePathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class ReadClient;
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
struct AttributePathParams
{
AttributePathParams() = default;

explicit AttributePathParams(EndpointId aEndpointId) :
AttributePathParams(aEndpointId, kInvalidClusterId, kInvalidAttributeId, kInvalidListIndex)
{}

//
// TODO: (Issue #10596) Need to ensure that we do not encode the NodeId over the wire
// if it is either not 'set', or is set to a value that matches accessing fabric
Expand All @@ -50,9 +56,10 @@ struct AttributePathParams
mClusterId(aClusterId), mAttributeId(aAttributeId), mEndpointId(aEndpointId), mListIndex(aListIndex)
{}

AttributePathParams() {}

bool IsWildcardPath() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); }
[[nodiscard]] bool IsWildcardPath() const
{
return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId();
}

bool operator==(const AttributePathParams & aOther) const
{
Expand All @@ -66,12 +73,12 @@ struct AttributePathParams
* be wildcard. This does not verify that the attribute being targeted is actually of list type when the list index is not
* wildcard.
*/
bool IsValidAttributePath() const { return HasWildcardListIndex() || !HasWildcardAttributeId(); }
[[nodiscard]] bool IsValidAttributePath() const { return HasWildcardListIndex() || !HasWildcardAttributeId(); }

inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; }
inline bool HasWildcardAttributeId() const { return mAttributeId == kInvalidAttributeId; }
inline bool HasWildcardListIndex() const { return mListIndex == kInvalidListIndex; }
[[nodiscard]] inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
[[nodiscard]] inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; }
[[nodiscard]] inline bool HasWildcardAttributeId() const { return mAttributeId == kInvalidAttributeId; }
[[nodiscard]] inline bool HasWildcardListIndex() const { return mListIndex == kInvalidListIndex; }
inline void SetWildcardEndpointId() { mEndpointId = kInvalidEndpointId; }
inline void SetWildcardClusterId() { mClusterId = kInvalidClusterId; }
inline void SetWildcardAttributeId()
Expand All @@ -80,7 +87,7 @@ struct AttributePathParams
mListIndex = kInvalidListIndex;
}

bool IsAttributePathSupersetOf(const AttributePathParams & other) const
[[nodiscard]] bool IsAttributePathSupersetOf(const AttributePathParams & other) const
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
Expand All @@ -90,7 +97,7 @@ struct AttributePathParams
return true;
}

bool IsAttributePathSupersetOf(const ConcreteAttributePath & other) const
[[nodiscard]] bool IsAttributePathSupersetOf(const ConcreteAttributePath & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
}
else
{
status = emAfWriteAttributeExternal(request.path.mEndpointId, request.path.mClusterId, request.path.mAttributeId,
dataBuffer.data(), (*attributeMetadata)->attributeType);
status =
emAfWriteAttributeExternal(request.path, EmberAfWriteDataInput(dataBuffer.data(), (*attributeMetadata)->attributeType));
}

if (status != Protocols::InteractionModel::Status::Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "EmberReadWriteOverride.h"

#include <app/util/attribute-storage.h>
#include <app/util/attribute-table.h>
#include <app/util/ember-io-storage.h>
#include <lib/support/Span.h>

Expand Down Expand Up @@ -100,8 +101,7 @@ Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord,
return Status::Success;
}

Status emAfWriteAttributeExternal(chip::EndpointId endpoint, chip::ClusterId cluster, chip::AttributeId attributeID,
uint8_t * dataPtr, EmberAfAttributeType dataType)
Status emAfWriteAttributeExternal(const chip::app::ConcreteAttributePath & path, const EmberAfWriteDataInput & input)
{
if (gEmberStatusCode != Status::Success)
{
Expand All @@ -110,13 +110,13 @@ Status emAfWriteAttributeExternal(chip::EndpointId endpoint, chip::ClusterId clu

// ember here deduces the size of dataPtr. For testing however, we KNOW we read
// out of the ember IO buffer, so we try to use that
VerifyOrDie(dataPtr == chip::app::Compatibility::Internal::gEmberAttributeIOBufferSpan.data());
VerifyOrDie(input.dataPtr == chip::app::Compatibility::Internal::gEmberAttributeIOBufferSpan.data());

// In theory this should do type validation and sizes. This is NOT done for testing.
// copy over as much data as possible
// NOTE: we do NOT use (*metadata)->size since it is unclear if our mocks set that correctly
size_t len = std::min<size_t>(sizeof(gEmberIoBuffer), chip::app::Compatibility::Internal::gEmberAttributeIOBufferSpan.size());
memcpy(gEmberIoBuffer, dataPtr, len);
memcpy(gEmberIoBuffer, input.dataPtr, len);
gEmberIoBufferFill = len;

return Status::Success;
Expand All @@ -125,5 +125,6 @@ Status emAfWriteAttributeExternal(chip::EndpointId endpoint, chip::ClusterId clu
Status emberAfWriteAttribute(chip::EndpointId endpoint, chip::ClusterId cluster, chip::AttributeId attributeID, uint8_t * dataPtr,
EmberAfAttributeType dataType)
{
return emAfWriteAttributeExternal(endpoint, cluster, attributeID, dataPtr, dataType);
return emAfWriteAttributeExternal(chip::app::ConcreteAttributePath(endpoint, cluster, attributeID),
EmberAfWriteDataInput(dataPtr, dataType));
}
2 changes: 1 addition & 1 deletion src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ CHIP_ERROR Engine::InsertPathIntoDirtySet(const AttributePathParams & aAttribute
return CHIP_NO_ERROR;
}

CHIP_ERROR Engine::SetDirty(AttributePathParams & aAttributePath)
CHIP_ERROR Engine::SetDirty(const AttributePathParams & aAttributePath)
{
BumpDirtySetGeneration();

Expand Down
2 changes: 1 addition & 1 deletion src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Engine
/**
* Application marks mutated change path and would be sent out in later report.
*/
CHIP_ERROR SetDirty(AttributePathParams & aAttributePathParams);
CHIP_ERROR SetDirty(const AttributePathParams & aAttributePathParams);

/**
* @brief
Expand Down
42 changes: 8 additions & 34 deletions src/app/reporting/reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,23 @@
using namespace chip;
using namespace chip::app;

namespace {

void IncreaseClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPath)
{
DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath);
if (version == nullptr)
{
ChipLogError(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " not found in IncreaseClusterDataVersion!",
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId));
}
else
{
(*(version))++;
ChipLogDetail(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " update version to %" PRIx32,
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId), *(version));
}
}

} // namespace

void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId)
{
// Attribute writes have asserted this already, but this assert should catch
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

AttributePathParams info;
info.mClusterId = clusterId;
info.mAttributeId = attributeId;
info.mEndpointId = endpoint;

IncreaseClusterDataVersion(ConcreteClusterPath(endpoint, clusterId));
InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
emberAfAttributeChanged(endpoint, clusterId, attributeId, emberAfGlobalInteractionModelAttributesChangedListener());
}

void MatterReportingAttributeChangeCallback(const ConcreteAttributePath & aPath)
{
return MatterReportingAttributeChangeCallback(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
// Attribute writes have asserted this already, but this assert should catch
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

emberAfAttributeChanged(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId,
emberAfGlobalInteractionModelAttributesChangedListener());
}

void MatterReportingAttributeChangeCallback(EndpointId endpoint)
Expand All @@ -70,10 +49,5 @@ void MatterReportingAttributeChangeCallback(EndpointId endpoint)
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

AttributePathParams info;
info.mEndpointId = endpoint;

// We are adding or enabling a whole endpoint, in this case, we do not touch the cluster data version.

InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
emberAfEndpointChanged(endpoint, emberAfGlobalInteractionModelAttributesChangedListener());
}
11 changes: 11 additions & 0 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <app/util/attribute-metadata.h> // EmberAfAttributeMetadata

#include <app/AttributePathParams.h>
#include <app/ConcreteAttributePath.h>
#include <app/data-model/Nullable.h>
#include <lib/core/DataModelTypes.h>
Expand Down Expand Up @@ -314,5 +315,15 @@ enum class MarkAttributeDirty
kYes,
};

/// Notification object of a specific path being changed
class AttributesChangedListener
{
public:
virtual ~AttributesChangedListener() = default;

/// Called when the set of attributes identified by AttributePathParams (which may contain wildcards) is to be considered dirty.
virtual void MarkDirty(const AttributePathParams & path) = 0;
};

} // namespace app
} // namespace chip
Loading
Loading