Skip to content

Commit

Permalink
Remove one more direct ember coupling in reporting engine (using of C…
Browse files Browse the repository at this point in the history
…heckEventSupportStatus 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 <[email protected]>
  • Loading branch information
andy31415 and restyled-commits authored Oct 3, 2024
1 parent 6cc76c1 commit 0564a26
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ std::optional<DataModel::ActionReturnStatus> CodegenDataModelProvider::Invoke(co
return std::nullopt;
}

bool CodegenDataModelProvider::EndpointExists(EndpointId endpoint)
{
return (emberAfIndexFromEndpoint(endpoint) != kEmberInvalidEndpointIndex);
}

EndpointId CodegenDataModelProvider::FirstEndpoint()
{
// find the first enabled index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CodegenDataModelProvider : public chip::app::DataModel::Provider
/// 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;
Expand Down
13 changes: 13 additions & 0 deletions src/app/data-model-provider/MetadataTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ const ClusterEntry ClusterEntry::kInvalid{
.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
1 change: 1 addition & 0 deletions src/app/data-model-provider/MetadataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ProviderMetadataTree

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;
Expand Down
47 changes: 33 additions & 14 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -330,7 +348,8 @@ CHIP_ERROR Engine::CheckAccessDeniedEventPaths(TLV::TLVWriter & aWriter, bool &
}

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;
Expand Down

0 comments on commit 0564a26

Please sign in to comment.