Skip to content

Commit 994c390

Browse files
Make use of DataModel::Provider device type resolution in the access control (project-chip#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 <andreilitvin@google.com>
1 parent e814987 commit 994c390

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/app/server/Server.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
#include <access/examples/ExampleAccessControlDelegate.h>
2121

22+
#include <app/AppConfig.h>
2223
#include <app/EventManagement.h>
2324
#include <app/InteractionModelEngine.h>
25+
#include <app/data-model-provider/Provider.h>
2426
#include <app/server/Dnssd.h>
2527
#include <app/server/EchoHandler.h>
2628
#include <app/util/DataModelHandler.h>
@@ -81,6 +83,33 @@ using chip::Transport::TcpListenParameters;
8183

8284
namespace {
8385

86+
#if CHIP_CONFIG_USE_DATA_MODEL_INTERFACE
87+
class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolver
88+
{
89+
public:
90+
bool IsDeviceTypeOnEndpoint(chip::DeviceTypeId deviceType, chip::EndpointId endpoint) override
91+
{
92+
chip::app::DataModel::Provider * model = chip::app::InteractionModelEngine::GetInstance()->GetDataModelProvider();
93+
94+
for (auto type = model->FirstDeviceType(endpoint); type.has_value(); type = model->NextDeviceType(endpoint, *type))
95+
{
96+
if (type->deviceTypeId == deviceType)
97+
{
98+
#if CHIP_CONFIG_USE_EMBER_DATA_MODEL
99+
VerifyOrDie(chip::app::IsDeviceTypeOnEndpoint(deviceType, endpoint));
100+
#endif // CHIP_CONFIG_USE_EMBER_DATA_MODEL
101+
return true;
102+
}
103+
}
104+
#if CHIP_CONFIG_USE_EMBER_DATA_MODEL
105+
VerifyOrDie(!chip::app::IsDeviceTypeOnEndpoint(deviceType, endpoint));
106+
#endif // CHIP_CONFIG_USE_EMBER_DATA_MODEL
107+
return false;
108+
}
109+
} sDeviceTypeResolver;
110+
#else // CHIP_CONFIG_USE_DATA_MODEL_INTERFACE
111+
112+
// Ember implementation of the device type resolver
84113
class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolver
85114
{
86115
public:
@@ -89,6 +118,7 @@ class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolve
89118
return chip::app::IsDeviceTypeOnEndpoint(deviceType, endpoint);
90119
}
91120
} sDeviceTypeResolver;
121+
#endif
92122

93123
} // namespace
94124

0 commit comments

Comments
 (0)