Skip to content

Commit 0564a26

Browse files
Remove one more direct ember coupling in reporting engine (using of CheckEventSupportStatus from ember-compatibility) (project-chip#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>
1 parent 6cc76c1 commit 0564a26

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ std::optional<DataModel::ActionReturnStatus> CodegenDataModelProvider::Invoke(co
386386
return std::nullopt;
387387
}
388388

389+
bool CodegenDataModelProvider::EndpointExists(EndpointId endpoint)
390+
{
391+
return (emberAfIndexFromEndpoint(endpoint) != kEmberInvalidEndpointIndex);
392+
}
393+
389394
EndpointId CodegenDataModelProvider::FirstEndpoint()
390395
{
391396
// find the first enabled index

src/app/codegen-data-model-provider/CodegenDataModelProvider.h

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class CodegenDataModelProvider : public chip::app::DataModel::Provider
9696
/// attribute tree iteration
9797
EndpointId FirstEndpoint() override;
9898
EndpointId NextEndpoint(EndpointId before) override;
99+
bool EndpointExists(EndpointId endpoint) override;
99100

100101
DataModel::ClusterEntry FirstCluster(EndpointId endpoint) override;
101102
DataModel::ClusterEntry NextCluster(const ConcreteClusterPath & before) override;

src/app/data-model-provider/MetadataTypes.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ const ClusterEntry ClusterEntry::kInvalid{
3030
.info = ClusterInfo(0 /* version */), // version of invalid cluster entry does not matter
3131
};
3232

33+
// A default implementation if just first/next exist
34+
bool ProviderMetadataTree::EndpointExists(EndpointId endpoint)
35+
{
36+
for (EndpointId id = FirstEndpoint(); id != kInvalidEndpointId; id = NextEndpoint(id))
37+
{
38+
if (id == endpoint)
39+
{
40+
return true;
41+
}
42+
}
43+
return false;
44+
}
45+
3346
} // namespace DataModel
3447
} // namespace app
3548
} // namespace chip

src/app/data-model-provider/MetadataTypes.h

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class ProviderMetadataTree
128128

129129
virtual EndpointId FirstEndpoint() = 0;
130130
virtual EndpointId NextEndpoint(EndpointId before) = 0;
131+
virtual bool EndpointExists(EndpointId id);
131132

132133
virtual ClusterEntry FirstCluster(EndpointId endpoint) = 0;
133134
virtual ClusterEntry NextCluster(const ConcreteClusterPath & before) = 0;

src/app/reporting/Engine.cpp

+33-14
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,51 @@
1616
* limitations under the License.
1717
*/
1818

19-
/**
20-
* @file
21-
* This file implements reporting engine for CHIP
22-
* Data Model profile.
23-
*
24-
*/
25-
26-
#include <app/data-model-provider/ActionReturnStatus.h>
27-
#include <app/icd/server/ICDServerConfig.h>
28-
#include <app/reporting/Read-Checked.h>
29-
#if CHIP_CONFIG_ENABLE_ICD_SERVER
30-
#include <app/icd/server/ICDNotifier.h> // nogncheck
31-
#endif
3219
#include <app/AppConfig.h>
20+
#include <app/ConcreteEventPath.h>
3321
#include <app/InteractionModelEngine.h>
3422
#include <app/RequiredPrivilege.h>
23+
#include <app/data-model-provider/ActionReturnStatus.h>
24+
#include <app/data-model-provider/Provider.h>
25+
#include <app/icd/server/ICDServerConfig.h>
3526
#include <app/reporting/Engine.h>
27+
#include <app/reporting/Read-Checked.h>
3628
#include <app/reporting/Read.h>
3729
#include <app/reporting/reporting.h>
3830
#include <app/util/MatterCallbacks.h>
3931
#include <app/util/ember-compatibility-functions.h>
32+
#include <lib/core/DataModelTypes.h>
33+
#include <protocols/interaction_model/StatusCode.h>
34+
35+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
36+
#include <app/icd/server/ICDNotifier.h> // nogncheck
37+
#endif
4038

4139
using namespace chip::Access;
4240

4341
namespace chip {
4442
namespace app {
4543
namespace reporting {
44+
namespace {
45+
46+
using Protocols::InteractionModel::Status;
47+
48+
Status EventPathValid(DataModel::Provider * model, const ConcreteEventPath & eventPath)
49+
{
50+
#if CHIP_CONFIG_USE_DATA_MODEL_INTERFACE
51+
52+
if (!model->GetClusterInfo(eventPath).has_value())
53+
{
54+
return model->EndpointExists(eventPath.mEndpointId) ? Status::UnsupportedCluster : Status::UnsupportedEndpoint;
55+
}
56+
57+
return Status::Success;
58+
#else
59+
return CheckEventSupportStatus(eventPath);
60+
#endif
61+
}
62+
63+
} // namespace
4664

4765
Engine::Engine(InteractionModelEngine * apImEngine) : mpImEngine(apImEngine) {}
4866

@@ -330,7 +348,8 @@ CHIP_ERROR Engine::CheckAccessDeniedEventPaths(TLV::TLVWriter & aWriter, bool &
330348
}
331349

332350
ConcreteEventPath path(current->mValue.mEndpointId, current->mValue.mClusterId, current->mValue.mEventId);
333-
Status status = CheckEventSupportStatus(path);
351+
Status status = EventPathValid(mpImEngine->GetDataModelProvider(), path);
352+
334353
if (status != Status::Success)
335354
{
336355
TLV::TLVWriter checkpoint = aWriter;

0 commit comments

Comments
 (0)