Skip to content

Commit

Permalink
Make reporting::Engine able to use DataModel::Provider for cluster ve…
Browse files Browse the repository at this point in the history
…rsion checks (project-chip#35863)

* Update repoting Engine to be able to use DataModel::Provider for version checks.

* Restyle

* Fix an include

* Fix an include

* Fix an include

* Restyled by clang-format

* Update src/app/reporting/Read-Ember.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
4 people authored and yyzhong-g committed Dec 11, 2024
1 parent b262e47 commit fa8a558
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
*
*/

#include "app/data-model-provider/ActionReturnStatus.h"
#include <app/data-model-provider/ActionReturnStatus.h>
#include <app/icd/server/ICDServerConfig.h>
#include <app/reporting/Read-Checked.h>
#if CHIP_CONFIG_ENABLE_ICD_SERVER
#include <app/icd/server/ICDNotifier.h> // nogncheck
#endif
Expand Down Expand Up @@ -82,8 +83,10 @@ bool Engine::IsClusterDataVersionMatch(const SingleLinkedListNode<DataVersionFil
if (aPath.mEndpointId == filter->mValue.mEndpointId && aPath.mClusterId == filter->mValue.mClusterId)
{
existPathMatch = true;
if (!IsClusterDataVersionEqual(ConcreteClusterPath(filter->mValue.mEndpointId, filter->mValue.mClusterId),
filter->mValue.mDataVersion.Value()))

if (!Impl::IsClusterDataVersionEqualTo(mpImEngine->GetDataModelProvider(),
ConcreteClusterPath(filter->mValue.mEndpointId, filter->mValue.mClusterId),
filter->mValue.mDataVersion.Value()))
{
existVersionMismatch = true;
}
Expand Down
22 changes: 20 additions & 2 deletions src/app/reporting/Read-Checked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app/data-model-provider/ActionReturnStatus.h"
#include "lib/support/StringBuilder.h"
#include <app/reporting/Read-Checked.h>

#include <app/data-model-provider/ActionReturnStatus.h>
#include <app/reporting/Read-DataModel.h>
#include <app/reporting/Read-Ember.h>
#include <app/util/MatterCallbacks.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/StringBuilder.h>

namespace chip {
namespace app {
Expand Down Expand Up @@ -160,6 +161,23 @@ ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataModel, const Ac
return statusDm;
}

bool IsClusterDataVersionEqualTo(DataModel::Provider * dataModel, const ConcreteClusterPath & path, DataVersion dataVersion)
{
bool emberResult = EmberImpl::IsClusterDataVersionEqualTo(dataModel, path, dataVersion);
bool dmResult = DataModelImpl::IsClusterDataVersionEqualTo(dataModel, path, dataVersion);

if (emberResult != dmResult)
{
ChipLogError(Test, "Different data model check result between ember (%s) and data model provider(%s)",
emberResult ? "TRUE" : "FALSE", dmResult ? "TRUE" : "FALSE");
#if CHIP_CONFIG_DATA_MODEL_CHECK_DIE_ON_FAILURE
chipDie();
#endif
}

return dmResult;
}

} // namespace CheckedImpl
} // namespace reporting
} // namespace app
Expand Down
2 changes: 2 additions & 0 deletions src/app/reporting/Read-Checked.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
AttributeReportIBs::Builder & reportBuilder,
const ConcreteReadAttributePath & path, AttributeEncodeState * encoderState);

bool IsClusterDataVersionEqualTo(DataModel::Provider * dataModel, const ConcreteClusterPath & path, DataVersion dataVersion);

} // namespace CheckedImpl
} // namespace reporting
} // namespace app
Expand Down
16 changes: 14 additions & 2 deletions src/app/reporting/Read-DataModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app/data-model-provider/ActionReturnStatus.h"
#include "lib/support/logging/TextOnlyLogging.h"
#include <app/reporting/Read-DataModel.h>

