Skip to content

Commit 6998926

Browse files
committed
Make codegen data model call increasing the cluster data version
1 parent 0078f8d commit 6998926

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

src/app/codegen-data-model-provider/CodegenDataModelProvider_Write.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include "app/util/attribute-storage.h"
1718
#include <app/codegen-data-model-provider/CodegenDataModelProvider.h>
1819

1920
#include <access/AccessControl.h>
@@ -356,6 +357,8 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
356357
// however for now this is called directly because ember code does this call
357358
// inside emberAfWriteAttribute.
358359
MatterReportingAttributeChangeCallback(request.path);
360+
361+
emberAfIncreaseClusterDataVersion(request.path);
359362
CurrentContext().dataModelChangeListener->MarkDirty(request.path);
360363
}
361364
return *aai_result;
@@ -398,6 +401,7 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
398401
// - This likely maps to `MatterReportingAttributeChangeCallback` HOWEVER current ember write functions
399402
// will selectively call that one depending on old attribute state (i.e. calling every time is a
400403
// change in behavior)
404+
emberAfIncreaseClusterDataVersion(request.path);
401405
CurrentContext().dataModelChangeListener->MarkDirty(request.path);
402406
return CHIP_NO_ERROR;
403407
}

src/app/reporting/Engine.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,10 @@ void Engine::MarkDirty(const ConcreteAttributePath & path)
10091009
{
10101010
// NOTE: original MatterReportingAttributeChangeCallback ALSO does a
10111011
// IncreaseClusterDataVersion. However that ties directly to ember so it is not
1012-
// done here. The code should be migrated to execute this.
1013-
1012+
// done here.
1013+
//
1014+
// Instead the DataModel::Provider is responsible to properly increase cluster
1015+
// data versions.
10141016
AttributePathParams info(path.mEndpointId, path.mClusterId, path.mAttributeId);
10151017
CHIP_ERROR err = SetDirty(info);
10161018
if (err != CHIP_NO_ERROR)

src/app/reporting/reporting.cpp

+2-21
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,19 @@
2424
using namespace chip;
2525
using namespace chip::app;
2626

27-
namespace {
28-
29-
void IncreaseClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPath)
30-
{
31-
DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath);
32-
if (version == nullptr)
33-
{
34-
ChipLogError(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " not found in IncreaseClusterDataVersion!",
35-
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId));
36-
}
37-
else
38-
{
39-
(*(version))++;
40-
ChipLogDetail(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " update version to %" PRIx32,
41-
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId), *(version));
42-
}
43-
}
44-
45-
} // namespace
46-
4727
void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId)
4828
{
4929
// Attribute writes have asserted this already, but this assert should catch
5030
// applications notifying about changes from their end.
5131
assertChipStackLockedByCurrentThread();
5232

33+
emberAfIncreaseClusterDataVersion(ConcreteClusterPath(endpoint, clusterId));
34+
5335
AttributePathParams info;
5436
info.mClusterId = clusterId;
5537
info.mAttributeId = attributeId;
5638
info.mEndpointId = endpoint;
5739

58-
IncreaseClusterDataVersion(ConcreteClusterPath(endpoint, clusterId));
5940
InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
6041
}
6142

src/app/util/attribute-storage.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "app/ConcreteClusterPath.h"
1819
#include <app/util/attribute-storage.h>
1920

2021
#include <app/util/attribute-storage-detail.h>
@@ -1462,3 +1463,20 @@ DataVersion * emberAfDataVersionStorage(const chip::app::ConcreteClusterPath & a
14621463

14631464
return ep.dataVersions + clusterIndex;
14641465
}
1466+
1467+
void emberAfIncreaseClusterDataVersion(const chip::app::ConcreteClusterPath & aConcreteClusterPath)
1468+
{
1469+
DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath);
1470+
if (version == nullptr)
1471+
{
1472+
ChipLogError(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " not found in IncreaseClusterDataVersion!",
1473+
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId));
1474+
}
1475+
else
1476+
{
1477+
(*(version))++;
1478+
ChipLogDetail(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " update version to %" PRIx32,
1479+
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId), *(version));
1480+
}
1481+
}
1482+

src/app/util/attribute-storage.h

+7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::C
177177
*/
178178
chip::DataVersion * emberAfDataVersionStorage(const chip::app::ConcreteClusterPath & aConcreteClusterPath);
179179

180+
/**
181+
* Increases the cluster version for the specified path.
182+
*
183+
* Will log errors in case the version storage for the given path does not exist.
184+
*/
185+
void emberAfIncreaseClusterDataVersion(const chip::app::ConcreteClusterPath & aConcreteClusterPath);
186+
180187
/**
181188
* @brief Returns the number of pre-compiled endpoints.
182189
*/

src/app/util/mock/attribute-storage.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ DataVersion * emberAfDataVersionStorage(const chip::app::ConcreteClusterPath & a
313313
return &dataVersion;
314314
}
315315

316+
void emberAfIncreaseClusterDataVersion(const chip::app::ConcreteClusterPath & aConcreteClusterPath)
317+
{
318+
dataVersion++;
319+
}
320+
316321
namespace chip {
317322
namespace app {
318323

0 commit comments

Comments
 (0)