Skip to content

Commit

Permalink
Make use of DataModel::Provider device type resolution in the access …
Browse files Browse the repository at this point in the history
…control (#35862)

* Add separate listing for device types

* Make unit tests work

* Restyle

* Fixup include

* Fixup include

* Make use of DataModel::Provider when doing device type resolution

* Add clang-tidy comments

* Fix merge error: duplicate declaration

* Fix a few more merge conflict markers

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored Oct 4, 2024
1 parent e814987 commit 994c390
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

#include <access/examples/ExampleAccessControlDelegate.h>

#include <app/AppConfig.h>
#include <app/EventManagement.h>
#include <app/InteractionModelEngine.h>
#include <app/data-model-provider/Provider.h>
#include <app/server/Dnssd.h>
#include <app/server/EchoHandler.h>
#include <app/util/DataModelHandler.h>
Expand Down Expand Up @@ -81,6 +83,33 @@ using chip::Transport::TcpListenParameters;

namespace {

#if CHIP_CONFIG_USE_DATA_MODEL_INTERFACE
class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolver
{
public:
bool IsDeviceTypeOnEndpoint(chip::DeviceTypeId deviceType, chip::EndpointId endpoint) override
{
chip::app::DataModel::Provider * model = chip::app::InteractionModelEngine::GetInstance()->GetDataModelProvider();

for (auto type = model->FirstDeviceType(endpoint); type.has_value(); type = model->NextDeviceType(endpoint, *type))
{
if (type->deviceTypeId == deviceType)
{
#if CHIP_CONFIG_USE_EMBER_DATA_MODEL
VerifyOrDie(chip::app::IsDeviceTypeOnEndpoint(deviceType, endpoint));
#endif // CHIP_CONFIG_USE_EMBER_DATA_MODEL
return true;
}
}
#if CHIP_CONFIG_USE_EMBER_DATA_MODEL
VerifyOrDie(!chip::app::IsDeviceTypeOnEndpoint(deviceType, endpoint));
#endif // CHIP_CONFIG_USE_EMBER_DATA_MODEL
return false;
}
} sDeviceTypeResolver;
#else // CHIP_CONFIG_USE_DATA_MODEL_INTERFACE

// Ember implementation of the device type resolver
class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolver
{
public:
Expand All @@ -89,6 +118,7 @@ class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolve
return chip::app::IsDeviceTypeOnEndpoint(deviceType, endpoint);
}
} sDeviceTypeResolver;
#endif

} // namespace

Expand Down

0 comments on commit 994c390

Please sign in to comment.