Remove one more direct ember coupling in reporting engine (using of CheckEventSupportStatus from ember-compatibility) (#35873)
* Update event support checks
* Fix an include
* Restyled by clang-format
* Fix typo
* Restyled by clang-format
* Added a EndpointExists call to the datamodel provider along with a default implementation
* Remove missing config use after merge with master
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp b/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp
index 4796aa0..afba240 100644
--- a/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp
+++ b/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp
@@ -386,6 +386,11 @@
return std::nullopt;
}
+bool CodegenDataModelProvider::EndpointExists(EndpointId endpoint)
+{
+ return (emberAfIndexFromEndpoint(endpoint) != kEmberInvalidEndpointIndex);
+}
+
EndpointId CodegenDataModelProvider::FirstEndpoint()
{
// find the first enabled index
diff --git a/src/app/codegen-data-model-provider/CodegenDataModelProvider.h b/src/app/codegen-data-model-provider/CodegenDataModelProvider.h
index 990c9e7..500b491 100644
--- a/src/app/codegen-data-model-provider/CodegenDataModelProvider.h
+++ b/src/app/codegen-data-model-provider/CodegenDataModelProvider.h
@@ -96,6 +96,7 @@
/// attribute tree iteration
EndpointId FirstEndpoint() override;
EndpointId NextEndpoint(EndpointId before) override;
+ bool EndpointExists(EndpointId endpoint) override;
DataModel::ClusterEntry FirstCluster(EndpointId endpoint) override;
DataModel::ClusterEntry NextCluster(const ConcreteClusterPath & before) override;
diff --git a/src/app/data-model-provider/MetadataTypes.cpp b/src/app/data-model-provider/MetadataTypes.cpp
index 3ff238d..ed3e266 100644
--- a/src/app/data-model-provider/MetadataTypes.cpp
+++ b/src/app/data-model-provider/MetadataTypes.cpp
@@ -30,6 +30,19 @@
.info = ClusterInfo(0 /* version */), // version of invalid cluster entry does not matter
};
+// A default implementation if just first/next exist
+bool ProviderMetadataTree::EndpointExists(EndpointId endpoint)
+{
+ for (EndpointId id = FirstEndpoint(); id != kInvalidEndpointId; id = NextEndpoint(id))
+ {
+ if (id == endpoint)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace DataModel
} // namespace app
} // namespace chip
diff --git a/src/app/data-model-provider/MetadataTypes.h b/src/app/data-model-provider/MetadataTypes.h
index 5e46d63..65c89da 100644
--- a/src/app/data-model-provider/MetadataTypes.h
+++ b/src/app/data-model-provider/MetadataTypes.h
@@ -128,6 +128,7 @@
virtual EndpointId FirstEndpoint() = 0;
virtual EndpointId NextEndpoint(EndpointId before) = 0;
+ virtual bool EndpointExists(EndpointId id);
virtual ClusterEntry FirstCluster(EndpointId endpoint) = 0;
virtual ClusterEntry NextCluster(const ConcreteClusterPath & before) = 0;
diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp
index 7ffadfd..2dd0873 100644
--- a/src/app/reporting/Engine.cpp
+++ b/src/app/reporting/Engine.cpp
@@ -16,33 +16,51 @@
* limitations under the License.
*/
-/**
- * @file
- * This file implements reporting engine for CHIP
- * Data Model profile.
- *
- */
-
-#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
#include <app/AppConfig.h>
+#include <app/ConcreteEventPath.h>
#include <app/InteractionModelEngine.h>
#include <app/RequiredPrivilege.h>
+#include <app/data-model-provider/ActionReturnStatus.h>
+#include <app/data-model-provider/Provider.h>
+#include <app/icd/server/ICDServerConfig.h>
#include <app/reporting/Engine.h>
+#include <app/reporting/Read-Checked.h>
#include <app/reporting/Read.h>
#include <app/reporting/reporting.h>
#include <app/util/MatterCallbacks.h>
#include <app/util/ember-compatibility-functions.h>
+#include <lib/core/DataModelTypes.h>
+#include <protocols/interaction_model/StatusCode.h>
+
+#if CHIP_CONFIG_ENABLE_ICD_SERVER
+#include <app/icd/server/ICDNotifier.h> // nogncheck
+#endif
using namespace chip::Access;
namespace chip {
namespace app {
namespace reporting {
+namespace {
+
+using Protocols::InteractionModel::Status;
+
+Status EventPathValid(DataModel::Provider * model, const ConcreteEventPath & eventPath)
+{
+#if CHIP_CONFIG_USE_DATA_MODEL_INTERFACE
+
+ if (!model->GetClusterInfo(eventPath).has_value())
+ {
+ return model->EndpointExists(eventPath.mEndpointId) ? Status::UnsupportedCluster : Status::UnsupportedEndpoint;
+ }
+
+ return Status::Success;
+#else
+ return CheckEventSupportStatus(eventPath);
+#endif
+}
+
+} // namespace
Engine::Engine(InteractionModelEngine * apImEngine) : mpImEngine(apImEngine) {}
@@ -330,7 +348,8 @@
}
ConcreteEventPath path(current->mValue.mEndpointId, current->mValue.mClusterId, current->mValue.mEventId);
- Status status = CheckEventSupportStatus(path);
+ Status status = EventPathValid(mpImEngine->GetDataModelProvider(), path);
+
if (status != Status::Success)
{
TLV::TLVWriter checkpoint = aWriter;