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

Make reporting::Engine able to use DataModel::Provider for cluster version checks #35863

Merged
merged 8 commits into from
Oct 2, 2024
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
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 @@ -72,8 +73,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
Loading