#include <app/AppConfig.h>
#include <app/data-model-provider/ActionReturnStatus.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model-provider/Provider.h>
#include <app/util/MatterCallbacks.h>
#include <optional>

namespace chip {
namespace app {
Expand Down Expand Up @@ -101,6 +102,17 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
return status;
}

bool IsClusterDataVersionEqualTo(DataModel::Provider * dataModel, const ConcreteClusterPath & path, DataVersion dataVersion)
{
std::optional<DataModel::ClusterInfo> info = dataModel->GetClusterInfo(path);
if (!info.has_value())
{
return false;
}

return (info->dataVersion == dataVersion);
}

} // namespace DataModelImpl
} // namespace reporting
} // namespace app
Expand Down
2 changes: 2 additions & 0 deletions src/app/reporting/Read-DataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
AttributeReportIBs::Builder & reportBuilder,
const ConcreteReadAttributePath & path, AttributeEncodeState * encoderState);

bool IsClusterDataVersionEqualTo(DataModel::Provider * dataModel, const ConcreteClusterPath & path, DataVersion dataVersion);

} // namespace DataModelImpl
} // namespace reporting
} // namespace app
Expand Down
7 changes: 6 additions & 1 deletion src/app/reporting/Read-Ember.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app/data-model-provider/ActionReturnStatus.h"
#include <app/reporting/Read-Ember.h>

#include <app/AppConfig.h>
#include <app/data-model-provider/ActionReturnStatus.h>
#include <app/util/MatterCallbacks.h>
#include <app/util/ember-compatibility-functions.h>

Expand Down Expand Up @@ -51,6 +51,11 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
return CHIP_NO_ERROR;
}

bool IsClusterDataVersionEqualTo(DataModel::Provider * dataModel, const ConcreteClusterPath & path, DataVersion dataVersion)
{
return IsClusterDataVersionEqual(path, dataVersion);
}

} // namespace EmberImpl
} // namespace reporting
} // namespace app
Expand Down
4 changes: 4 additions & 0 deletions src/app/reporting/Read-Ember.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

#include <access/SubjectDescriptor.h>
#include <app/AttributeEncodeState.h>
#include <app/ConcreteClusterPath.h>
#include <app/MessageDef/AttributeReportIBs.h>
#include <app/data-model-provider/ActionReturnStatus.h>
#include <app/data-model-provider/Provider.h>
#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>

namespace chip {
namespace app {
Expand All @@ -33,6 +35,8 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
AttributeReportIBs::Builder & reportBuilder,
const ConcreteReadAttributePath & path, AttributeEncodeState * encoderState);

bool IsClusterDataVersionEqualTo(DataModel::Provider * dataModel, const ConcreteClusterPath & path, DataVersion dataVersion);

} // namespace EmberImpl
} // namespace reporting
} // namespace app
Expand Down
1 change: 1 addition & 0 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class TestReadInteraction : public chip::Test::AppContext
gCircularEventBuffer, logStorageResources, &mEventCounter);
mOldProvider = InteractionModelEngine::GetInstance()->SetDataModelProvider(&TestImCustomDataModel::Instance());
chip::Test::SetMockNodeConfig(TestMockNodeConfig());
chip::Test::SetVersionTo(chip::Test::kTestDataVersion1);
}
void TearDown() override
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/util/mock/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void BumpVersion();
/// Sets GetVersion to return 0
void ResetVersion();

/// Force the global cluster version to a specific value
void SetVersionTo(DataVersion version);

/// Gets the current value for the version that will
/// be returned by emberAfDataVersionStorage
DataVersion GetVersion();
Expand Down
5 changes: 5 additions & 0 deletions src/app/util/mock/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ DataVersion GetVersion()
return dataVersion;
}

void SetVersionTo(DataVersion version)
{
dataVersion = version;
}

CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const ConcreteAttributePath & aPath,
AttributeReportIBs::Builder & aAttributeReports, AttributeEncodeState * apEncoderState)
{
Expand Down

0 comments on commit fa8a558

Please sign in to comment.