Skip to content

Commit 9a1d0a7

Browse files
zaid-googlerestyled-commitsandy31415Copilot
authored
Code Driven All Devices Example App (project-chip#41607)
* Initial draft of all devices example app * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Address some review comments * Address more review comments * Restyled by whitespace * Restyled by clang-format * Restyled by gn * More review comments * Review comments for BUILD.gn configs * Restyled by clang-format * Restyled by gn * Add TODOs based on review comments * Restyled by whitespace * Restyled by clang-format * Update wifi diagnostics optional atteribute set usage * Remove SemanticTags function from Device * Restyled by clang-format * Make device endpoint a command line argument * Cleanup includes and remove old args.gni * Address comments, make command line args seperate from main * Restyled by whitespace * Restyled by clang-format * Restyled by gn * separation of base device with single endpoint device * Add comments, fix unregister calls, cleanup of member variables * Remove unique pointer for timer * Restyled by whitespace * Restyled by clang-format * update comment * Restyled by whitespace * Restructure device interfaces * Add all devices app build and basic composition test to CI * Restyled by clang-format * Remove build variants for CI, not currently supported * Fix path for all devices app in CI * Update device info provider used * Update comments * Restyled by whitespace * Restyled by clang-format * Add new device info provider * Restyled by whitespace * Restyled by clang-format * Update examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp Co-authored-by: Copilot <[email protected]> * Update examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h Co-authored-by: Copilot <[email protected]> * Update examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h Co-authored-by: Copilot <[email protected]> * Update examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h Co-authored-by: Copilot <[email protected]> * Fix build * Init on network commissioning * Remove unnecessary build gni imports * Restyled by whitespace * Restyled by clang-format * Restyled by gn * zcl updates * Revert "zcl updates" This reverts commit 70760c5. * Update dependencies and defines * Update with timer delegate changes * Restyled by clang-format * fix build file --------- Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Andrei Litvin <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent b68b0d1 commit 9a1d0a7

33 files changed

+1569
-48
lines changed

.github/workflows/tests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,15 @@ jobs:
665665
&& rm -rf out/linux-x64-all-clusters-${BUILD_VARIANT}-tsan-clang-test
666666
"
667667
668+
- name: Build linux-x64-all-devices-app
669+
env:
670+
CCACHE_DIR: "${{ github.workspace }}/.ccache"
671+
run: >-
672+
./scripts/run_in_build_env.sh "./scripts/build/build_examples.py
673+
--target linux-x64-all-devices-app-tsan-clang-test
674+
--pw-command-launcher=ccache build --copy-artifacts-to objdir-clone
675+
&& rm -rf out/linux-x64-all-devices-app-tsan-clang-test"
676+
668677
- name: Build linux-x64-lit-icd
669678
env:
670679
CCACHE_DIR: "${{ github.workspace }}/.ccache"
@@ -835,6 +844,7 @@ jobs:
835844
run: |
836845
echo -n "" >/tmp/test_env.yaml
837846
echo "ALL_CLUSTERS_APP: objdir-clone/linux-x64-all-clusters-${BUILD_VARIANT}-tsan-clang-test/chip-all-clusters-app" >> /tmp/test_env.yaml
847+
echo "ALL_DEVICES_APP: objdir-clone/linux-x64-all-devices-app-tsan-clang-test/all-devices-app" >> /tmp/test_env.yaml
838848
echo "BRIDGE_APP: objdir-clone/linux-x64-bridge-${BUILD_VARIANT}-tsan-clang-test-unified/chip-bridge-app" >> /tmp/test_env.yaml
839849
echo "CHIP_LOCK_APP: objdir-clone/linux-x64-lock-${BUILD_VARIANT}-tsan-clang-test-unified/chip-lock-app" >> /tmp/test_env.yaml
840850
echo "CAMERA_APP: objdir-clone/linux-x64-camera/chip-camera-app" >> /tmp/test_env.yaml
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2025 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
config("includes") {
16+
# allows includes like "devices/..."
17+
include_dirs = [ ".." ]
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2025 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
source_set("boolean-state-sensor") {
19+
sources = [
20+
"BooleanStateSensorDevice.cpp",
21+
"BooleanStateSensorDevice.h",
22+
]
23+
24+
public_deps = [
25+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/interface:single-endpoint-device",
26+
"${chip_root}/src/app/clusters/boolean-state-server",
27+
"${chip_root}/src/app/clusters/identify-server",
28+
"${chip_root}/src/data-model-providers/codedriven",
29+
"${chip_root}/src/lib/core:error",
30+
"${chip_root}/src/lib/support",
31+
]
32+
33+
public_configs = [
34+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes",
35+
"${chip_root}/src:includes",
36+
]
37+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include <devices/boolean-state-sensor/BooleanStateSensorDevice.h>
18+
19+
using namespace chip::app::Clusters;
20+
21+
namespace chip::app {
22+
23+
CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider,
24+
EndpointId parentId)
25+
{
26+
ReturnErrorOnFailure(SingleEndpointRegistration(endpoint, provider, parentId));
27+
28+
mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, *mTimerDelegate));
29+
ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration()));
30+
31+
mBooleanStateCluster.Create(endpoint);
32+
ReturnErrorOnFailure(provider.AddCluster(mBooleanStateCluster.Registration()));
33+
34+
return provider.AddEndpoint(mEndpointRegistration);
35+
}
36+
37+
void BooleanStateSensorDevice::UnRegister(CodeDrivenDataModelProvider & provider)
38+
{
39+
SingleEndpointUnregistration(provider);
40+
if (mBooleanStateCluster.IsConstructed())
41+
{
42+
provider.RemoveCluster(&mBooleanStateCluster.Cluster());
43+
mBooleanStateCluster.Destroy();
44+
}
45+
if (mIdentifyCluster.IsConstructed())
46+
{
47+
provider.RemoveCluster(&mIdentifyCluster.Cluster());
48+
mIdentifyCluster.Destroy();
49+
}
50+
}
51+
52+
} // namespace chip::app
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
#include <app/clusters/boolean-state-server/boolean-state-cluster.h>
20+
#include <app/clusters/identify-server/IdentifyCluster.h>
21+
#include <devices/interface/SingleEndpointDevice.h>
22+
#include <lib/support/TimerDelegate.h>
23+
#include <memory>
24+
25+
namespace chip {
26+
namespace app {
27+
28+
class BooleanStateSensorDevice : public SingleEndpointDevice
29+
{
30+
public:
31+
/// This is a general class for boolean state sensor devices. The device type passed here will
32+
/// determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable
33+
/// class for the sensor types that share the same core functionality through the identify and
34+
/// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying
35+
/// data for the Span of deviceTypes remains valid for the entire lifetime of the BooleanStateSensorDevice object instance.
36+
BooleanStateSensorDevice(TimerDelegate * timerDelegate, Span<const DataModel::DeviceTypeEntry> deviceType) :
37+
SingleEndpointDevice(deviceType), mTimerDelegate(timerDelegate)
38+
{}
39+
~BooleanStateSensorDevice() override = default;
40+
41+
CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider,
42+
EndpointId parentId = kInvalidEndpointId) override;
43+
void UnRegister(CodeDrivenDataModelProvider & provider) override;
44+
45+
Clusters::BooleanStateCluster & BooleanState() { return mBooleanStateCluster.Cluster(); }
46+
47+
private:
48+
TimerDelegate * mTimerDelegate;
49+
LazyRegisteredServerCluster<Clusters::IdentifyCluster> mIdentifyCluster;
50+
LazyRegisteredServerCluster<Clusters::BooleanStateCluster> mBooleanStateCluster;
51+
};
52+
53+
} // namespace app
54+
} // namespace chip
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2025 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
source_set("device-factory") {
19+
sources = [ "DeviceFactory.h" ]
20+
21+
public_deps = [
22+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor",
23+
"${chip_root}/src/lib/core:error",
24+
"${chip_root}/zzz_generated/app-common/devices/",
25+
]
26+
27+
public_configs = [
28+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes",
29+
"${chip_root}/src:includes",
30+
]
31+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <app/DefaultTimerDelegate.h>
21+
#include <devices/Types.h>
22+
#include <devices/boolean-state-sensor/BooleanStateSensorDevice.h>
23+
#include <functional>
24+
#include <lib/core/CHIPError.h>
25+
#include <map>
26+
27+
namespace chip::app {
28+
29+
/**
30+
* This is a factory class made to be used to create any valid device type as part of the
31+
* all-devices-app. This class is meant to abstract away some details of device specific code,
32+
* and to have more generic implementation code being used in main to create a device. The keys
33+
* in the device registry map are the command line arguments used to start the respective device.
34+
* Create devices by fetching the instance of this class and passing in the device type argument
35+
* i.e. DeviceFactory::GetInstance().Create(deviceTypeName)
36+
*/
37+
class DeviceFactory
38+
{
39+
public:
40+
using DeviceCreator = std::function<std::unique_ptr<DeviceInterface>()>;
41+
42+
static DeviceFactory & GetInstance()
43+
{
44+
static DeviceFactory instance;
45+
return instance;
46+
}
47+
48+
bool IsValidDevice(const std::string & deviceTypeArg) { return mRegistry.find(deviceTypeArg) != mRegistry.end(); }
49+
50+
std::unique_ptr<DeviceInterface> Create(const std::string & deviceTypeArg)
51+
{
52+
if (IsValidDevice(deviceTypeArg))
53+
{
54+
return mRegistry.find(deviceTypeArg)->second();
55+
}
56+
else
57+
{
58+
ChipLogError(
59+
Support,
60+
"INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n",
61+
deviceTypeArg.c_str());
62+
}
63+
return nullptr;
64+
}
65+
66+
private:
67+
std::map<std::string, DeviceCreator> mRegistry;
68+
DefaultTimerDelegate timer;
69+
70+
DeviceFactory()
71+
{
72+
mRegistry["contact-sensor"] = [this]() {
73+
return std::make_unique<BooleanStateSensorDevice>(
74+
&timer, Span<const DataModel::DeviceTypeEntry>(&Device::Type::kContactSensor, 1));
75+
};
76+
mRegistry["water-leak-detector"] = [this]() {
77+
return std::make_unique<BooleanStateSensorDevice>(
78+
&timer, Span<const DataModel::DeviceTypeEntry>(&Device::Type::kWaterLeakDetector, 1));
79+
};
80+
}
81+
};
82+
83+
} // namespace chip::app
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2025 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
source_set("device-interface") {
19+
sources = [
20+
"DeviceInterface.cpp",
21+
"DeviceInterface.h",
22+
]
23+
24+
public_deps = [
25+
"${chip_root}/src/app/clusters/descriptor",
26+
"${chip_root}/src/data-model-providers/codedriven",
27+
"${chip_root}/src/lib/core:error",
28+
"${chip_root}/src/lib/support",
29+
]
30+
31+
public_configs = [
32+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes",
33+
"${chip_root}/src:includes",
34+
]
35+
}
36+
37+
source_set("single-endpoint-device") {
38+
sources = [
39+
"SingleEndpointDevice.cpp",
40+
"SingleEndpointDevice.h",
41+
]
42+
43+
public_deps = [
44+
":device-interface",
45+
"${chip_root}/src/app/clusters/descriptor",
46+
"${chip_root}/src/data-model-providers/codedriven",
47+
"${chip_root}/src/lib/core:error",
48+
"${chip_root}/src/lib/support",
49+
]
50+
51+
public_configs = [
52+
"${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes",
53+
"${chip_root}/src:includes",
54+
]
55+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <devices/interface/DeviceInterface.h>
19+
20+
using namespace chip::app::Clusters;
21+
22+
namespace chip::app {
23+
24+
CHIP_ERROR DeviceInterface::DeviceTypes(ReadOnlyBufferBuilder<DataModel::DeviceTypeEntry> & out) const
25+
{
26+
VerifyOrReturnValue(mDescriptorCluster.IsConstructed(), CHIP_NO_ERROR);
27+
ReturnErrorOnFailure(out.ReferenceExisting(mDeviceTypes));
28+
29+
return CHIP_NO_ERROR;
30+
}
31+
32+
CHIP_ERROR DeviceInterface::ClientClusters(ReadOnlyBufferBuilder<ClusterId> & out) const
33+
{
34+
// no bindings
35+
return CHIP_NO_ERROR;
36+
}
37+
38+
} // namespace chip::app

0 commit comments

Comments
 (0)