From 2fef989ca238b6ccbf48678a0d9e371f90ce7e6d Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Thu, 23 Oct 2025 14:23:11 -0400 Subject: [PATCH 01/48] Initial draft of all devices example app --- examples/BUILD.gn | 5 +- .../devices/base-device/BUILD.gn | 27 ++ .../devices/base-device/Device.cpp | 68 +++++ .../devices/base-device/Device.h | 70 +++++ .../devices/contact-sensor/BUILD.gn | 29 ++ .../contact-sensor/ContactSensorDevice.cpp | 51 ++++ .../contact-sensor/ContactSensorDevice.h | 49 +++ .../devices/device-factory/BUILD.gn | 24 ++ .../devices/device-factory/DeviceFactory.h | 57 ++++ .../devices/root-node/BUILD.gn | 37 +++ .../devices/root-node/RootNodeDevice.cpp | 154 ++++++++++ .../devices/root-node/RootNodeDevice.h | 78 +++++ .../devices/water-leak-detector/BUILD.gn | 29 ++ .../WaterLeakDetectorDevice.cpp | 51 ++++ .../WaterLeakDetectorDevice.h | 49 +++ examples/all-devices-app/linux/.gn | 25 ++ examples/all-devices-app/linux/BUILD.gn | 76 +++++ examples/all-devices-app/linux/args.gni | 28 ++ .../all-devices-app/linux/build_overrides | 1 + .../linux/include/CHIPProjectAppConfig.h | 39 +++ examples/all-devices-app/linux/main.cpp | 283 ++++++++++++++++++ .../linux/third_party/connectedhomeip | 1 + examples/platform/linux/BUILD.gn | 17 +- scripts/build/build/targets.py | 1 + scripts/build/builders/host.py | 6 + 25 files changed, 1252 insertions(+), 3 deletions(-) create mode 100644 examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn create mode 100644 examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp create mode 100644 examples/all-devices-app/all-devices-common/devices/base-device/Device.h create mode 100644 examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn create mode 100644 examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp create mode 100644 examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h create mode 100644 examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn create mode 100644 examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h create mode 100644 examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn create mode 100644 examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp create mode 100644 examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h create mode 100644 examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn create mode 100644 examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp create mode 100644 examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h create mode 100644 examples/all-devices-app/linux/.gn create mode 100644 examples/all-devices-app/linux/BUILD.gn create mode 100644 examples/all-devices-app/linux/args.gni create mode 120000 examples/all-devices-app/linux/build_overrides create mode 100644 examples/all-devices-app/linux/include/CHIPProjectAppConfig.h create mode 100644 examples/all-devices-app/linux/main.cpp create mode 120000 examples/all-devices-app/linux/third_party/connectedhomeip diff --git a/examples/BUILD.gn b/examples/BUILD.gn index a8cb18422949e2..131304d4eaa135 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -26,7 +26,10 @@ if (chip_build_tests) { deps = [] tests = [] if (chip_device_platform == "linux" && current_os == "linux") { - tests += [ "${chip_root}/examples/energy-management-app/energy-management-common/tests" ] + tests += [ + "${chip_root}/examples/all-devices-app/tests", + "${chip_root}/examples/energy-management-app/energy-management-common/tests", + ] } } } diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn new file mode 100644 index 00000000000000..098942016fdb21 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn @@ -0,0 +1,27 @@ +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("includes") { + # allows includes like "devices/..." + include_dirs = [ "../.." ] +} + +source_set("base-device") { + sources = [ + "Device.cpp", + "Device.h", + ] + + public_deps = [ + "${chip_root}/src/app/clusters/descriptor", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", + "${chip_root}/zzz_generated/app-common/clusters/Descriptor", + ] + + public_configs = [ + ":includes", + "${chip_root}/src:includes", + ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp new file mode 100644 index 00000000000000..862cb5c8a4fc9e --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -0,0 +1,68 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Device.h" +#include + +using namespace chip::app::Clusters; + +namespace chip::app { + +CHIP_ERROR Device::BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +{ + VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); + mEndpointId = endpoint; + + mDescriptorCluster.Create(endpoint, DescriptorCluster::OptionalAttributesSet(0), Span()); + ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); + + mEndpointRegistration.endpointEntry = DataModel::EndpointEntry{ + .id = endpoint, // + .parentId = parentId, // + .compositionPattern = DataModel::EndpointCompositionPattern::kFullFamily, + }; + return CHIP_NO_ERROR; +} + +CHIP_ERROR Device::DeviceTypes(ReadOnlyBufferBuilder & out) const +{ + ReturnErrorOnFailure(out.EnsureAppendCapacity(1)); + + if (mDescriptorCluster.IsConstructed()) + { + ReturnErrorOnFailure(out.Append(DataModel::DeviceTypeEntry{ + .deviceTypeId = mDeviceType.deviceType, + .deviceTypeRevision = static_cast(mDeviceType.revision), + })); + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR Device::SemanticTags(ReadOnlyBufferBuilder & out) const +{ + // no semantic tags + return CHIP_NO_ERROR; +} + +CHIP_ERROR Device::ClientClusters(ReadOnlyBufferBuilder & out) const +{ + // no bindings + return CHIP_NO_ERROR; +} + +} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h new file mode 100644 index 00000000000000..4c493419c607d8 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -0,0 +1,70 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace chip::app { + +/// A device is a entity that maintains some cluster functionality. +/// +/// Current implementation assumes that a device is registered on a single +/// endpoint. +class Device : public EndpointInterface +{ +public: + using DeviceType = Clusters::Descriptor::Structs::DeviceTypeStruct::Type; + Device(const DeviceType & deviceType) : mDeviceType(deviceType), mEndpointRegistration(*this, {}) {} + virtual ~Device() = default; + + EndpointId GetEndpointId() const { return mEndpointId; } + + /// Register relevant clusters on the given endpoint + virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId = kInvalidEndpointId) = 0; + + /// Remove clusters from the given provider. + /// + /// Will only be called if register has succeeded before + virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; + + // Endpoint interface implementation + CHIP_ERROR SemanticTags(ReadOnlyBufferBuilder & out) const override; + CHIP_ERROR DeviceTypes(ReadOnlyBufferBuilder & out) const override; + CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; + +protected: + /// Internal registration function for common device clusters and endpoint registration. + /// Subclasses are expected to call this + CHIP_ERROR BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); + + EndpointId mEndpointId = kInvalidEndpointId; + const DeviceType mDeviceType; + EndpointInterfaceRegistration mEndpointRegistration; + + // Common clusters.. + LazyRegisteredServerCluster mDescriptorCluster; +}; + +} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn new file mode 100644 index 00000000000000..fbf613161f292e --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn @@ -0,0 +1,29 @@ +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("includes") { + # allows includes like "devices/..." + include_dirs = [ ".." ] +} + +source_set("contact-sensor") { + sources = [ + "ContactSensorDevice.cpp", + "ContactSensorDevice.h", + ] + + public_deps = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/src/app/clusters/boolean-state-server", + "${chip_root}/src/app/clusters/identify-server", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", + "${chip_root}/zzz_generated/app-common/clusters/Descriptor", + ] + + public_configs = [ + ":includes", + "${chip_root}/src:includes", + ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp new file mode 100644 index 00000000000000..0217ad3f7c7bd4 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +using namespace chip::app::Clusters; + +namespace chip::app { + +CHIP_ERROR ContactSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +{ + ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); + + mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, mTimerDelegate)); + ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration())); + + mBooleanStateCluster.Create(endpoint); + ReturnErrorOnFailure(provider.AddCluster(mBooleanStateCluster.Registration())); + + return provider.AddEndpoint(mEndpointRegistration); +} + +void ContactSensorDevice::UnRegister(CodeDrivenDataModelProvider & provider) +{ + provider.RemoveEndpoint(mEndpointId); + if (mBooleanStateCluster.IsConstructed()) + { + provider.RemoveCluster(&mBooleanStateCluster.Cluster()); + mBooleanStateCluster.Destroy(); + } + if (mIdentifyCluster.IsConstructed()) + { + provider.RemoveCluster(&mIdentifyCluster.Cluster()); + mIdentifyCluster.Destroy(); + } +} + +} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h new file mode 100644 index 00000000000000..ecf22c008d30c0 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include +#include +#include + +namespace chip { +namespace app { + +constexpr DeviceTypeId kContactSensorDeviceTypeRevision = 2; + +class ContactSensorDevice : public Device +{ +public: + ContactSensorDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0015), + .revision = kContactSensorDeviceTypeRevision }) {} + ~ContactSensorDevice() override = default; + + CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId = kInvalidEndpointId) override; + void UnRegister(CodeDrivenDataModelProvider & provider) override; + + Clusters::BooleanStateCluster & Cluster() { return mBooleanStateCluster.Cluster(); } + +private: + DefaultTimerDelegate mTimerDelegate; + LazyRegisteredServerCluster mIdentifyCluster; + LazyRegisteredServerCluster mBooleanStateCluster; +}; + +} // namespace app +} // namespace chip diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn new file mode 100644 index 00000000000000..fbe1ed8466584e --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn @@ -0,0 +1,24 @@ +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("includes") { + # allows includes like "devices/..." + include_dirs = [ "../.." ] +} + +source_set("device-factory"){ + sources = [ + "DeviceFactory.h", + ] + + public_deps = [ + "${chip_root}/src/lib/core:error", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/contact-sensor", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/water-leak-detector", + ] + + public_configs = [ + ":includes", + "${chip_root}/src:includes", + ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h new file mode 100644 index 00000000000000..5a0656aae2a7cd --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -0,0 +1,57 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace chip::app { + +class DeviceFactory { +public: + using DeviceCreator = std::function()>; + + static DeviceFactory & GetInstance() { + static DeviceFactory instance; + return instance; + } + + bool IsValidDevice(const std::string& deviceTypeArg){ + return mRegistry.find(deviceTypeArg) != mRegistry.end(); + } + + std::unique_ptr Create(const std::string& deviceTypeArg) { + if (IsValidDevice(deviceTypeArg)) { + return mRegistry.find(deviceTypeArg)->second(); + } + return nullptr; + } + +private: + std::map mRegistry; + + DeviceFactory() { + mRegistry["contact-sensor"] = []() { return std::make_unique(); }; + mRegistry["water-leak-detector"] = []() { return std::make_unique(); }; + } +}; + +} \ No newline at end of file diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn new file mode 100644 index 00000000000000..097d1a2182c4b4 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn @@ -0,0 +1,37 @@ +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("includes") { + # allows includes like "devices/..." + include_dirs = [ ".." ] +} + +source_set("root-node") { + sources = [ + "RootNodeDevice.cpp", + "RootNodeDevice.h", + ] + + public_deps = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/src/app/clusters/access-control-server", + "${chip_root}/src/app/clusters/administrator-commissioning-server", + "${chip_root}/src/app/clusters/basic-information", + "${chip_root}/src/app/clusters/general-commissioning-server", + "${chip_root}/src/app/clusters/general-diagnostics-server", + "${chip_root}/src/app/clusters/group-key-mgmt-server", + "${chip_root}/src/app/clusters/network-commissioning", + "${chip_root}/src/app/clusters/operational-credentials-server", + "${chip_root}/src/app/clusters/software-diagnostics-server", + "${chip_root}/src/app/clusters/wifi-network-diagnostics-server", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", + "${chip_root}/zzz_generated/app-common/clusters/Descriptor", + ] + + public_configs = [ + ":includes", + "${chip_root}/src:includes", + ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp new file mode 100644 index 00000000000000..72f58f1cef4658 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -0,0 +1,154 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::DeviceLayer; + +namespace chip { +namespace app { + +CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelProvider & provider, EndpointId parentId) +{ + ReturnErrorOnFailure(BaseRegistration(endpointId, provider, parentId)); + + mBasicInformationCluster.Create(); + mBasicInformationCluster.Cluster() + .OptionalAttributes() + .Set() + .Set() + .Set() + .Set() + .Set() + .Set() + .Set() + .Set(); + + ReturnErrorOnFailure(provider.AddCluster(mBasicInformationCluster.Registration())); + + mGeneralCommissioningCluster.Create(); + ReturnErrorOnFailure(provider.AddCluster(mGeneralCommissioningCluster.Registration())); + + mAdministratorCommissioningCluster.Create(endpointId, BitFlags{}); + ReturnErrorOnFailure(provider.AddCluster(mAdministratorCommissioningCluster.Registration())); + + mGeneralDiagnosticsCluster.Create(GeneralDiagnosticsCluster::OptionalAttributeSet{}); + ReturnErrorOnFailure(provider.AddCluster(mGeneralDiagnosticsCluster.Registration())); + + mGroupKeyManagementCluster.Create(); + ReturnErrorOnFailure(provider.AddCluster(mGroupKeyManagementCluster.Registration())); + + mSoftwareDiagnosticsServerCluster.Create(SoftwareDiagnosticsLogic::OptionalAttributeSet{}); + ReturnErrorOnFailure(provider.AddCluster(mSoftwareDiagnosticsServerCluster.Registration())); + + mAccessControlCluster.Create(); + ReturnErrorOnFailure(provider.AddCluster(mAccessControlCluster.Registration())); + + mOperationalCredentialsCluster.Create(endpointId, OperationalCredentialsCluster::Context{ .fabricTable = Server::GetInstance().GetFabricTable(), + .failSafeContext = Server::GetInstance().GetFailSafeContext(), + .sessionManager = Server::GetInstance().GetSecureSessionManager(), + .dnssdServer = app::DnssdServer::Instance(), + .commissioningWindowManager = Server::GetInstance().GetCommissioningWindowManager() }); + ReturnErrorOnFailure(provider.AddCluster(mOperationalCredentialsCluster.Registration())); + + return provider.AddEndpoint(mEndpointRegistration); +} + +void RootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) +{ + provider.RemoveEndpoint(mEndpointId); + if (mBasicInformationCluster.IsConstructed()) + { + provider.RemoveCluster(&mBasicInformationCluster.Cluster()); + mBasicInformationCluster.Destroy(); + } + if (mGeneralCommissioningCluster.IsConstructed()) + { + provider.RemoveCluster(&mGeneralCommissioningCluster.Cluster()); + mGeneralCommissioningCluster.Destroy(); + } + if (mAdministratorCommissioningCluster.IsConstructed()) + { + provider.RemoveCluster(&mAdministratorCommissioningCluster.Cluster()); + mAdministratorCommissioningCluster.Destroy(); + } + if (mGeneralDiagnosticsCluster.IsConstructed()) + { + provider.RemoveCluster(&mGeneralDiagnosticsCluster.Cluster()); + mGeneralDiagnosticsCluster.Destroy(); + } + if (mGroupKeyManagementCluster.IsConstructed()) + { + provider.RemoveCluster(&mGroupKeyManagementCluster.Cluster()); + mGroupKeyManagementCluster.Destroy(); + } + if (mSoftwareDiagnosticsServerCluster.IsConstructed()) + { + provider.RemoveCluster(&mSoftwareDiagnosticsServerCluster.Cluster()); + mSoftwareDiagnosticsServerCluster.Destroy(); + } + if (mAccessControlCluster.IsConstructed()) + { + provider.RemoveCluster(&mAccessControlCluster.Cluster()); + mAccessControlCluster.Destroy(); + } + if (mOperationalCredentialsCluster.IsConstructed()) + { + provider.RemoveCluster(&mOperationalCredentialsCluster.Cluster()); + mOperationalCredentialsCluster.Destroy(); + } +} + +CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelProvider & provider, EndpointId parentId) +{ + ReturnErrorOnFailure(RootNodeDevice::Register(endpointId, provider, parentId)); + + mWifiDiagnosticsCluster.Create(endpointId, DeviceLayer::GetDiagnosticDataProvider(), + WiFiDiagnosticsServerLogic::OptionalAttributeSet{}, + BitFlags{}); + ReturnErrorOnFailure(provider.AddCluster(mWifiDiagnosticsCluster.Registration())); + + mNetworkCommissioningCluster.Create(endpointId, mWifiDriver); + ReturnErrorOnFailure(provider.AddCluster(mNetworkCommissioningCluster.Registration())); + + return CHIP_NO_ERROR; +} + +void WifiRootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) { + RootNodeDevice::UnRegister(provider); + if (mNetworkCommissioningCluster.IsConstructed()) + { + provider.RemoveCluster(&mNetworkCommissioningCluster.Cluster()); + mNetworkCommissioningCluster.Destroy(); + } + if (mWifiDiagnosticsCluster.IsConstructed()) + { + provider.RemoveCluster(&mWifiDiagnosticsCluster.Cluster()); + mWifiDiagnosticsCluster.Destroy(); + } +} + +} // namespace app +} // namespace chip \ No newline at end of file diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h new file mode 100644 index 00000000000000..0a091cc4058b12 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -0,0 +1,78 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace chip { +namespace app { + +class RootNodeDevice : public Device +{ +public: + ~RootNodeDevice() override = default; + + CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId = kInvalidEndpointId) override; + void UnRegister(CodeDrivenDataModelProvider & provider) override; + +protected: + // Most implementations require network commissioning, so only subclasses have access to this. + RootNodeDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0016), .revision = 3 }) {} + +private: + LazyRegisteredServerCluster mBasicInformationCluster; + LazyRegisteredServerCluster mGeneralCommissioningCluster; + LazyRegisteredServerCluster + mAdministratorCommissioningCluster; + LazyRegisteredServerCluster mGeneralDiagnosticsCluster; + LazyRegisteredServerCluster mGroupKeyManagementCluster; + LazyRegisteredServerCluster mSoftwareDiagnosticsServerCluster; + LazyRegisteredServerCluster mAccessControlCluster; + LazyRegisteredServerCluster mOperationalCredentialsCluster; +}; + +class WifiRootNodeDevice : public RootNodeDevice { +public: + WifiRootNodeDevice(DeviceLayer::NetworkCommissioning::WiFiDriver *wifiDriver) : RootNodeDevice(), mWifiDriver(wifiDriver) + {} + + ~WifiRootNodeDevice() override = default; + + CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId = kInvalidEndpointId) override; + void UnRegister(CodeDrivenDataModelProvider & provider) override; +private: + LazyRegisteredServerCluster mNetworkCommissioningCluster; + LazyRegisteredServerCluster mWifiDiagnosticsCluster; + DeviceLayer::NetworkCommissioning::WiFiDriver *mWifiDriver; +}; + +} // namespace app +} // namespace chip \ No newline at end of file diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn new file mode 100644 index 00000000000000..41fffa92f8221b --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn @@ -0,0 +1,29 @@ +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("includes") { + # allows includes like "devices/..." + include_dirs = [ ".." ] +} + +source_set("water-leak-detector") { + sources = [ + "WaterLeakDetectorDevice.cpp", + "WaterLeakDetectorDevice.h", + ] + + public_deps = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/src/app/clusters/boolean-state-server", + "${chip_root}/src/app/clusters/identify-server", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", + "${chip_root}/zzz_generated/app-common/clusters/Descriptor", + ] + + public_configs = [ + ":includes", + "${chip_root}/src:includes", + ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp new file mode 100644 index 00000000000000..f4eedce0ba5d2c --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +using namespace chip::app::Clusters; + +namespace chip::app { + +CHIP_ERROR WaterLeakDetectorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +{ + ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); + + mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, mTimerDelegate)); + ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration())); + + mBooleanStateCluster.Create(endpoint); + ReturnErrorOnFailure(provider.AddCluster(mBooleanStateCluster.Registration())); + + return provider.AddEndpoint(mEndpointRegistration); +} + +void WaterLeakDetectorDevice::UnRegister(CodeDrivenDataModelProvider & provider) +{ + provider.RemoveEndpoint(mEndpointId); + if (mBooleanStateCluster.IsConstructed()) + { + provider.RemoveCluster(&mBooleanStateCluster.Cluster()); + mBooleanStateCluster.Destroy(); + } + if (mIdentifyCluster.IsConstructed()) + { + provider.RemoveCluster(&mIdentifyCluster.Cluster()); + mIdentifyCluster.Destroy(); + } +} + +} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h new file mode 100644 index 00000000000000..9dfaa2099ac076 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include +#include +#include + +namespace chip { +namespace app { + +constexpr DeviceTypeId kWaterLeakDetectorDeviceTypeRevision = 1; + +class WaterLeakDetectorDevice : public Device +{ +public: + WaterLeakDetectorDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0043), + .revision = kWaterLeakDetectorDeviceTypeRevision }) {} + ~WaterLeakDetectorDevice() override = default; + + CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId = kInvalidEndpointId) override; + void UnRegister(CodeDrivenDataModelProvider & provider) override; + + Clusters::BooleanStateCluster & Cluster() { return mBooleanStateCluster.Cluster(); } + +private: + DefaultTimerDelegate mTimerDelegate; + LazyRegisteredServerCluster mIdentifyCluster; + LazyRegisteredServerCluster mBooleanStateCluster; +}; + +} // namespace app +} // namespace chip diff --git a/examples/all-devices-app/linux/.gn b/examples/all-devices-app/linux/.gn new file mode 100644 index 00000000000000..5d1ce757507582 --- /dev/null +++ b/examples/all-devices-app/linux/.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + import("//args.gni") +} diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn new file mode 100644 index 00000000000000..2a2b330286726f --- /dev/null +++ b/examples/all-devices-app/linux/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") + +import("${chip_root}/build/chip/tools.gni") +import("${chip_root}/examples/common/pigweed/rpc_config.gni") +import("${chip_root}/src/app/common_flags.gni") + +import("$dir_pw_build/target_types.gni") + +config("includes") { + include_dirs = [ + ".", + "include", + ] +} + +executable("all-devices-app") { + sources = [ + "include/CHIPProjectAppConfig.h", + "main.cpp", + ] + + deps = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/contact-sensor", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/device-factory", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/root-node", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/water-leak-detector", + "${chip_root}/examples/common/tracing:commandline", + "${chip_root}/examples/platform/linux:app-main", + "${chip_root}/examples/platform/linux:linux-commissionable-data-provider", + "${chip_root}/examples/providers:device_info_provider_please_do_not_reuse_as_is", + "${chip_root}/src/app/clusters/administrator-commissioning-server", + "${chip_root}/src/app/clusters/basic-information", + "${chip_root}/src/app/clusters/general-commissioning-server", + "${chip_root}/src/app/clusters/general-diagnostics-server", + "${chip_root}/src/app/clusters/group-key-mgmt-server", + "${chip_root}/src/app/clusters/network-commissioning", + "${chip_root}/src/app/clusters/software-diagnostics-server", + "${chip_root}/src/app/clusters/wifi-network-diagnostics-server", + "${chip_root}/src/app/persistence", + "${chip_root}/src/app/persistence:default", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib", + ] + deps += pw_build_LINK_DEPS + + include_dirs = [ + "include", + "${chip_root}/examples/common", + ] + + output_dir = root_out_dir +} + +group("linux") { + deps = [ ":all-devices-app" ] +} + +group("default") { + deps = [ ":linux" ] +} diff --git a/examples/all-devices-app/linux/args.gni b/examples/all-devices-app/linux/args.gni new file mode 100644 index 00000000000000..241e13a624a2e7 --- /dev/null +++ b/examples/all-devices-app/linux/args.gni @@ -0,0 +1,28 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# CHIPProjectConfig.h + +import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") +import("${chip_root}/config/standalone/args.gni") + +chip_device_project_config_include = "" +chip_project_config_include = "" +chip_system_project_config_include = "" + +chip_project_config_include_dirs = + [ "${chip_root}/examples/contact-sensor-app/linux/include" ] +chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] +matter_enable_tracing_support = true diff --git a/examples/all-devices-app/linux/build_overrides b/examples/all-devices-app/linux/build_overrides new file mode 120000 index 00000000000000..e578e73312ebd1 --- /dev/null +++ b/examples/all-devices-app/linux/build_overrides @@ -0,0 +1 @@ +../../build_overrides \ No newline at end of file diff --git a/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h b/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h new file mode 100644 index 00000000000000..3b9e60aa31754d --- /dev/null +++ b/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +// include the CHIPProjectConfig from config/standalone +#include + +#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0 + +// Bulbs do not typically use this - enabled so we can use shell to discover commissioners +#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT 1 + +#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 + +#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1 + +#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 0x0015 // Contact sensor + +#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1 + +#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1 + +#define CHIP_DEVICE_CONFIG_DEVICE_NAME "Contact sensor" diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp new file mode 100644 index 00000000000000..be2865067d0e98 --- /dev/null +++ b/examples/all-devices-app/linux/main.cpp @@ -0,0 +1,283 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::Platform; +using namespace chip::DeviceLayer; +using namespace chip::app::Clusters; +using namespace chip::ArgParser; + +namespace { +AppMainLoopImplementation * gMainLoopImplementation = nullptr; + +DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sWiFiDriver; + +DeviceInfoProviderImpl gExampleDeviceInfoProvider; + +// To hold SPAKE2+ verifier, discriminator, passcode +LinuxCommissionableDataProvider gCommissionableDataProvider; + +// App custom argument handling +constexpr uint16_t kOptionDeviceType = 0xffd0; +const char * deviceTypeName = "contact-sensor"; //defaulting to contact sensor if not specified + +chip::ArgParser::OptionDef sAllDevicesAppOptionDefs[] = { + { "device", chip::ArgParser::kArgumentRequired, kOptionDeviceType }, +}; + +bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int identifier, const char * name, const char * value) +{ + switch (identifier) + { + case kOptionDeviceType: + if (value == nullptr || !DeviceFactory::GetInstance().IsValidDevice(value)) + { + ChipLogError(Support, "INTERNAL ERROR: Invalid device type: %s\n", value); + return false; + } + ChipLogProgress(AppServer, "Using the device type of %s", value); + deviceTypeName = value; + return true; + default: + ChipLogError(Support, "%s: INTERNAL ERROR: Unhandled option: %s\n", program, name); + return false; + } + + return true; +} + +chip::ArgParser::OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function + sAllDevicesAppOptionDefs, // array of option definitions + "PROGRAM OPTIONS", // help group + "-d, --device \n" }; + +void StopSignalHandler(int /* signal */) +{ + if (gMainLoopImplementation != nullptr) + { + gMainLoopImplementation->SignalSafeStopMainLoop(); + } + else + { + Server::GetInstance().GenerateShutDownEvent(); + SystemLayer().ScheduleLambda([]() { PlatformMgr().StopEventLoopTask(); }); + } +} + +[[maybe_unused]] chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentStorageDelegate * delegate) +{ + static chip::app::DefaultAttributePersistenceProvider attributePersistenceProvider; + static chip::app::CodeDrivenDataModelProvider dataModelProvider = + chip::app::CodeDrivenDataModelProvider(*delegate, attributePersistenceProvider); + + static WifiRootNodeDevice rootNodeDevice(&sWiFiDriver); + static std::unique_ptr constructedDevice; + + rootNodeDevice.Register(kRootEndpointId, dataModelProvider, kInvalidEndpointId); + constructedDevice = DeviceFactory::GetInstance().Create(deviceTypeName); + constructedDevice->Register(1, dataModelProvider, kInvalidEndpointId); + + return &dataModelProvider; +} + +void RunApplication(AppMainLoopImplementation * mainLoop = nullptr) +{ + gMainLoopImplementation = mainLoop; + + static chip::CommonCaseDeviceServerInitParams initParams; + VerifyOrDie(initParams.InitializeStaticResourcesBeforeServerInit() == CHIP_NO_ERROR); + + initParams.dataModelProvider = PopulateCodeDrivenDataModelProvider(initParams.persistentStorageDelegate); + initParams.operationalServicePort = CHIP_PORT; + initParams.userDirectedCommissioningPort = CHIP_UDC_PORT; + initParams.interfaceId = Inet::InterfaceId::Null(); + + chip::CommandLineApp::TracingSetup tracing_setup; + tracing_setup.EnableTracingFor("json:log"); + + // Init ZCL Data Model and CHIP App Server + CHIP_ERROR err = Server::GetInstance().Init(initParams); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Server init failed: %" CHIP_ERROR_FORMAT, err.Format()); + chipDie(); + } + + // Now that the server has started and we are done with our startup logging, + // log our discovery/onboarding information again so it's not lost in the + // noise. + ConfigurationMgr().LogDeviceConfig(); + + chip::PayloadContents payload; + + payload.version = 0; + payload.rendezvousInformation.SetValue(RendezvousInformationFlag::kBLE); + + if (GetCommissionableDataProvider()->GetSetupPasscode(payload.setUpPINCode) != CHIP_NO_ERROR) + { + payload.setUpPINCode = CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE; + } + + uint16_t discriminator = 0; + VerifyOrDie(GetCommissionableDataProvider()->GetSetupDiscriminator(discriminator) == CHIP_NO_ERROR); + payload.discriminator.SetLongValue(discriminator); + + VerifyOrDie(chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(payload.vendorID) == CHIP_NO_ERROR); + VerifyOrDie(chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(payload.productID) == CHIP_NO_ERROR); + PrintOnboardingCodes(payload); + + SetDeviceAttestationCredentialsProvider(Credentials::Examples::GetExampleDACProvider()); + + sWiFiDriver.Set5gSupport(true); + + struct sigaction sa = {}; + sa.sa_handler = StopSignalHandler; + sa.sa_flags = SA_RESETHAND; + sigaction(SIGINT, &sa, nullptr); + sigaction(SIGTERM, &sa, nullptr); + + if (mainLoop != nullptr) + { + mainLoop->RunMainLoop(); + } + else + { + DeviceLayer::PlatformMgr().RunEventLoop(); + } + gMainLoopImplementation = nullptr; + + Server::GetInstance().Shutdown(); + DeviceLayer::PlatformMgr().Shutdown(); + tracing_setup.StopTracing(); +} + +void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg) +{ + (void) arg; + if (event->Type == DeviceLayer::DeviceEventType::kCHIPoBLEConnectionEstablished) + { + ChipLogProgress(DeviceLayer, "Receive kCHIPoBLEConnectionEstablished"); + } + else if ((event->Type == chip::DeviceLayer::DeviceEventType::kInternetConnectivityChange)) + { + // Restart the server on connectivity change + DnssdServer::Instance().StartServer(); + } +} + +CHIP_ERROR InitCommissionableDataProvider(LinuxCommissionableDataProvider & provider) +{ + auto discriminator = static_cast(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR); + chip::Optional discriminatorFromParam = LinuxDeviceOptions::GetInstance().discriminator; + if (discriminatorFromParam.HasValue()) + { + discriminator = discriminatorFromParam.Value(); + } + + const auto setupPasscode = MakeOptional(static_cast(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE)); + const uint32_t spake2pIterationCount = Crypto::kSpake2p_Min_PBKDF_Iterations; + + Optional> serializedSpake2pVerifier = NullOptional; + Optional> spake2pSalt = NullOptional; + + return provider.Init( // + serializedSpake2pVerifier, // + spake2pSalt, // + spake2pIterationCount, // + setupPasscode, // + discriminator // + ); +} + +CHIP_ERROR Initialize(int argc, char * argv[]) +{ + ChipLogProgress(AppServer, "Initializing..."); + ReturnErrorOnFailure(Platform::MemoryInit()); + ReturnErrorOnFailure(ParseArguments(argc, argv, &sCmdLineOptions)); + ReturnErrorOnFailure(DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH)); + ReturnErrorOnFailure(DeviceLayer::PlatformMgr().InitChipStack()); + + ReturnErrorOnFailure(InitCommissionableDataProvider(gCommissionableDataProvider)); + DeviceLayer::SetCommissionableDataProvider(&gCommissionableDataProvider); + DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + ConfigurationMgr().LogDeviceConfig(); + + ReturnErrorOnFailure(DeviceLayer::PlatformMgrImpl().AddEventHandler(EventHandler, 0)); + ReturnErrorOnFailure(DeviceLayer::ConnectivityMgr().SetBLEDeviceName(nullptr)); + ReturnErrorOnFailure(DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(0, false)); + ReturnErrorOnFailure(DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true)); + + return CHIP_NO_ERROR; +} + +} // namespace + +void ApplicationShutdown() {} + +int main(int argc, char * argv[]) +{ + ChipLogProgress(AppServer, "Initializing"); + + if (CHIP_ERROR err = Initialize(argc, argv); err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Initialize() failed: %" CHIP_ERROR_FORMAT, err.Format()); + chipDie(); + } + + ChipLogProgress(AppServer, "Hello from all-devices-app!"); + RunApplication(); + + return 0; +} diff --git a/examples/all-devices-app/linux/third_party/connectedhomeip b/examples/all-devices-app/linux/third_party/connectedhomeip new file mode 120000 index 00000000000000..c866b86874994d --- /dev/null +++ b/examples/all-devices-app/linux/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../.. \ No newline at end of file diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index d87f18303928d5..81007fb2138d14 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -99,6 +99,20 @@ source_set("commodity-metering-test-event-trigger") { sources = [ "${chip_root}/src/app/clusters/commodity-metering-server/CommodityMeteringTestEventTriggerHandler.h" ] } +source_set("linux-commissionable-data-provider") { + sources = [ + "LinuxCommissionableDataProvider.cpp", + "LinuxCommissionableDataProvider.h", + ] + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + "${chip_root}/src/platform", + ] + + public_configs = [ ":app-main-config" ] +} + source_set("commodity-tariff-test-event-trigger") { sources = [ "${chip_root}/src/app/clusters/commodity-tariff-server/CommodityTariffTestEventTriggerHandler.h" ] } @@ -115,8 +129,6 @@ source_set("app-main") { "AppMain.h", "CommissionableInit.cpp", "CommissionableInit.h", - "LinuxCommissionableDataProvider.cpp", - "LinuxCommissionableDataProvider.h", "NamedPipeCommands.cpp", "NamedPipeCommands.h", "Options.cpp", @@ -137,6 +149,7 @@ source_set("app-main") { ":electrical-grid-conditions-test-event-trigger", ":energy-evse-test-event-trigger", ":energy-reporting-test-event-trigger", + ":linux-commissionable-data-provider", ":meter-identification-test-event-trigger", ":smco-test-event-trigger", ":software-diagnostics-test-event-trigger", diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index d1412e5288dfdc..7a452ce29d4941 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -107,6 +107,7 @@ def BuildHostTarget(): app=HostApp.RPC_CONSOLE).OnlyIfRe(f'{native_board_name}-'), TargetPart('all-clusters', app=HostApp.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=HostApp.ALL_CLUSTERS_MINIMAL), + TargetPart('all-devices-app', app=HostApp.ALL_DEVICES_APP), TargetPart('chip-tool', app=HostApp.CHIP_TOOL), TargetPart('thermostat', app=HostApp.THERMOSTAT), # TODO: controllers depending on a datamodel is odd. For now fix compile dependencies on ember. diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 5f49cbbc529326..e3445c860ed51a 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -49,6 +49,7 @@ class HostFuzzingType(Enum): class HostApp(Enum): ALL_CLUSTERS = auto() ALL_CLUSTERS_MINIMAL = auto() + ALL_DEVICES_APP = auto() CHIP_TOOL = auto() CHIP_TOOL_DARWIN = auto() THERMOSTAT = auto() @@ -100,6 +101,8 @@ def ExamplePath(self): return 'all-clusters-app/linux' elif self == HostApp.ALL_CLUSTERS_MINIMAL: return 'all-clusters-minimal-app/linux' + elif self == HostApp.ALL_DEVICES_APP: + return 'all-devices-app/linux' elif self == HostApp.CHIP_TOOL: return 'chip-tool' elif self == HostApp.CHIP_TOOL_DARWIN: @@ -192,6 +195,9 @@ def OutputNames(self): elif self == HostApp.ALL_CLUSTERS_MINIMAL: yield 'chip-all-clusters-minimal-app' yield 'chip-all-clusters-minimal-app.map' + elif self == HostApp.ALL_DEVICES_APP: + yield 'all-devices-app' + yield 'all-devices-app.map' elif self == HostApp.CHIP_TOOL: yield 'chip-tool' yield 'chip-tool.map' From 4708c0052e418199d9bc7752d529c2d9ef9020ac Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 23 Oct 2025 19:08:36 +0000 Subject: [PATCH 02/48] Restyled by whitespace --- .../devices/device-factory/DeviceFactory.h | 4 ++-- .../devices/root-node/RootNodeDevice.cpp | 8 ++++---- .../all-devices-common/devices/root-node/RootNodeDevice.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 5a0656aae2a7cd..748091183b471d 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -44,7 +44,7 @@ class DeviceFactory { } return nullptr; } - + private: std::map mRegistry; @@ -54,4 +54,4 @@ class DeviceFactory { } }; -} \ No newline at end of file +} diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index 72f58f1cef4658..e6583639a05d6d 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -121,10 +121,10 @@ void RootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) } } -CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelProvider & provider, EndpointId parentId) +CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelProvider & provider, EndpointId parentId) { ReturnErrorOnFailure(RootNodeDevice::Register(endpointId, provider, parentId)); - + mWifiDiagnosticsCluster.Create(endpointId, DeviceLayer::GetDiagnosticDataProvider(), WiFiDiagnosticsServerLogic::OptionalAttributeSet{}, BitFlags{}); @@ -132,7 +132,7 @@ CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataMod mNetworkCommissioningCluster.Create(endpointId, mWifiDriver); ReturnErrorOnFailure(provider.AddCluster(mNetworkCommissioningCluster.Registration())); - + return CHIP_NO_ERROR; } @@ -151,4 +151,4 @@ void WifiRootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) { } } // namespace app -} // namespace chip \ No newline at end of file +} // namespace chip diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index 0a091cc4058b12..30b0f4deeb13aa 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -75,4 +75,4 @@ class WifiRootNodeDevice : public RootNodeDevice { }; } // namespace app -} // namespace chip \ No newline at end of file +} // namespace chip From 1e0aa5e794768b47141269bfca848b7fa22a56da Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 23 Oct 2025 19:08:41 +0000 Subject: [PATCH 03/48] Restyled by clang-format --- .../devices/base-device/Device.h | 4 ++-- .../contact-sensor/ContactSensorDevice.h | 7 +++--- .../devices/device-factory/DeviceFactory.h | 23 +++++++++++-------- .../devices/root-node/RootNodeDevice.cpp | 19 ++++++++------- .../devices/root-node/RootNodeDevice.h | 13 ++++++----- .../WaterLeakDetectorDevice.h | 8 ++++--- examples/all-devices-app/linux/main.cpp | 14 +++++------ 7 files changed, 49 insertions(+), 39 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 4c493419c607d8..4c2784f0e3afad 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -17,11 +17,11 @@ #pragma once -#include #include +#include +#include #include #include -#include #include diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h index ecf22c008d30c0..cf2bdd194e580d 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h @@ -16,9 +16,9 @@ */ #pragma once +#include #include #include -#include #include namespace chip { @@ -29,8 +29,9 @@ constexpr DeviceTypeId kContactSensorDeviceTypeRevision = 2; class ContactSensorDevice : public Device { public: - ContactSensorDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0015), - .revision = kContactSensorDeviceTypeRevision }) {} + ContactSensorDevice() : + Device(Device::DeviceType{ .deviceType = static_cast(0x0015), .revision = kContactSensorDeviceTypeRevision }) + {} ~ContactSensorDevice() override = default; CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 748091183b471d..065dc09a50c361 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -25,21 +25,23 @@ namespace chip::app { -class DeviceFactory { +class DeviceFactory +{ public: using DeviceCreator = std::function()>; - static DeviceFactory & GetInstance() { + static DeviceFactory & GetInstance() + { static DeviceFactory instance; return instance; } - bool IsValidDevice(const std::string& deviceTypeArg){ - return mRegistry.find(deviceTypeArg) != mRegistry.end(); - } + bool IsValidDevice(const std::string & deviceTypeArg) { return mRegistry.find(deviceTypeArg) != mRegistry.end(); } - std::unique_ptr Create(const std::string& deviceTypeArg) { - if (IsValidDevice(deviceTypeArg)) { + std::unique_ptr Create(const std::string & deviceTypeArg) + { + if (IsValidDevice(deviceTypeArg)) + { return mRegistry.find(deviceTypeArg)->second(); } return nullptr; @@ -48,10 +50,11 @@ class DeviceFactory { private: std::map mRegistry; - DeviceFactory() { - mRegistry["contact-sensor"] = []() { return std::make_unique(); }; + DeviceFactory() + { + mRegistry["contact-sensor"] = []() { return std::make_unique(); }; mRegistry["water-leak-detector"] = []() { return std::make_unique(); }; } }; -} +} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index e6583639a05d6d..43044d90a15563 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -66,11 +66,14 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr mAccessControlCluster.Create(); ReturnErrorOnFailure(provider.AddCluster(mAccessControlCluster.Registration())); - mOperationalCredentialsCluster.Create(endpointId, OperationalCredentialsCluster::Context{ .fabricTable = Server::GetInstance().GetFabricTable(), - .failSafeContext = Server::GetInstance().GetFailSafeContext(), - .sessionManager = Server::GetInstance().GetSecureSessionManager(), - .dnssdServer = app::DnssdServer::Instance(), - .commissioningWindowManager = Server::GetInstance().GetCommissioningWindowManager() }); + mOperationalCredentialsCluster.Create( + endpointId, + OperationalCredentialsCluster::Context{ .fabricTable = Server::GetInstance().GetFabricTable(), + .failSafeContext = Server::GetInstance().GetFailSafeContext(), + .sessionManager = Server::GetInstance().GetSecureSessionManager(), + .dnssdServer = app::DnssdServer::Instance(), + .commissioningWindowManager = + Server::GetInstance().GetCommissioningWindowManager() }); ReturnErrorOnFailure(provider.AddCluster(mOperationalCredentialsCluster.Registration())); return provider.AddEndpoint(mEndpointRegistration); @@ -126,8 +129,7 @@ CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataMod ReturnErrorOnFailure(RootNodeDevice::Register(endpointId, provider, parentId)); mWifiDiagnosticsCluster.Create(endpointId, DeviceLayer::GetDiagnosticDataProvider(), - WiFiDiagnosticsServerLogic::OptionalAttributeSet{}, - BitFlags{}); + WiFiDiagnosticsServerLogic::OptionalAttributeSet{}, BitFlags{}); ReturnErrorOnFailure(provider.AddCluster(mWifiDiagnosticsCluster.Registration())); mNetworkCommissioningCluster.Create(endpointId, mWifiDriver); @@ -136,7 +138,8 @@ CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataMod return CHIP_NO_ERROR; } -void WifiRootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) { +void WifiRootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) +{ RootNodeDevice::UnRegister(provider); if (mNetworkCommissioningCluster.IsConstructed()) { diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index 30b0f4deeb13aa..94583f45cd6232 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -16,14 +16,14 @@ */ #pragma once -#include -#include #include #include #include #include #include #include +#include +#include #include #include #include @@ -58,20 +58,21 @@ class RootNodeDevice : public Device LazyRegisteredServerCluster mOperationalCredentialsCluster; }; -class WifiRootNodeDevice : public RootNodeDevice { +class WifiRootNodeDevice : public RootNodeDevice +{ public: - WifiRootNodeDevice(DeviceLayer::NetworkCommissioning::WiFiDriver *wifiDriver) : RootNodeDevice(), mWifiDriver(wifiDriver) - {} + WifiRootNodeDevice(DeviceLayer::NetworkCommissioning::WiFiDriver * wifiDriver) : RootNodeDevice(), mWifiDriver(wifiDriver) {} ~WifiRootNodeDevice() override = default; CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) override; void UnRegister(CodeDrivenDataModelProvider & provider) override; + private: LazyRegisteredServerCluster mNetworkCommissioningCluster; LazyRegisteredServerCluster mWifiDiagnosticsCluster; - DeviceLayer::NetworkCommissioning::WiFiDriver *mWifiDriver; + DeviceLayer::NetworkCommissioning::WiFiDriver * mWifiDriver; }; } // namespace app diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h index 9dfaa2099ac076..ba790134b66302 100644 --- a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h @@ -16,9 +16,9 @@ */ #pragma once +#include #include #include -#include #include namespace chip { @@ -29,8 +29,10 @@ constexpr DeviceTypeId kWaterLeakDetectorDeviceTypeRevision = 1; class WaterLeakDetectorDevice : public Device { public: - WaterLeakDetectorDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0043), - .revision = kWaterLeakDetectorDeviceTypeRevision }) {} + WaterLeakDetectorDevice() : + Device( + Device::DeviceType{ .deviceType = static_cast(0x0043), .revision = kWaterLeakDetectorDeviceTypeRevision }) + {} ~WaterLeakDetectorDevice() override = default; CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index be2865067d0e98..421978abb0f0b5 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -16,6 +16,8 @@ * limitations under the License. */ +#include +#include #include #include #include @@ -34,19 +36,17 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include #include #include #include -#include -#include -#include -#include -#include -#include #include #include @@ -71,7 +71,7 @@ LinuxCommissionableDataProvider gCommissionableDataProvider; // App custom argument handling constexpr uint16_t kOptionDeviceType = 0xffd0; -const char * deviceTypeName = "contact-sensor"; //defaulting to contact sensor if not specified +const char * deviceTypeName = "contact-sensor"; // defaulting to contact sensor if not specified chip::ArgParser::OptionDef sAllDevicesAppOptionDefs[] = { { "device", chip::ArgParser::kArgumentRequired, kOptionDeviceType }, From 1f10a2763f662ee6c64ba641d17a011b3f37c110 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 23 Oct 2025 19:08:44 +0000 Subject: [PATCH 04/48] Restyled by gn --- examples/BUILD.gn | 2 +- .../all-devices-common/devices/device-factory/BUILD.gn | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/BUILD.gn b/examples/BUILD.gn index 131304d4eaa135..ce5a2805f6b724 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -26,7 +26,7 @@ if (chip_build_tests) { deps = [] tests = [] if (chip_device_platform == "linux" && current_os == "linux") { - tests += [ + tests += [ "${chip_root}/examples/all-devices-app/tests", "${chip_root}/examples/energy-management-app/energy-management-common/tests", ] diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn index fbe1ed8466584e..80af2f416f3288 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn @@ -6,17 +6,15 @@ config("includes") { include_dirs = [ "../.." ] } -source_set("device-factory"){ - sources = [ - "DeviceFactory.h", - ] +source_set("device-factory") { + sources = [ "DeviceFactory.h" ] public_deps = [ - "${chip_root}/src/lib/core:error", "${chip_root}/examples/all-devices-app/all-devices-common/devices/contact-sensor", "${chip_root}/examples/all-devices-app/all-devices-common/devices/water-leak-detector", + "${chip_root}/src/lib/core:error", ] - + public_configs = [ ":includes", "${chip_root}/src:includes", From 5d05758030391c7d9b6c2e7ad647a36417450c11 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 24 Oct 2025 09:20:55 -0400 Subject: [PATCH 05/48] Address some review comments --- examples/BUILD.gn | 1 - .../devices/base-device/BUILD.gn | 14 ++++++++++++++ .../devices/base-device/Device.cpp | 1 + .../devices/contact-sensor/BUILD.gn | 14 ++++++++++++++ .../devices/contact-sensor/ContactSensorDevice.cpp | 2 +- .../devices/contact-sensor/ContactSensorDevice.h | 9 +++++---- .../devices/device-factory/BUILD.gn | 14 ++++++++++++++ .../devices/device-factory/DeviceFactory.h | 3 ++- .../all-devices-common/devices/root-node/BUILD.gn | 14 ++++++++++++++ .../devices/root-node/RootNodeDevice.h | 1 + .../devices/water-leak-detector/BUILD.gn | 14 ++++++++++++++ .../water-leak-detector/WaterLeakDetectorDevice.h | 1 + examples/all-devices-app/linux/.gn | 2 +- examples/all-devices-app/linux/BUILD.gn | 2 +- examples/all-devices-app/linux/args.gni | 2 +- .../linux/include/CHIPProjectAppConfig.h | 2 +- examples/all-devices-app/linux/main.cpp | 4 ++-- 17 files changed, 87 insertions(+), 13 deletions(-) diff --git a/examples/BUILD.gn b/examples/BUILD.gn index ce5a2805f6b724..fd66811b711924 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -27,7 +27,6 @@ if (chip_build_tests) { tests = [] if (chip_device_platform == "linux" && current_os == "linux") { tests += [ - "${chip_root}/examples/all-devices-app/tests", "${chip_root}/examples/energy-management-app/energy-management-common/tests", ] } diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn index 098942016fdb21..c916d38b4c0b77 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn @@ -1,3 +1,17 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import("//build_overrides/build.gni") import("//build_overrides/chip.gni") diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 862cb5c8a4fc9e..47eca04cd500ff 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -40,6 +40,7 @@ CHIP_ERROR Device::BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProv CHIP_ERROR Device::DeviceTypes(ReadOnlyBufferBuilder & out) const { + VerifyOrReturnValue(mDescriptorCluster.IsConstructed(), CHIP_NO_ERROR); ReturnErrorOnFailure(out.EnsureAppendCapacity(1)); if (mDescriptorCluster.IsConstructed()) diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn index fbf613161f292e..b313a1768dfcb2 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn @@ -1,3 +1,17 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import("//build_overrides/build.gni") import("//build_overrides/chip.gni") diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp index 0217ad3f7c7bd4..c3d91a8a1559ac 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp @@ -24,7 +24,7 @@ CHIP_ERROR ContactSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDa { ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); - mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, mTimerDelegate)); + mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, *mTimerDelegate)); ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration())); mBooleanStateCluster.Create(endpoint); diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h index cf2bdd194e580d..11d229e1a23ba2 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h @@ -16,7 +16,7 @@ */ #pragma once -#include +#include #include #include #include @@ -29,8 +29,9 @@ constexpr DeviceTypeId kContactSensorDeviceTypeRevision = 2; class ContactSensorDevice : public Device { public: - ContactSensorDevice() : - Device(Device::DeviceType{ .deviceType = static_cast(0x0015), .revision = kContactSensorDeviceTypeRevision }) + ContactSensorDevice(std::unique_ptr timerDelegate) : + //TODO: Update the hard coded device type once #41602 is merged + Device(Device::DeviceType{ .deviceType = static_cast(0x0015), .revision = kContactSensorDeviceTypeRevision }), mTimerDelegate(std::move(timerDelegate)) {} ~ContactSensorDevice() override = default; @@ -41,7 +42,7 @@ class ContactSensorDevice : public Device Clusters::BooleanStateCluster & Cluster() { return mBooleanStateCluster.Cluster(); } private: - DefaultTimerDelegate mTimerDelegate; + std::unique_ptr mTimerDelegate; LazyRegisteredServerCluster mIdentifyCluster; LazyRegisteredServerCluster mBooleanStateCluster; }; diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn index 80af2f416f3288..6256103cfdb4fd 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn @@ -1,3 +1,17 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import("//build_overrides/build.gni") import("//build_overrides/chip.gni") diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 065dc09a50c361..676fcab7d06fec 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include #include @@ -52,7 +53,7 @@ class DeviceFactory DeviceFactory() { - mRegistry["contact-sensor"] = []() { return std::make_unique(); }; + mRegistry["contact-sensor"] = []() { return std::make_unique(std::make_unique()); }; mRegistry["water-leak-detector"] = []() { return std::make_unique(); }; } }; diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn index 097d1a2182c4b4..7c2a9c0ec1c285 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn @@ -1,3 +1,17 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import("//build_overrides/build.gni") import("//build_overrides/chip.gni") diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index 94583f45cd6232..7ef8c51b2121f4 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -44,6 +44,7 @@ class RootNodeDevice : public Device protected: // Most implementations require network commissioning, so only subclasses have access to this. + //TODO: Update the hard coded device type once #41602 is merged RootNodeDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0016), .revision = 3 }) {} private: diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn index 41fffa92f8221b..d21930b57165f5 100644 --- a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn @@ -1,3 +1,17 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import("//build_overrides/build.gni") import("//build_overrides/chip.gni") diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h index ba790134b66302..a08e7581f9be17 100644 --- a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h @@ -30,6 +30,7 @@ class WaterLeakDetectorDevice : public Device { public: WaterLeakDetectorDevice() : + //TODO: Update the hard coded device type once #41602 is merged Device( Device::DeviceType{ .deviceType = static_cast(0x0043), .revision = kWaterLeakDetectorDeviceTypeRevision }) {} diff --git a/examples/all-devices-app/linux/.gn b/examples/all-devices-app/linux/.gn index 5d1ce757507582..5e56861d956ef5 100644 --- a/examples/all-devices-app/linux/.gn +++ b/examples/all-devices-app/linux/.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Project CHIP Authors +# Copyright (c) 2025 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index 2a2b330286726f..2d28c678c1985e 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Project CHIP Authors +# Copyright (c) 2025 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/all-devices-app/linux/args.gni b/examples/all-devices-app/linux/args.gni index 241e13a624a2e7..2f4c8cf88d8817 100644 --- a/examples/all-devices-app/linux/args.gni +++ b/examples/all-devices-app/linux/args.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Project CHIP Authors +# Copyright (c) 2025 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h b/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h index 3b9e60aa31754d..1cca90ecc52655 100644 --- a/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h +++ b/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2025 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 421978abb0f0b5..6a23551dd3d620 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2025 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -116,7 +116,7 @@ void StopSignalHandler(int /* signal */) } } -[[maybe_unused]] chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentStorageDelegate * delegate) +chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentStorageDelegate * delegate) { static chip::app::DefaultAttributePersistenceProvider attributePersistenceProvider; static chip::app::CodeDrivenDataModelProvider dataModelProvider = From 050d6a73fab8cb23d6e0b111b85b0a111c06ba9b Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 24 Oct 2025 11:59:28 -0400 Subject: [PATCH 06/48] Address more review comments --- .../devices/base-device/BUILD.gn | 1 - .../devices/base-device/Device.cpp | 17 +++--- .../devices/base-device/Device.h | 10 ++-- .../BUILD.gn | 7 ++- .../BooleanStateSensorDevice.cpp} | 6 +-- .../BooleanStateSensorDevice.h} | 19 ++++--- .../devices/device-factory/BUILD.gn | 4 +- .../devices/device-factory/DeviceFactory.h | 20 ++++--- .../devices/root-node/BUILD.gn | 2 +- .../devices/root-node/RootNodeDevice.h | 6 +-- .../devices/water-leak-detector/BUILD.gn | 43 --------------- .../WaterLeakDetectorDevice.cpp | 51 ------------------ .../WaterLeakDetectorDevice.h | 52 ------------------- examples/all-devices-app/linux/BUILD.gn | 11 ---- examples/all-devices-app/linux/main.cpp | 18 +------ 15 files changed, 50 insertions(+), 217 deletions(-) rename examples/all-devices-app/all-devices-common/devices/{contact-sensor => boolean-state-sensor}/BUILD.gn (88%) rename examples/all-devices-app/all-devices-common/devices/{contact-sensor/ContactSensorDevice.cpp => boolean-state-sensor/BooleanStateSensorDevice.cpp} (84%) rename examples/all-devices-app/all-devices-common/devices/{contact-sensor/ContactSensorDevice.h => boolean-state-sensor/BooleanStateSensorDevice.h} (65%) delete mode 100644 examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn delete mode 100644 examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp delete mode 100644 examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn index c916d38b4c0b77..d70f4af6c8e7b8 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn @@ -31,7 +31,6 @@ source_set("base-device") { "${chip_root}/src/data-model-providers/codedriven", "${chip_root}/src/lib/core:error", "${chip_root}/src/lib/support", - "${chip_root}/zzz_generated/app-common/clusters/Descriptor", ] public_configs = [ diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 47eca04cd500ff..4509ac81025a2e 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -22,7 +22,7 @@ using namespace chip::app::Clusters; namespace chip::app { -CHIP_ERROR Device::BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) { VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); mEndpointId = endpoint; @@ -31,36 +31,33 @@ CHIP_ERROR Device::BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProv ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); mEndpointRegistration.endpointEntry = DataModel::EndpointEntry{ - .id = endpoint, // - .parentId = parentId, // + .id = endpoint, + .parentId = parentId, .compositionPattern = DataModel::EndpointCompositionPattern::kFullFamily, }; return CHIP_NO_ERROR; } -CHIP_ERROR Device::DeviceTypes(ReadOnlyBufferBuilder & out) const +CHIP_ERROR BaseDevice::DeviceTypes(ReadOnlyBufferBuilder & out) const { VerifyOrReturnValue(mDescriptorCluster.IsConstructed(), CHIP_NO_ERROR); ReturnErrorOnFailure(out.EnsureAppendCapacity(1)); if (mDescriptorCluster.IsConstructed()) { - ReturnErrorOnFailure(out.Append(DataModel::DeviceTypeEntry{ - .deviceTypeId = mDeviceType.deviceType, - .deviceTypeRevision = static_cast(mDeviceType.revision), - })); + ReturnErrorOnFailure(out.Append(mDeviceType)); } return CHIP_NO_ERROR; } -CHIP_ERROR Device::SemanticTags(ReadOnlyBufferBuilder & out) const +CHIP_ERROR BaseDevice::SemanticTags(ReadOnlyBufferBuilder & out) const { // no semantic tags return CHIP_NO_ERROR; } -CHIP_ERROR Device::ClientClusters(ReadOnlyBufferBuilder & out) const +CHIP_ERROR BaseDevice::ClientClusters(ReadOnlyBufferBuilder & out) const { // no bindings return CHIP_NO_ERROR; diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 4c2784f0e3afad..3470737a043e79 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -31,12 +31,10 @@ namespace chip::app { /// /// Current implementation assumes that a device is registered on a single /// endpoint. -class Device : public EndpointInterface +class BaseDevice : public EndpointInterface { public: - using DeviceType = Clusters::Descriptor::Structs::DeviceTypeStruct::Type; - Device(const DeviceType & deviceType) : mDeviceType(deviceType), mEndpointRegistration(*this, {}) {} - virtual ~Device() = default; + virtual ~BaseDevice() = default; EndpointId GetEndpointId() const { return mEndpointId; } @@ -55,12 +53,14 @@ class Device : public EndpointInterface CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; protected: + BaseDevice(const DataModel::DeviceTypeEntry & deviceType) : mDeviceType(deviceType), mEndpointRegistration(*this, {}) {} + /// Internal registration function for common device clusters and endpoint registration. /// Subclasses are expected to call this CHIP_ERROR BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); EndpointId mEndpointId = kInvalidEndpointId; - const DeviceType mDeviceType; + const DataModel::DeviceTypeEntry mDeviceType; EndpointInterfaceRegistration mEndpointRegistration; // Common clusters.. diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn similarity index 88% rename from examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn rename to examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn index b313a1768dfcb2..266ce6f6f1ba51 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn @@ -20,10 +20,10 @@ config("includes") { include_dirs = [ ".." ] } -source_set("contact-sensor") { +source_set("boolean-state-sensor") { sources = [ - "ContactSensorDevice.cpp", - "ContactSensorDevice.h", + "BooleanStateSensorDevice.cpp", + "BooleanStateSensorDevice.h", ] public_deps = [ @@ -33,7 +33,6 @@ source_set("contact-sensor") { "${chip_root}/src/data-model-providers/codedriven", "${chip_root}/src/lib/core:error", "${chip_root}/src/lib/support", - "${chip_root}/zzz_generated/app-common/clusters/Descriptor", ] public_configs = [ diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp similarity index 84% rename from examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp rename to examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp index c3d91a8a1559ac..0f7f508a3b7005 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include using namespace chip::app::Clusters; namespace chip::app { -CHIP_ERROR ContactSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) { ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); @@ -33,7 +33,7 @@ CHIP_ERROR ContactSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDa return provider.AddEndpoint(mEndpointRegistration); } -void ContactSensorDevice::UnRegister(CodeDrivenDataModelProvider & provider) +void BooleanStateSensorDevice::UnRegister(CodeDrivenDataModelProvider & provider) { provider.RemoveEndpoint(mEndpointId); if (mBooleanStateCluster.IsConstructed()) diff --git a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h similarity index 65% rename from examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h rename to examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index 11d229e1a23ba2..6daa229e851d65 100644 --- a/examples/all-devices-app/all-devices-common/devices/contact-sensor/ContactSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -24,22 +24,25 @@ namespace chip { namespace app { -constexpr DeviceTypeId kContactSensorDeviceTypeRevision = 2; - -class ContactSensorDevice : public Device +class BooleanStateSensorDevice : public BaseDevice { public: - ContactSensorDevice(std::unique_ptr timerDelegate) : - //TODO: Update the hard coded device type once #41602 is merged - Device(Device::DeviceType{ .deviceType = static_cast(0x0015), .revision = kContactSensorDeviceTypeRevision }), mTimerDelegate(std::move(timerDelegate)) + /* + * This is a general class for boolean state sensor devices. The device type passed here will + * determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable + * class for the sensor types that share the same core functionality through the identify and + * boolean state clusters. + */ + BooleanStateSensorDevice(std::unique_ptr timerDelegate, const DataModel::DeviceTypeEntry & deviceType) : + BaseDevice(deviceType), mTimerDelegate(std::move(timerDelegate)) {} - ~ContactSensorDevice() override = default; + ~BooleanStateSensorDevice() override = default; CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) override; void UnRegister(CodeDrivenDataModelProvider & provider) override; - Clusters::BooleanStateCluster & Cluster() { return mBooleanStateCluster.Cluster(); } + Clusters::BooleanStateCluster & BooleanState() { return mBooleanStateCluster.Cluster(); } private: std::unique_ptr mTimerDelegate; diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn index 6256103cfdb4fd..412b1663671b99 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn @@ -24,9 +24,9 @@ source_set("device-factory") { sources = [ "DeviceFactory.h" ] public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/contact-sensor", - "${chip_root}/examples/all-devices-app/all-devices-common/devices/water-leak-detector", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor", "${chip_root}/src/lib/core:error", + "${chip_root}/zzz_generated/app-common/devices/", ] public_configs = [ diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 676fcab7d06fec..d6692683d81c18 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -18,18 +18,26 @@ #pragma once #include -#include -#include +#include #include #include #include +#include namespace chip::app { +/** + * This is a factory class made to be used to create any valid device type as part of the + * all-devices-app. This class is meant to abstract away some details of device specific code, + * and to have more generic implementation code being used in main to create a device. The keys + * in the device registry map are the command line arguments used to start the respective device. + * Create devices by fetching the instance of this class and passing in the device type argument + * i.e. DeviceFactory::GetInstance().Create(deviceTypeName) + */ class DeviceFactory { public: - using DeviceCreator = std::function()>; + using DeviceCreator = std::function()>; static DeviceFactory & GetInstance() { @@ -39,7 +47,7 @@ class DeviceFactory bool IsValidDevice(const std::string & deviceTypeArg) { return mRegistry.find(deviceTypeArg) != mRegistry.end(); } - std::unique_ptr Create(const std::string & deviceTypeArg) + std::unique_ptr Create(const std::string & deviceTypeArg) { if (IsValidDevice(deviceTypeArg)) { @@ -53,8 +61,8 @@ class DeviceFactory DeviceFactory() { - mRegistry["contact-sensor"] = []() { return std::make_unique(std::make_unique()); }; - mRegistry["water-leak-detector"] = []() { return std::make_unique(); }; + mRegistry["contact-sensor"] = []() { return std::make_unique(std::make_unique(), Device::Type::kContactSensor); }; + mRegistry["water-leak-detector"] = []() { return std::make_unique(std::make_unique(), Device::Type::kWaterLeakDetector); }; } }; diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn index 7c2a9c0ec1c285..7088d01279afc2 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn @@ -41,7 +41,7 @@ source_set("root-node") { "${chip_root}/src/data-model-providers/codedriven", "${chip_root}/src/lib/core:error", "${chip_root}/src/lib/support", - "${chip_root}/zzz_generated/app-common/clusters/Descriptor", + "${chip_root}/zzz_generated/app-common/devices/", ] public_configs = [ diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index 7ef8c51b2121f4..cc9e1b62b7b33f 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -29,11 +29,12 @@ #include #include #include +#include namespace chip { namespace app { -class RootNodeDevice : public Device +class RootNodeDevice : public BaseDevice { public: ~RootNodeDevice() override = default; @@ -44,8 +45,7 @@ class RootNodeDevice : public Device protected: // Most implementations require network commissioning, so only subclasses have access to this. - //TODO: Update the hard coded device type once #41602 is merged - RootNodeDevice() : Device(Device::DeviceType{ .deviceType = static_cast(0x0016), .revision = 3 }) {} + RootNodeDevice() : BaseDevice(Device::Type::kRootNode) {} private: LazyRegisteredServerCluster mBasicInformationCluster; diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn deleted file mode 100644 index d21930b57165f5..00000000000000 --- a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/BUILD.gn +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2025 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") - -config("includes") { - # allows includes like "devices/..." - include_dirs = [ ".." ] -} - -source_set("water-leak-detector") { - sources = [ - "WaterLeakDetectorDevice.cpp", - "WaterLeakDetectorDevice.h", - ] - - public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", - "${chip_root}/src/app/clusters/boolean-state-server", - "${chip_root}/src/app/clusters/identify-server", - "${chip_root}/src/data-model-providers/codedriven", - "${chip_root}/src/lib/core:error", - "${chip_root}/src/lib/support", - "${chip_root}/zzz_generated/app-common/clusters/Descriptor", - ] - - public_configs = [ - ":includes", - "${chip_root}/src:includes", - ] -} diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp deleted file mode 100644 index f4eedce0ba5d2c..00000000000000 --- a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright (c) 2025 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -using namespace chip::app::Clusters; - -namespace chip::app { - -CHIP_ERROR WaterLeakDetectorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) -{ - ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); - - mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, mTimerDelegate)); - ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration())); - - mBooleanStateCluster.Create(endpoint); - ReturnErrorOnFailure(provider.AddCluster(mBooleanStateCluster.Registration())); - - return provider.AddEndpoint(mEndpointRegistration); -} - -void WaterLeakDetectorDevice::UnRegister(CodeDrivenDataModelProvider & provider) -{ - provider.RemoveEndpoint(mEndpointId); - if (mBooleanStateCluster.IsConstructed()) - { - provider.RemoveCluster(&mBooleanStateCluster.Cluster()); - mBooleanStateCluster.Destroy(); - } - if (mIdentifyCluster.IsConstructed()) - { - provider.RemoveCluster(&mIdentifyCluster.Cluster()); - mIdentifyCluster.Destroy(); - } -} - -} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h b/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h deleted file mode 100644 index a08e7581f9be17..00000000000000 --- a/examples/all-devices-app/all-devices-common/devices/water-leak-detector/WaterLeakDetectorDevice.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright (c) 2025 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include -#include -#include - -namespace chip { -namespace app { - -constexpr DeviceTypeId kWaterLeakDetectorDeviceTypeRevision = 1; - -class WaterLeakDetectorDevice : public Device -{ -public: - WaterLeakDetectorDevice() : - //TODO: Update the hard coded device type once #41602 is merged - Device( - Device::DeviceType{ .deviceType = static_cast(0x0043), .revision = kWaterLeakDetectorDeviceTypeRevision }) - {} - ~WaterLeakDetectorDevice() override = default; - - CHIP_ERROR Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, - EndpointId parentId = kInvalidEndpointId) override; - void UnRegister(CodeDrivenDataModelProvider & provider) override; - - Clusters::BooleanStateCluster & Cluster() { return mBooleanStateCluster.Cluster(); } - -private: - DefaultTimerDelegate mTimerDelegate; - LazyRegisteredServerCluster mIdentifyCluster; - LazyRegisteredServerCluster mBooleanStateCluster; -}; - -} // namespace app -} // namespace chip diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index 2d28c678c1985e..c5619a41781847 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -35,23 +35,12 @@ executable("all-devices-app") { ] deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", - "${chip_root}/examples/all-devices-app/all-devices-common/devices/contact-sensor", "${chip_root}/examples/all-devices-app/all-devices-common/devices/device-factory", "${chip_root}/examples/all-devices-app/all-devices-common/devices/root-node", - "${chip_root}/examples/all-devices-app/all-devices-common/devices/water-leak-detector", "${chip_root}/examples/common/tracing:commandline", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/examples/platform/linux:linux-commissionable-data-provider", "${chip_root}/examples/providers:device_info_provider_please_do_not_reuse_as_is", - "${chip_root}/src/app/clusters/administrator-commissioning-server", - "${chip_root}/src/app/clusters/basic-information", - "${chip_root}/src/app/clusters/general-commissioning-server", - "${chip_root}/src/app/clusters/general-diagnostics-server", - "${chip_root}/src/app/clusters/group-key-mgmt-server", - "${chip_root}/src/app/clusters/network-commissioning", - "${chip_root}/src/app/clusters/software-diagnostics-server", - "${chip_root}/src/app/clusters/wifi-network-diagnostics-server", "${chip_root}/src/app/persistence", "${chip_root}/src/app/persistence:default", "${chip_root}/src/data-model-providers/codedriven", diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 6a23551dd3d620..cc6dc3142bac79 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -19,19 +19,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -39,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -47,9 +33,7 @@ #include #include #include - #include -#include #include using namespace chip; @@ -123,7 +107,7 @@ chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentS chip::app::CodeDrivenDataModelProvider(*delegate, attributePersistenceProvider); static WifiRootNodeDevice rootNodeDevice(&sWiFiDriver); - static std::unique_ptr constructedDevice; + static std::unique_ptr constructedDevice; rootNodeDevice.Register(kRootEndpointId, dataModelProvider, kInvalidEndpointId); constructedDevice = DeviceFactory::GetInstance().Create(deviceTypeName); From 675bc02734eb43d93cfdb6a7be7856e8735a39df Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Oct 2025 16:03:59 +0000 Subject: [PATCH 07/48] Restyled by whitespace --- .../all-devices-common/devices/base-device/Device.cpp | 4 ++-- .../all-devices-common/devices/base-device/Device.h | 2 +- .../devices/boolean-state-sensor/BooleanStateSensorDevice.h | 6 +++--- .../devices/device-factory/DeviceFactory.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 4509ac81025a2e..fc1ae55fc8d219 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -31,8 +31,8 @@ CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModel ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); mEndpointRegistration.endpointEntry = DataModel::EndpointEntry{ - .id = endpoint, - .parentId = parentId, + .id = endpoint, + .parentId = parentId, .compositionPattern = DataModel::EndpointCompositionPattern::kFullFamily, }; return CHIP_NO_ERROR; diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 3470737a043e79..5ee1e1cbebfb85 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -54,7 +54,7 @@ class BaseDevice : public EndpointInterface protected: BaseDevice(const DataModel::DeviceTypeEntry & deviceType) : mDeviceType(deviceType), mEndpointRegistration(*this, {}) {} - + /// Internal registration function for common device clusters and endpoint registration. /// Subclasses are expected to call this CHIP_ERROR BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index 6daa229e851d65..67b59b59191474 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -28,9 +28,9 @@ class BooleanStateSensorDevice : public BaseDevice { public: /* - * This is a general class for boolean state sensor devices. The device type passed here will - * determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable - * class for the sensor types that share the same core functionality through the identify and + * This is a general class for boolean state sensor devices. The device type passed here will + * determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable + * class for the sensor types that share the same core functionality through the identify and * boolean state clusters. */ BooleanStateSensorDevice(std::unique_ptr timerDelegate, const DataModel::DeviceTypeEntry & deviceType) : diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index d6692683d81c18..795471d3c78a8b 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -27,7 +27,7 @@ namespace chip::app { /** - * This is a factory class made to be used to create any valid device type as part of the + * This is a factory class made to be used to create any valid device type as part of the * all-devices-app. This class is meant to abstract away some details of device specific code, * and to have more generic implementation code being used in main to create a device. The keys * in the device registry map are the command line arguments used to start the respective device. From 54f4933b3a171a74ddf78bc8bc7632082c8857de Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Oct 2025 16:04:06 +0000 Subject: [PATCH 08/48] Restyled by clang-format --- .../BooleanStateSensorDevice.cpp | 3 ++- .../boolean-state-sensor/BooleanStateSensorDevice.h | 10 ++++++---- .../devices/device-factory/DeviceFactory.h | 12 +++++++++--- .../devices/root-node/RootNodeDevice.h | 2 +- examples/all-devices-app/linux/main.cpp | 4 ++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp index 0f7f508a3b7005..c6e186b769cfee 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp @@ -20,7 +20,8 @@ using namespace chip::app::Clusters; namespace chip::app { -CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId) { ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index 67b59b59191474..d71a33aa86e625 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -16,9 +16,9 @@ */ #pragma once -#include #include #include +#include #include namespace chip { @@ -32,9 +32,11 @@ class BooleanStateSensorDevice : public BaseDevice * determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable * class for the sensor types that share the same core functionality through the identify and * boolean state clusters. - */ - BooleanStateSensorDevice(std::unique_ptr timerDelegate, const DataModel::DeviceTypeEntry & deviceType) : - BaseDevice(deviceType), mTimerDelegate(std::move(timerDelegate)) + */ + BooleanStateSensorDevice(std::unique_ptr timerDelegate, + const DataModel::DeviceTypeEntry & deviceType) : + BaseDevice(deviceType), + mTimerDelegate(std::move(timerDelegate)) {} ~BooleanStateSensorDevice() override = default; diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 795471d3c78a8b..3a7da3d6c3a724 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -18,11 +18,11 @@ #pragma once #include +#include #include #include #include #include -#include namespace chip::app { @@ -61,8 +61,14 @@ class DeviceFactory DeviceFactory() { - mRegistry["contact-sensor"] = []() { return std::make_unique(std::make_unique(), Device::Type::kContactSensor); }; - mRegistry["water-leak-detector"] = []() { return std::make_unique(std::make_unique(), Device::Type::kWaterLeakDetector); }; + mRegistry["contact-sensor"] = []() { + return std::make_unique(std::make_unique(), + Device::Type::kContactSensor); + }; + mRegistry["water-leak-detector"] = []() { + return std::make_unique(std::make_unique(), + Device::Type::kWaterLeakDetector); + }; } }; diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index cc9e1b62b7b33f..e01f934c679df2 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -27,9 +27,9 @@ #include #include #include +#include #include #include -#include namespace chip { namespace app { diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index cc6dc3142bac79..6c178ea427359b 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#include #include #include #include @@ -32,9 +33,8 @@ #include #include #include -#include -#include #include +#include using namespace chip; using namespace chip::app; From e755f19618903fdbcafb374978a2341007d48b79 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Oct 2025 16:04:09 +0000 Subject: [PATCH 09/48] Restyled by gn --- examples/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/BUILD.gn b/examples/BUILD.gn index fd66811b711924..a8cb18422949e2 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -26,9 +26,7 @@ if (chip_build_tests) { deps = [] tests = [] if (chip_device_platform == "linux" && current_os == "linux") { - tests += [ - "${chip_root}/examples/energy-management-app/energy-management-common/tests", - ] + tests += [ "${chip_root}/examples/energy-management-app/energy-management-common/tests" ] } } } From 899949aa45067884f134f9a785a98974392536d3 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 24 Oct 2025 14:48:05 -0400 Subject: [PATCH 10/48] More review comments --- .../devices/base-device/Device.cpp | 7 +--- .../devices/base-device/Device.h | 4 +- .../BooleanStateSensorDevice.h | 2 +- .../devices/device-factory/DeviceFactory.h | 4 +- .../devices/root-node/RootNodeDevice.h | 4 +- examples/all-devices-app/linux/BUILD.gn | 1 - examples/all-devices-app/linux/args.gni | 2 - .../linux/include/CHIPProjectAppConfig.h | 39 ------------------- .../build/testdata/all_targets_linux_x64.txt | 2 +- 9 files changed, 9 insertions(+), 56 deletions(-) delete mode 100644 examples/all-devices-app/linux/include/CHIPProjectAppConfig.h diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index fc1ae55fc8d219..8eda3f7a5e6118 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -41,12 +41,7 @@ CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModel CHIP_ERROR BaseDevice::DeviceTypes(ReadOnlyBufferBuilder & out) const { VerifyOrReturnValue(mDescriptorCluster.IsConstructed(), CHIP_NO_ERROR); - ReturnErrorOnFailure(out.EnsureAppendCapacity(1)); - - if (mDescriptorCluster.IsConstructed()) - { - ReturnErrorOnFailure(out.Append(mDeviceType)); - } + ReturnErrorOnFailure(out.ReferenceExisting(mDeviceTypes)); return CHIP_NO_ERROR; } diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 5ee1e1cbebfb85..27596f251e9fc5 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -53,14 +53,14 @@ class BaseDevice : public EndpointInterface CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; protected: - BaseDevice(const DataModel::DeviceTypeEntry & deviceType) : mDeviceType(deviceType), mEndpointRegistration(*this, {}) {} + BaseDevice(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} /// Internal registration function for common device clusters and endpoint registration. /// Subclasses are expected to call this CHIP_ERROR BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); EndpointId mEndpointId = kInvalidEndpointId; - const DataModel::DeviceTypeEntry mDeviceType; + Span mDeviceTypes; EndpointInterfaceRegistration mEndpointRegistration; // Common clusters.. diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index d71a33aa86e625..35867d58314140 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -34,7 +34,7 @@ class BooleanStateSensorDevice : public BaseDevice * boolean state clusters. */ BooleanStateSensorDevice(std::unique_ptr timerDelegate, - const DataModel::DeviceTypeEntry & deviceType) : + Span deviceType) : BaseDevice(deviceType), mTimerDelegate(std::move(timerDelegate)) {} diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 3a7da3d6c3a724..e7e8215312f5c4 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -63,11 +63,11 @@ class DeviceFactory { mRegistry["contact-sensor"] = []() { return std::make_unique(std::make_unique(), - Device::Type::kContactSensor); + Span(&Device::Type::kContactSensor, 1)); }; mRegistry["water-leak-detector"] = []() { return std::make_unique(std::make_unique(), - Device::Type::kWaterLeakDetector); + Span(&Device::Type::kWaterLeakDetector, 1)); }; } }; diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index e01f934c679df2..3052cb05a70e53 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include namespace chip { namespace app { @@ -45,7 +45,7 @@ class RootNodeDevice : public BaseDevice protected: // Most implementations require network commissioning, so only subclasses have access to this. - RootNodeDevice() : BaseDevice(Device::Type::kRootNode) {} + RootNodeDevice() : BaseDevice(Span(&Device::Type::kRootNode, 1)) {} private: LazyRegisteredServerCluster mBasicInformationCluster; diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index c5619a41781847..df0149f2980146 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -30,7 +30,6 @@ config("includes") { executable("all-devices-app") { sources = [ - "include/CHIPProjectAppConfig.h", "main.cpp", ] diff --git a/examples/all-devices-app/linux/args.gni b/examples/all-devices-app/linux/args.gni index 2f4c8cf88d8817..21e8a89c475fa7 100644 --- a/examples/all-devices-app/linux/args.gni +++ b/examples/all-devices-app/linux/args.gni @@ -18,8 +18,6 @@ import("//build_overrides/chip.gni") import("//build_overrides/pigweed.gni") import("${chip_root}/config/standalone/args.gni") -chip_device_project_config_include = "" -chip_project_config_include = "" chip_system_project_config_include = "" chip_project_config_include_dirs = diff --git a/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h b/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h deleted file mode 100644 index 1cca90ecc52655..00000000000000 --- a/examples/all-devices-app/linux/include/CHIPProjectAppConfig.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Copyright (c) 2025 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -// include the CHIPProjectConfig from config/standalone -#include - -#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0 - -// Bulbs do not typically use this - enabled so we can use shell to discover commissioners -#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT 1 - -#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 - -#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1 - -#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 0x0015 // Contact sensor - -#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1 - -#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1 - -#define CHIP_DEVICE_CONFIG_DEVICE_NAME "Contact sensor" diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index bfca70ad19640a..68ea156c9fd80f 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -9,7 +9,7 @@ efr32-{brd2601b,brd2605a,brd2703a,brd2704b,brd2708a,brd2911a,brd4186a,brd4186c,b esp32-{c3devkit,devkitc,m5stack,qemu}-{all-clusters,all-clusters-minimal,bridge,energy-gateway,energy-management,light,lock,ota-provider,ota-requestor,ota-requestor,shell,temperature-measurement,tests}[-ipv6only][-rpc][-tracing] genio-lighting-app linux-fake-tests[-asan][-boringssl][-clang][-coverage][-dmalloc][-libfuzzer][-mbedtls][-ossfuzz][-pw-fuzztest][-tsan][-ubsan] -linux-{arm64,x64}-{address-resolve-tool,air-purifier,air-quality-sensor,all-clusters,all-clusters-minimal,bridge,camera,camera-controller,chip-cert,chip-tool,closure,contact-sensor,dishwasher,energy-gateway,energy-management,fabric-admin,fabric-bridge,fabric-sync,java-matter-controller,jf-admin-app,jf-control-app,kotlin-matter-controller,light,light-data-model-no-unique-id,lit-icd,lock,microwave-oven,minmdns,network-manager,ota-provider,ota-requestor,python-bindings,refrigerator,rpc-console,rvc,shell,simulated-app1,simulated-app2,terms-and-conditions,tests,thermostat,tv-app,tv-casting-app,water-leak-detector}[-asan][-boringssl][-chip-casting-simplified][-clang][-coverage][-disable-dnssd-tests][-dmalloc][-enable-dnssd-tests][-evse-test-event][-googletest][-ipv6only][-libfuzzer][-libnl][-mbedtls][-minmdns-verbose][-nfc-commission][-nlfaultinject][-no-ble][-no-interactive][-no-shell][-no-thread][-no-wifi][-no-wifipaf][-nodeps][-ossfuzz][-platform-mdns][-pw-fuzztest][-rpc][-same-event-loop][-terms-and-conditions][-test][-tsan][-ubsan][-webrtc][-with-ui] +linux-{arm64,x64}-{address-resolve-tool,air-purifier,air-quality-sensor,all-clusters,all-clusters-minimal,all-devices-app,bridge,camera,camera-controller,chip-cert,chip-tool,closure,contact-sensor,dishwasher,energy-gateway,energy-management,fabric-admin,fabric-bridge,fabric-sync,java-matter-controller,jf-admin-app,jf-control-app,kotlin-matter-controller,light,light-data-model-no-unique-id,lit-icd,lock,microwave-oven,minmdns,network-manager,ota-provider,ota-requestor,python-bindings,refrigerator,rpc-console,rvc,shell,simulated-app1,simulated-app2,terms-and-conditions,tests,thermostat,tv-app,tv-casting-app,water-leak-detector}[-asan][-boringssl][-chip-casting-simplified][-clang][-coverage][-disable-dnssd-tests][-dmalloc][-enable-dnssd-tests][-evse-test-event][-googletest][-ipv6only][-libfuzzer][-libnl][-mbedtls][-minmdns-verbose][-nfc-commission][-nlfaultinject][-no-ble][-no-interactive][-no-shell][-no-thread][-no-wifi][-no-wifipaf][-nodeps][-ossfuzz][-platform-mdns][-pw-fuzztest][-rpc][-same-event-loop][-terms-and-conditions][-test][-tsan][-ubsan][-webrtc][-with-ui] linux-x64-efr32-test-runner[-clang] imx-{all-clusters-app,all-clusters-minimal-app,chip-tool,lighting-app,ota-provider-app,thermostat}[-release][-trusty] infineon-psoc6-{all-clusters,all-clusters-minimal,light,lock}[-ota][-trustm][-updateimage] From 14230f4c5642d54cb0430d9ed5b1cda4caba1e2e Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 24 Oct 2025 16:07:21 -0400 Subject: [PATCH 11/48] Review comments for BUILD.gn configs --- .../all-devices-common/devices/BUILD.gn | 18 ++++++++++++++++++ .../devices/base-device/BUILD.gn | 7 +------ .../devices/base-device/Device.cpp | 2 +- .../devices/boolean-state-sensor/BUILD.gn | 7 +------ .../devices/device-factory/BUILD.gn | 7 +------ .../devices/root-node/BUILD.gn | 7 +------ 6 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 examples/all-devices-app/all-devices-common/devices/BUILD.gn diff --git a/examples/all-devices-app/all-devices-common/devices/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/BUILD.gn new file mode 100644 index 00000000000000..273449fed25680 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +config("includes") { + # allows includes like "devices/..." + include_dirs = [ ".." ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn index d70f4af6c8e7b8..6f1b4ae9f08b9f 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn @@ -15,11 +15,6 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -config("includes") { - # allows includes like "devices/..." - include_dirs = [ "../.." ] -} - source_set("base-device") { sources = [ "Device.cpp", @@ -34,7 +29,7 @@ source_set("base-device") { ] public_configs = [ - ":includes", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", "${chip_root}/src:includes", ] } diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 8eda3f7a5e6118..9bc343a4cb3320 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "Device.h" +#include #include using namespace chip::app::Clusters; diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn index 266ce6f6f1ba51..4735d17bac9e73 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn @@ -15,11 +15,6 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -config("includes") { - # allows includes like "devices/..." - include_dirs = [ ".." ] -} - source_set("boolean-state-sensor") { sources = [ "BooleanStateSensorDevice.cpp", @@ -36,7 +31,7 @@ source_set("boolean-state-sensor") { ] public_configs = [ - ":includes", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", "${chip_root}/src:includes", ] } diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn index 412b1663671b99..7331b6f1fa307a 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/BUILD.gn @@ -15,11 +15,6 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -config("includes") { - # allows includes like "devices/..." - include_dirs = [ "../.." ] -} - source_set("device-factory") { sources = [ "DeviceFactory.h" ] @@ -30,7 +25,7 @@ source_set("device-factory") { ] public_configs = [ - ":includes", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", "${chip_root}/src:includes", ] } diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn index 7088d01279afc2..3bd2220be5f7a7 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn @@ -15,11 +15,6 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -config("includes") { - # allows includes like "devices/..." - include_dirs = [ ".." ] -} - source_set("root-node") { sources = [ "RootNodeDevice.cpp", @@ -45,7 +40,7 @@ source_set("root-node") { ] public_configs = [ - ":includes", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", "${chip_root}/src:includes", ] } From 0debc8da7fd7bf041f69ff3eb1d37fbd906bf59f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Oct 2025 20:09:38 +0000 Subject: [PATCH 12/48] Restyled by clang-format --- .../devices/device-factory/DeviceFactory.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index e7e8215312f5c4..03306d084fd0ab 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -62,12 +62,13 @@ class DeviceFactory DeviceFactory() { mRegistry["contact-sensor"] = []() { - return std::make_unique(std::make_unique(), - Span(&Device::Type::kContactSensor, 1)); + return std::make_unique( + std::make_unique(), Span(&Device::Type::kContactSensor, 1)); }; mRegistry["water-leak-detector"] = []() { - return std::make_unique(std::make_unique(), - Span(&Device::Type::kWaterLeakDetector, 1)); + return std::make_unique( + std::make_unique(), + Span(&Device::Type::kWaterLeakDetector, 1)); }; } }; From 523ed12c2a745e55f7c96d310adaa767eaa0865a Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Oct 2025 20:09:41 +0000 Subject: [PATCH 13/48] Restyled by gn --- examples/all-devices-app/linux/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index df0149f2980146..f02793f8b3e32a 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -29,9 +29,7 @@ config("includes") { } executable("all-devices-app") { - sources = [ - "main.cpp", - ] + sources = [ "main.cpp" ] deps = [ "${chip_root}/examples/all-devices-app/all-devices-common/devices/device-factory", From 1f52853950edce3dbdbbb59c13f86a8b902e013e Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Mon, 27 Oct 2025 13:20:20 +0000 Subject: [PATCH 14/48] Add TODOs based on review comments --- .../all-devices-common/devices/base-device/Device.cpp | 2 ++ .../all-devices-common/devices/root-node/RootNodeDevice.cpp | 3 +++ examples/all-devices-app/linux/main.cpp | 2 ++ 3 files changed, 7 insertions(+) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 9bc343a4cb3320..d5ed97035cae9f 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -27,6 +27,8 @@ CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModel VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); mEndpointId = endpoint; + //TODO: This needs to be updated to be more customizable and allow the cluster to be created with + // optional attributes or semantic tags being set. mDescriptorCluster.Create(endpoint, DescriptorCluster::OptionalAttributesSet(0), Span()); ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index 43044d90a15563..db8889ad738e71 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -35,6 +35,9 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr ReturnErrorOnFailure(BaseRegistration(endpointId, provider, parentId)); mBasicInformationCluster.Create(); + + //TODO: This needs to be refactored so the optional attributes being set for + // the cluster are configurable to allow different settings mBasicInformationCluster.Cluster() .OptionalAttributes() .Set() diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 6c178ea427359b..8f90bdb1cc889f 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -82,6 +82,8 @@ bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int i return true; } +//TODO: This message on supported device types needs to be updated to scale +// better once new devices are added. chip::ArgParser::OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function sAllDevicesAppOptionDefs, // array of option definitions "PROGRAM OPTIONS", // help group From cdd6d6e178c99635a4e6a905db5d5365f3c75bf9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 27 Oct 2025 13:22:01 +0000 Subject: [PATCH 15/48] Restyled by whitespace --- .../all-devices-common/devices/base-device/Device.cpp | 4 ++-- .../all-devices-common/devices/root-node/RootNodeDevice.cpp | 4 ++-- examples/all-devices-app/linux/main.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index d5ed97035cae9f..c1491a6b764e4c 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -27,8 +27,8 @@ CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModel VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); mEndpointId = endpoint; - //TODO: This needs to be updated to be more customizable and allow the cluster to be created with - // optional attributes or semantic tags being set. + //TODO: This needs to be updated to be more customizable and allow the cluster to be created with + // optional attributes or semantic tags being set. mDescriptorCluster.Create(endpoint, DescriptorCluster::OptionalAttributesSet(0), Span()); ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index db8889ad738e71..a9b2bf9d11914e 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -36,8 +36,8 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr mBasicInformationCluster.Create(); - //TODO: This needs to be refactored so the optional attributes being set for - // the cluster are configurable to allow different settings + //TODO: This needs to be refactored so the optional attributes being set for + // the cluster are configurable to allow different settings mBasicInformationCluster.Cluster() .OptionalAttributes() .Set() diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 8f90bdb1cc889f..61f0f721ece025 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -82,7 +82,7 @@ bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int i return true; } -//TODO: This message on supported device types needs to be updated to scale +//TODO: This message on supported device types needs to be updated to scale // better once new devices are added. chip::ArgParser::OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function sAllDevicesAppOptionDefs, // array of option definitions From 1e8876a4e4f7551f0f8fe94404aaededb79d85a0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 27 Oct 2025 13:22:06 +0000 Subject: [PATCH 16/48] Restyled by clang-format --- .../all-devices-common/devices/base-device/Device.cpp | 4 ++-- .../all-devices-common/devices/root-node/RootNodeDevice.cpp | 4 ++-- examples/all-devices-app/linux/main.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index c1491a6b764e4c..59c59d895def58 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -27,8 +27,8 @@ CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModel VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); mEndpointId = endpoint; - //TODO: This needs to be updated to be more customizable and allow the cluster to be created with - // optional attributes or semantic tags being set. + // TODO: This needs to be updated to be more customizable and allow the cluster to be created with + // optional attributes or semantic tags being set. mDescriptorCluster.Create(endpoint, DescriptorCluster::OptionalAttributesSet(0), Span()); ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index a9b2bf9d11914e..1d965b1152d43f 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -36,8 +36,8 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr mBasicInformationCluster.Create(); - //TODO: This needs to be refactored so the optional attributes being set for - // the cluster are configurable to allow different settings + // TODO: This needs to be refactored so the optional attributes being set for + // the cluster are configurable to allow different settings mBasicInformationCluster.Cluster() .OptionalAttributes() .Set() diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 61f0f721ece025..7c6fb03647e0cb 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -82,8 +82,8 @@ bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int i return true; } -//TODO: This message on supported device types needs to be updated to scale -// better once new devices are added. +// TODO: This message on supported device types needs to be updated to scale +// better once new devices are added. chip::ArgParser::OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function sAllDevicesAppOptionDefs, // array of option definitions "PROGRAM OPTIONS", // help group From 42517f3bf5d1acf16493c88cb1711ce78212c72e Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Mon, 27 Oct 2025 15:13:05 -0400 Subject: [PATCH 17/48] Update wifi diagnostics optional atteribute set usage --- .../all-devices-common/devices/root-node/RootNodeDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index 1d965b1152d43f..028da57a9a3677 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -132,7 +132,7 @@ CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataMod ReturnErrorOnFailure(RootNodeDevice::Register(endpointId, provider, parentId)); mWifiDiagnosticsCluster.Create(endpointId, DeviceLayer::GetDiagnosticDataProvider(), - WiFiDiagnosticsServerLogic::OptionalAttributeSet{}, BitFlags{}); + WiFiDiagnosticsServerCluster::OptionalAttributeSet{}, BitFlags{}); ReturnErrorOnFailure(provider.AddCluster(mWifiDiagnosticsCluster.Registration())); mNetworkCommissioningCluster.Create(endpointId, mWifiDriver); From eebaef94849eeb70a0d9397206f0cb842d92ed16 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Mon, 27 Oct 2025 15:13:46 -0400 Subject: [PATCH 18/48] Remove SemanticTags function from Device --- .../all-devices-common/devices/base-device/Device.cpp | 6 ------ .../all-devices-common/devices/base-device/Device.h | 1 - 2 files changed, 7 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 59c59d895def58..632244e25dc837 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -48,12 +48,6 @@ CHIP_ERROR BaseDevice::DeviceTypes(ReadOnlyBufferBuilder & out) const -{ - // no semantic tags - return CHIP_NO_ERROR; -} - CHIP_ERROR BaseDevice::ClientClusters(ReadOnlyBufferBuilder & out) const { // no bindings diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 27596f251e9fc5..36afc0f7939c90 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -48,7 +48,6 @@ class BaseDevice : public EndpointInterface virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; // Endpoint interface implementation - CHIP_ERROR SemanticTags(ReadOnlyBufferBuilder & out) const override; CHIP_ERROR DeviceTypes(ReadOnlyBufferBuilder & out) const override; CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; From c1c6f3a306561d791ec80cd5a26f606a68ff8d31 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 27 Oct 2025 19:16:50 +0000 Subject: [PATCH 19/48] Restyled by clang-format --- .../all-devices-common/devices/root-node/RootNodeDevice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index 028da57a9a3677..0de95914df63e1 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -132,7 +132,8 @@ CHIP_ERROR WifiRootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataMod ReturnErrorOnFailure(RootNodeDevice::Register(endpointId, provider, parentId)); mWifiDiagnosticsCluster.Create(endpointId, DeviceLayer::GetDiagnosticDataProvider(), - WiFiDiagnosticsServerCluster::OptionalAttributeSet{}, BitFlags{}); + WiFiDiagnosticsServerCluster::OptionalAttributeSet{}, + BitFlags{}); ReturnErrorOnFailure(provider.AddCluster(mWifiDiagnosticsCluster.Registration())); mNetworkCommissioningCluster.Create(endpointId, mWifiDriver); From 5164883dc483cb08c1da216e67567da95c9d1d3e Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Wed, 29 Oct 2025 10:50:48 -0400 Subject: [PATCH 20/48] Make device endpoint a command line argument --- examples/all-devices-app/linux/main.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 7c6fb03647e0cb..d1760fd7e4b1e7 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -55,25 +55,32 @@ LinuxCommissionableDataProvider gCommissionableDataProvider; // App custom argument handling constexpr uint16_t kOptionDeviceType = 0xffd0; +constexpr uint16_t kOptionEndpoint = 0xffd1; const char * deviceTypeName = "contact-sensor"; // defaulting to contact sensor if not specified +EndpointId deviceEndpoint = 1; // defaulting to endpoint 1 if not specified chip::ArgParser::OptionDef sAllDevicesAppOptionDefs[] = { { "device", chip::ArgParser::kArgumentRequired, kOptionDeviceType }, + { "endpoint", chip::ArgParser::kArgumentRequired, kOptionEndpoint }, }; bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int identifier, const char * name, const char * value) { switch (identifier) { - case kOptionDeviceType: + case kOptionDeviceType: if (value == nullptr || !DeviceFactory::GetInstance().IsValidDevice(value)) { - ChipLogError(Support, "INTERNAL ERROR: Invalid device type: %s\n", value); + ChipLogError(Support, "INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n", value); return false; } ChipLogProgress(AppServer, "Using the device type of %s", value); deviceTypeName = value; return true; + case kOptionEndpoint: + deviceEndpoint = static_cast(atoi(value)); + ChipLogProgress(AppServer, "Using endpoint %d for the device.", deviceEndpoint); + return true; default: ChipLogError(Support, "%s: INTERNAL ERROR: Unhandled option: %s\n", program, name); return false; @@ -87,7 +94,8 @@ bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int i chip::ArgParser::OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function sAllDevicesAppOptionDefs, // array of option definitions "PROGRAM OPTIONS", // help group - "-d, --device \n" }; + "-d, --device \n" + "-e, --endpoint \n"}; void StopSignalHandler(int /* signal */) { @@ -113,7 +121,7 @@ chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentS rootNodeDevice.Register(kRootEndpointId, dataModelProvider, kInvalidEndpointId); constructedDevice = DeviceFactory::GetInstance().Create(deviceTypeName); - constructedDevice->Register(1, dataModelProvider, kInvalidEndpointId); + constructedDevice->Register(deviceEndpoint, dataModelProvider, kInvalidEndpointId); return &dataModelProvider; } From ed2caa6604b786c0ae111224dac72b92c3f6b283 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Wed, 29 Oct 2025 14:25:44 -0400 Subject: [PATCH 21/48] Cleanup includes and remove old args.gni --- .../devices/base-device/Device.cpp | 1 - .../BooleanStateSensorDevice.h | 1 + examples/all-devices-app/linux/.gn | 4 --- examples/all-devices-app/linux/args.gni | 26 ------------------- examples/all-devices-app/linux/main.cpp | 3 --- 5 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 examples/all-devices-app/linux/args.gni diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 632244e25dc837..8ab2a9dfb74807 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -16,7 +16,6 @@ */ #include -#include using namespace chip::app::Clusters; diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index 35867d58314140..db7bf51b55192f 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace chip { namespace app { diff --git a/examples/all-devices-app/linux/.gn b/examples/all-devices-app/linux/.gn index 5e56861d956ef5..23cdfb229b946a 100644 --- a/examples/all-devices-app/linux/.gn +++ b/examples/all-devices-app/linux/.gn @@ -19,7 +19,3 @@ buildconfig = "${build_root}/config/BUILDCONFIG.gn" # CHIP uses angle bracket includes. check_system_includes = true - -default_args = { - import("//args.gni") -} diff --git a/examples/all-devices-app/linux/args.gni b/examples/all-devices-app/linux/args.gni deleted file mode 100644 index 21e8a89c475fa7..00000000000000 --- a/examples/all-devices-app/linux/args.gni +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2025 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# CHIPProjectConfig.h - -import("//build_overrides/chip.gni") -import("//build_overrides/pigweed.gni") -import("${chip_root}/config/standalone/args.gni") - -chip_system_project_config_include = "" - -chip_project_config_include_dirs = - [ "${chip_root}/examples/contact-sensor-app/linux/include" ] -chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] -matter_enable_tracing_support = true diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index d1760fd7e4b1e7..bf7f99cfd67df3 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -23,10 +23,7 @@ #include #include #include -#include #include -#include -#include #include #include #include From cd2c5e0bc3af0db5c9995baf6458c6658b904a6e Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Thu, 30 Oct 2025 18:08:33 -0400 Subject: [PATCH 22/48] Address comments, make command line args seperate from main --- .../devices/device-factory/DeviceFactory.h | 2 + examples/all-devices-app/linux/BUILD.gn | 1 + .../linux/app_options/AppOptions.cpp | 77 +++++++++++++++++++ .../linux/app_options/AppOptions.h | 43 +++++++++++ .../linux/app_options/BUILD.gn | 40 ++++++++++ examples/all-devices-app/linux/main.cpp | 49 +----------- 6 files changed, 167 insertions(+), 45 deletions(-) create mode 100644 examples/all-devices-app/linux/app_options/AppOptions.cpp create mode 100644 examples/all-devices-app/linux/app_options/AppOptions.h create mode 100644 examples/all-devices-app/linux/app_options/BUILD.gn diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 03306d084fd0ab..0e182ea3604309 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -52,6 +52,8 @@ class DeviceFactory if (IsValidDevice(deviceTypeArg)) { return mRegistry.find(deviceTypeArg)->second(); + }else { + ChipLogError(Support, "INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n", deviceTypeArg.c_str()); } return nullptr; } diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index f02793f8b3e32a..f29b0eb18c6e11 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -42,6 +42,7 @@ executable("all-devices-app") { "${chip_root}/src/app/persistence:default", "${chip_root}/src/data-model-providers/codedriven", "${chip_root}/src/lib", + "${chip_root}/examples/all-devices-app/linux/app_options:app-options", ] deps += pw_build_LINK_DEPS diff --git a/examples/all-devices-app/linux/app_options/AppOptions.cpp b/examples/all-devices-app/linux/app_options/AppOptions.cpp new file mode 100644 index 00000000000000..3bfb72b99778d5 --- /dev/null +++ b/examples/all-devices-app/linux/app_options/AppOptions.cpp @@ -0,0 +1,77 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +using namespace chip; +using namespace chip::ArgParser; + +// App custom argument handling +constexpr uint16_t kOptionDeviceType = 0xffd0; +constexpr uint16_t kOptionEndpoint = 0xffd1; + +const char * AppOptions::mDeviceTypeName = "contact-sensor"; // defaulting to contact sensor if not specified +chip::EndpointId AppOptions::mDeviceEndpoint = 1; // defaulting to endpoint 1 if not specified + +bool AppOptions::AllDevicesAppOptionHandler(const char * program, OptionSet * options, int identifier, const char * name, const char * value) +{ + switch (identifier) + { + case kOptionDeviceType: + if (value == nullptr) + { + ChipLogError(Support, "INTERNAL ERROR: No device type value passed in.\n"); + return false; + } + ChipLogProgress(AppServer, "Using the device type of %s", value); + mDeviceTypeName = value; + return true; + case kOptionEndpoint: + if (value == nullptr) + { + ChipLogError(Support, "INTERNAL ERROR: No endpoint ID value passed in.\n"); + return false; + } + mDeviceEndpoint = static_cast(atoi(value)); + ChipLogProgress(AppServer, "Using endpoint %d for the device.", mDeviceEndpoint); + return true; + default: + ChipLogError(Support, "%s: INTERNAL ERROR: Unhandled option: %s\n", program, name); + return false; + } + + return true; +} + +OptionSet * AppOptions::GetOptions() +{ + static OptionDef sAllDevicesAppOptionDefs[] = { + { "device", kArgumentRequired, kOptionDeviceType }, + { "endpoint", kArgumentRequired, kOptionEndpoint }, + }; + + // TODO: This message on supported device types needs to be updated to scale + // better once new devices are added. + static OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function + sAllDevicesAppOptionDefs, // array of option definitions + "PROGRAM OPTIONS", // help group + "-d, --device \n" + "-e, --endpoint \n"}; + + return &sCmdLineOptions; +} \ No newline at end of file diff --git a/examples/all-devices-app/linux/app_options/AppOptions.h b/examples/all-devices-app/linux/app_options/AppOptions.h new file mode 100644 index 00000000000000..d78f5226844a3e --- /dev/null +++ b/examples/all-devices-app/linux/app_options/AppOptions.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +class AppOptions +{ +public: + static chip::ArgParser::OptionSet * GetOptions(); + + static const char* GetDeviceType(){ + return mDeviceTypeName; + } + + static chip::EndpointId GetDeviceEndpoint(){ + return mDeviceEndpoint; + } + +private: + static bool AllDevicesAppOptionHandler(const char * program, chip::ArgParser::OptionSet * options, int identifier, const char * name, const char * value); + + static const char * mDeviceTypeName; + static chip::EndpointId mDeviceEndpoint; +}; diff --git a/examples/all-devices-app/linux/app_options/BUILD.gn b/examples/all-devices-app/linux/app_options/BUILD.gn new file mode 100644 index 00000000000000..c2938b1f5c7f6f --- /dev/null +++ b/examples/all-devices-app/linux/app_options/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +config("option-includes") { + include_dirs = [ ".." ] +} + + +source_set("app-options") { + sources = [ + "AppOptions.h", + "AppOptions.cpp", + ] + + public_deps = [ + "${chip_root}/examples/common/tracing:commandline", + "${chip_root}/examples/platform/linux:app-main", + "${chip_root}/src/lib", + ] + + public_configs = [ + "${chip_root}/src:includes", + ":option-includes", + ] + +} \ No newline at end of file diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index bf7f99cfd67df3..b843e2cd800c55 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace chip; using namespace chip::app; @@ -50,49 +51,7 @@ DeviceInfoProviderImpl gExampleDeviceInfoProvider; // To hold SPAKE2+ verifier, discriminator, passcode LinuxCommissionableDataProvider gCommissionableDataProvider; -// App custom argument handling -constexpr uint16_t kOptionDeviceType = 0xffd0; -constexpr uint16_t kOptionEndpoint = 0xffd1; -const char * deviceTypeName = "contact-sensor"; // defaulting to contact sensor if not specified -EndpointId deviceEndpoint = 1; // defaulting to endpoint 1 if not specified -chip::ArgParser::OptionDef sAllDevicesAppOptionDefs[] = { - { "device", chip::ArgParser::kArgumentRequired, kOptionDeviceType }, - { "endpoint", chip::ArgParser::kArgumentRequired, kOptionEndpoint }, -}; - -bool AllDevicesAppOptionHandler(const char * program, OptionSet * options, int identifier, const char * name, const char * value) -{ - switch (identifier) - { - case kOptionDeviceType: - if (value == nullptr || !DeviceFactory::GetInstance().IsValidDevice(value)) - { - ChipLogError(Support, "INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n", value); - return false; - } - ChipLogProgress(AppServer, "Using the device type of %s", value); - deviceTypeName = value; - return true; - case kOptionEndpoint: - deviceEndpoint = static_cast(atoi(value)); - ChipLogProgress(AppServer, "Using endpoint %d for the device.", deviceEndpoint); - return true; - default: - ChipLogError(Support, "%s: INTERNAL ERROR: Unhandled option: %s\n", program, name); - return false; - } - - return true; -} - -// TODO: This message on supported device types needs to be updated to scale -// better once new devices are added. -chip::ArgParser::OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function - sAllDevicesAppOptionDefs, // array of option definitions - "PROGRAM OPTIONS", // help group - "-d, --device \n" - "-e, --endpoint \n"}; void StopSignalHandler(int /* signal */) { @@ -117,8 +76,8 @@ chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentS static std::unique_ptr constructedDevice; rootNodeDevice.Register(kRootEndpointId, dataModelProvider, kInvalidEndpointId); - constructedDevice = DeviceFactory::GetInstance().Create(deviceTypeName); - constructedDevice->Register(deviceEndpoint, dataModelProvider, kInvalidEndpointId); + constructedDevice = DeviceFactory::GetInstance().Create(AppOptions::GetDeviceType()); + constructedDevice->Register(AppOptions::GetDeviceEndpoint(), dataModelProvider, kInvalidEndpointId); return &dataModelProvider; } @@ -236,7 +195,7 @@ CHIP_ERROR Initialize(int argc, char * argv[]) { ChipLogProgress(AppServer, "Initializing..."); ReturnErrorOnFailure(Platform::MemoryInit()); - ReturnErrorOnFailure(ParseArguments(argc, argv, &sCmdLineOptions)); + ReturnErrorOnFailure(ParseArguments(argc, argv, AppOptions::GetOptions())); ReturnErrorOnFailure(DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH)); ReturnErrorOnFailure(DeviceLayer::PlatformMgr().InitChipStack()); From ec9c9ba2329d9b65fc432422ce3680837cfa6376 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 31 Oct 2025 13:50:02 +0000 Subject: [PATCH 23/48] Restyled by whitespace --- .../all-devices-app/linux/app_options/AppOptions.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/all-devices-app/linux/app_options/AppOptions.cpp b/examples/all-devices-app/linux/app_options/AppOptions.cpp index 3bfb72b99778d5..06d0a53089ed43 100644 --- a/examples/all-devices-app/linux/app_options/AppOptions.cpp +++ b/examples/all-devices-app/linux/app_options/AppOptions.cpp @@ -32,7 +32,7 @@ bool AppOptions::AllDevicesAppOptionHandler(const char * program, OptionSet * op { switch (identifier) { - case kOptionDeviceType: + case kOptionDeviceType: if (value == nullptr) { ChipLogError(Support, "INTERNAL ERROR: No device type value passed in.\n"); @@ -41,7 +41,7 @@ bool AppOptions::AllDevicesAppOptionHandler(const char * program, OptionSet * op ChipLogProgress(AppServer, "Using the device type of %s", value); mDeviceTypeName = value; return true; - case kOptionEndpoint: + case kOptionEndpoint: if (value == nullptr) { ChipLogError(Support, "INTERNAL ERROR: No endpoint ID value passed in.\n"); @@ -58,7 +58,7 @@ bool AppOptions::AllDevicesAppOptionHandler(const char * program, OptionSet * op return true; } -OptionSet * AppOptions::GetOptions() +OptionSet * AppOptions::GetOptions() { static OptionDef sAllDevicesAppOptionDefs[] = { { "device", kArgumentRequired, kOptionDeviceType }, @@ -70,8 +70,8 @@ OptionSet * AppOptions::GetOptions() static OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function sAllDevicesAppOptionDefs, // array of option definitions "PROGRAM OPTIONS", // help group - "-d, --device \n" + "-d, --device \n" "-e, --endpoint \n"}; return &sCmdLineOptions; -} \ No newline at end of file +} From 0b4d7cb5f1af00a65046a508f6b29515fd3c2395 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 31 Oct 2025 13:50:06 +0000 Subject: [PATCH 24/48] Restyled by clang-format --- .../devices/device-factory/DeviceFactory.h | 9 +++++++-- .../linux/app_options/AppOptions.cpp | 15 ++++++++------- .../linux/app_options/AppOptions.h | 13 +++++-------- examples/all-devices-app/linux/main.cpp | 4 +--- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index 0e182ea3604309..b6f83360f4b789 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -52,8 +52,13 @@ class DeviceFactory if (IsValidDevice(deviceTypeArg)) { return mRegistry.find(deviceTypeArg)->second(); - }else { - ChipLogError(Support, "INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n", deviceTypeArg.c_str()); + } + else + { + ChipLogError( + Support, + "INTERNAL ERROR: Invalid device type: %s. Run with the --help argument to view the list of valid device types.\n", + deviceTypeArg.c_str()); } return nullptr; } diff --git a/examples/all-devices-app/linux/app_options/AppOptions.cpp b/examples/all-devices-app/linux/app_options/AppOptions.cpp index 06d0a53089ed43..a971bbfbff04e3 100644 --- a/examples/all-devices-app/linux/app_options/AppOptions.cpp +++ b/examples/all-devices-app/linux/app_options/AppOptions.cpp @@ -25,10 +25,11 @@ using namespace chip::ArgParser; constexpr uint16_t kOptionDeviceType = 0xffd0; constexpr uint16_t kOptionEndpoint = 0xffd1; -const char * AppOptions::mDeviceTypeName = "contact-sensor"; // defaulting to contact sensor if not specified -chip::EndpointId AppOptions::mDeviceEndpoint = 1; // defaulting to endpoint 1 if not specified +const char * AppOptions::mDeviceTypeName = "contact-sensor"; // defaulting to contact sensor if not specified +chip::EndpointId AppOptions::mDeviceEndpoint = 1; // defaulting to endpoint 1 if not specified -bool AppOptions::AllDevicesAppOptionHandler(const char * program, OptionSet * options, int identifier, const char * name, const char * value) +bool AppOptions::AllDevicesAppOptionHandler(const char * program, OptionSet * options, int identifier, const char * name, + const char * value) { switch (identifier) { @@ -68,10 +69,10 @@ OptionSet * AppOptions::GetOptions() // TODO: This message on supported device types needs to be updated to scale // better once new devices are added. static OptionSet sCmdLineOptions = { AllDevicesAppOptionHandler, // handler function - sAllDevicesAppOptionDefs, // array of option definitions - "PROGRAM OPTIONS", // help group - "-d, --device \n" - "-e, --endpoint \n"}; + sAllDevicesAppOptionDefs, // array of option definitions + "PROGRAM OPTIONS", // help group + "-d, --device \n" + "-e, --endpoint \n" }; return &sCmdLineOptions; } diff --git a/examples/all-devices-app/linux/app_options/AppOptions.h b/examples/all-devices-app/linux/app_options/AppOptions.h index d78f5226844a3e..57307b2b594a1a 100644 --- a/examples/all-devices-app/linux/app_options/AppOptions.h +++ b/examples/all-devices-app/linux/app_options/AppOptions.h @@ -19,24 +19,21 @@ #pragma once #include -#include #include +#include class AppOptions { public: static chip::ArgParser::OptionSet * GetOptions(); - static const char* GetDeviceType(){ - return mDeviceTypeName; - } + static const char * GetDeviceType() { return mDeviceTypeName; } - static chip::EndpointId GetDeviceEndpoint(){ - return mDeviceEndpoint; - } + static chip::EndpointId GetDeviceEndpoint() { return mDeviceEndpoint; } private: - static bool AllDevicesAppOptionHandler(const char * program, chip::ArgParser::OptionSet * options, int identifier, const char * name, const char * value); + static bool AllDevicesAppOptionHandler(const char * program, chip::ArgParser::OptionSet * options, int identifier, + const char * name, const char * value); static const char * mDeviceTypeName; static chip::EndpointId mDeviceEndpoint; diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index b843e2cd800c55..3d5f88597d9c98 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include using namespace chip; using namespace chip::app; @@ -51,8 +51,6 @@ DeviceInfoProviderImpl gExampleDeviceInfoProvider; // To hold SPAKE2+ verifier, discriminator, passcode LinuxCommissionableDataProvider gCommissionableDataProvider; - - void StopSignalHandler(int /* signal */) { if (gMainLoopImplementation != nullptr) From 1cabc929e5bf2abe4ced46dcf0fcbabb96a17d64 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 31 Oct 2025 13:50:09 +0000 Subject: [PATCH 25/48] Restyled by gn --- examples/all-devices-app/linux/BUILD.gn | 2 +- .../linux/app_options/BUILD.gn | 30 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index f29b0eb18c6e11..a987edf00783ab 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -34,6 +34,7 @@ executable("all-devices-app") { deps = [ "${chip_root}/examples/all-devices-app/all-devices-common/devices/device-factory", "${chip_root}/examples/all-devices-app/all-devices-common/devices/root-node", + "${chip_root}/examples/all-devices-app/linux/app_options:app-options", "${chip_root}/examples/common/tracing:commandline", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/examples/platform/linux:linux-commissionable-data-provider", @@ -42,7 +43,6 @@ executable("all-devices-app") { "${chip_root}/src/app/persistence:default", "${chip_root}/src/data-model-providers/codedriven", "${chip_root}/src/lib", - "${chip_root}/examples/all-devices-app/linux/app_options:app-options", ] deps += pw_build_LINK_DEPS diff --git a/examples/all-devices-app/linux/app_options/BUILD.gn b/examples/all-devices-app/linux/app_options/BUILD.gn index c2938b1f5c7f6f..976d325ad9c702 100644 --- a/examples/all-devices-app/linux/app_options/BUILD.gn +++ b/examples/all-devices-app/linux/app_options/BUILD.gn @@ -19,22 +19,20 @@ config("option-includes") { include_dirs = [ ".." ] } - source_set("app-options") { - sources = [ - "AppOptions.h", - "AppOptions.cpp", - ] - - public_deps = [ - "${chip_root}/examples/common/tracing:commandline", - "${chip_root}/examples/platform/linux:app-main", - "${chip_root}/src/lib", - ] + sources = [ + "AppOptions.cpp", + "AppOptions.h", + ] - public_configs = [ - "${chip_root}/src:includes", - ":option-includes", - ] + public_deps = [ + "${chip_root}/examples/common/tracing:commandline", + "${chip_root}/examples/platform/linux:app-main", + "${chip_root}/src/lib", + ] -} \ No newline at end of file + public_configs = [ + "${chip_root}/src:includes", + ":option-includes", + ] +} From 879cffd6f8e1631528b1e8fb3079b73107766914 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 31 Oct 2025 11:24:37 -0400 Subject: [PATCH 26/48] separation of base device with single endpoint device --- .../devices/base-device/Device.cpp | 18 ------ .../devices/base-device/Device.h | 7 -- .../devices/boolean-state-sensor/BUILD.gn | 2 +- .../BooleanStateSensorDevice.cpp | 2 +- .../BooleanStateSensorDevice.h | 6 +- .../devices/root-node/BUILD.gn | 2 +- .../devices/root-node/RootNodeDevice.cpp | 2 +- .../devices/root-node/RootNodeDevice.h | 6 +- .../devices/single-endpoint/BUILD.gn | 36 +++++++++++ .../single-endpoint/SingleEndpointDevice.cpp | 42 ++++++++++++ .../single-endpoint/SingleEndpointDevice.h | 64 +++++++++++++++++++ 11 files changed, 152 insertions(+), 35 deletions(-) create mode 100644 examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn create mode 100644 examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp create mode 100644 examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp index 8ab2a9dfb74807..c1067d03ef2029 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp @@ -21,24 +21,6 @@ using namespace chip::app::Clusters; namespace chip::app { -CHIP_ERROR BaseDevice::BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) -{ - VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); - mEndpointId = endpoint; - - // TODO: This needs to be updated to be more customizable and allow the cluster to be created with - // optional attributes or semantic tags being set. - mDescriptorCluster.Create(endpoint, DescriptorCluster::OptionalAttributesSet(0), Span()); - ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); - - mEndpointRegistration.endpointEntry = DataModel::EndpointEntry{ - .id = endpoint, - .parentId = parentId, - .compositionPattern = DataModel::EndpointCompositionPattern::kFullFamily, - }; - return CHIP_NO_ERROR; -} - CHIP_ERROR BaseDevice::DeviceTypes(ReadOnlyBufferBuilder & out) const { VerifyOrReturnValue(mDescriptorCluster.IsConstructed(), CHIP_NO_ERROR); diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 36afc0f7939c90..8fc813e3f448b4 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -36,8 +36,6 @@ class BaseDevice : public EndpointInterface public: virtual ~BaseDevice() = default; - EndpointId GetEndpointId() const { return mEndpointId; } - /// Register relevant clusters on the given endpoint virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) = 0; @@ -54,11 +52,6 @@ class BaseDevice : public EndpointInterface protected: BaseDevice(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} - /// Internal registration function for common device clusters and endpoint registration. - /// Subclasses are expected to call this - CHIP_ERROR BaseRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); - - EndpointId mEndpointId = kInvalidEndpointId; Span mDeviceTypes; EndpointInterfaceRegistration mEndpointRegistration; diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn index 4735d17bac9e73..b20010ad75996b 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn @@ -22,7 +22,7 @@ source_set("boolean-state-sensor") { ] public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/single-endpoint:single-endpoint-device", "${chip_root}/src/app/clusters/boolean-state-server", "${chip_root}/src/app/clusters/identify-server", "${chip_root}/src/data-model-providers/codedriven", diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp index c6e186b769cfee..81f85db04a130b 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp @@ -23,7 +23,7 @@ namespace chip::app { CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) { - ReturnErrorOnFailure(BaseRegistration(endpoint, provider, parentId)); + ReturnErrorOnFailure(SingleEndpointRegistration(endpoint, provider, parentId)); mIdentifyCluster.Create(IdentifyCluster::Config(endpoint, *mTimerDelegate)); ReturnErrorOnFailure(provider.AddCluster(mIdentifyCluster.Registration())); diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index db7bf51b55192f..faf694716c4f9d 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -19,13 +19,13 @@ #include #include #include -#include +#include #include namespace chip { namespace app { -class BooleanStateSensorDevice : public BaseDevice +class BooleanStateSensorDevice : public SingleEndpointDevice { public: /* @@ -36,7 +36,7 @@ class BooleanStateSensorDevice : public BaseDevice */ BooleanStateSensorDevice(std::unique_ptr timerDelegate, Span deviceType) : - BaseDevice(deviceType), + SingleEndpointDevice(deviceType), mTimerDelegate(std::move(timerDelegate)) {} ~BooleanStateSensorDevice() override = default; diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn index 3bd2220be5f7a7..2022556219a148 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn @@ -22,7 +22,7 @@ source_set("root-node") { ] public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/single-endpoint:single-endpoint-device", "${chip_root}/src/app/clusters/access-control-server", "${chip_root}/src/app/clusters/administrator-commissioning-server", "${chip_root}/src/app/clusters/basic-information", diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index 0de95914df63e1..b0cf50375b3c17 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -32,7 +32,7 @@ namespace app { CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelProvider & provider, EndpointId parentId) { - ReturnErrorOnFailure(BaseRegistration(endpointId, provider, parentId)); + ReturnErrorOnFailure(SingleEndpointRegistration(endpointId, provider, parentId)); mBasicInformationCluster.Create(); diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index 3052cb05a70e53..b5c694c1c558e8 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -28,13 +28,13 @@ #include #include #include -#include +#include #include namespace chip { namespace app { -class RootNodeDevice : public BaseDevice +class RootNodeDevice : public SingleEndpointDevice { public: ~RootNodeDevice() override = default; @@ -45,7 +45,7 @@ class RootNodeDevice : public BaseDevice protected: // Most implementations require network commissioning, so only subclasses have access to this. - RootNodeDevice() : BaseDevice(Span(&Device::Type::kRootNode, 1)) {} + RootNodeDevice() : SingleEndpointDevice(Span(&Device::Type::kRootNode, 1)) {} private: LazyRegisteredServerCluster mBasicInformationCluster; diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn new file mode 100644 index 00000000000000..c989707a0938b6 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2025 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +source_set("single-endpoint-device") { + sources = [ + "SingleEndpointDevice.cpp", + "SingleEndpointDevice.h", + ] + + public_deps = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + "${chip_root}/src/app/clusters/descriptor", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", + ] + + public_configs = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", + "${chip_root}/src:includes", + ] +} diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp new file mode 100644 index 00000000000000..66a4b918a5c865 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +using namespace chip::app::Clusters; + +namespace chip::app { + +CHIP_ERROR SingleEndpointDevice::SingleEndpointRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +{ + VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); + mEndpointId = endpoint; + + // TODO: This needs to be updated to be more customizable and allow the cluster to be created with + // optional attributes or semantic tags being set. + mDescriptorCluster.Create(endpoint, DescriptorCluster::OptionalAttributesSet(0), Span()); + ReturnErrorOnFailure(provider.AddCluster(mDescriptorCluster.Registration())); + + mEndpointRegistration.endpointEntry = DataModel::EndpointEntry{ + .id = endpoint, + .parentId = parentId, + .compositionPattern = DataModel::EndpointCompositionPattern::kFullFamily, + }; + return CHIP_NO_ERROR; +} + +} // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h new file mode 100644 index 00000000000000..9d4fae04c0f134 --- /dev/null +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +namespace chip::app { + +/// A device is a entity that maintains some cluster functionality. +/// +/// Current implementation assumes that a device is registered on a single +/// endpoint. +class SingleEndpointDevice : public BaseDevice +{ +public: + virtual ~SingleEndpointDevice() = default; + + EndpointId GetEndpointId() const { return mEndpointId; } + + /// Register relevant clusters on the given endpoint + virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId = kInvalidEndpointId) = 0; + + /// Remove clusters from the given provider. + /// + /// Will only be called if register has succeeded before + virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; + +protected: + SingleEndpointDevice(Span deviceTypes) : BaseDevice(deviceTypes) {} + + /// Internal registration function for common device clusters and endpoint registration. + /// Subclasses are expected to call this + CHIP_ERROR SingleEndpointRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); + + EndpointId mEndpointId = kInvalidEndpointId; + + // Common clusters.. + LazyRegisteredServerCluster mDescriptorCluster; +}; + +} // namespace chip::app From 5ef1f493ec4eba7f5d440c96818514c1abcc4e59 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 31 Oct 2025 15:30:09 -0400 Subject: [PATCH 27/48] Add comments, fix unregister calls, cleanup of member variables --- .../devices/base-device/Device.h | 12 +++++--- .../BooleanStateSensorDevice.cpp | 2 +- .../BooleanStateSensorDevice.h | 11 ++++--- .../devices/root-node/RootNodeDevice.cpp | 2 +- .../single-endpoint/SingleEndpointDevice.cpp | 9 ++++++ .../single-endpoint/SingleEndpointDevice.h | 29 ++++++++++--------- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 8fc813e3f448b4..b8136711650b79 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -36,13 +36,15 @@ class BaseDevice : public EndpointInterface public: virtual ~BaseDevice() = default; - /// Register relevant clusters on the given endpoint + /// Register relevant clusters on the given endpoint. This must only + /// be called after starting up a device for the first time. This function + /// will create/instantiate all clusters on the device and complete endpoint registration. virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) = 0; - /// Remove clusters from the given provider. - /// - /// Will only be called if register has succeeded before + /// Removes a device's clusters from the given provider. This + /// must only be called when any functionality from the device + /// is no longer needed (for example, on shutown). virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; // Endpoint interface implementation @@ -50,6 +52,8 @@ class BaseDevice : public EndpointInterface CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; protected: + /// The caller creating a BaseDevice MUST ensure that the underlying data for the Span of + /// deviceTypes remains valid for the entire liefetime of the BaseDevice object instance. BaseDevice(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} Span mDeviceTypes; diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp index 81f85db04a130b..1d4d33adaf94af 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.cpp @@ -36,7 +36,7 @@ CHIP_ERROR BooleanStateSensorDevice::Register(chip::EndpointId endpoint, CodeDri void BooleanStateSensorDevice::UnRegister(CodeDrivenDataModelProvider & provider) { - provider.RemoveEndpoint(mEndpointId); + SingleEndpointUnregistration(provider); if (mBooleanStateCluster.IsConstructed()) { provider.RemoveCluster(&mBooleanStateCluster.Cluster()); diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index faf694716c4f9d..3c81ef2463db48 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -28,12 +28,11 @@ namespace app { class BooleanStateSensorDevice : public SingleEndpointDevice { public: - /* - * This is a general class for boolean state sensor devices. The device type passed here will - * determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable - * class for the sensor types that share the same core functionality through the identify and - * boolean state clusters. - */ + /// This is a general class for boolean state sensor devices. The device type passed here will + /// determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable + /// class for the sensor types that share the same core functionality through the identify and + /// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying + /// data for the Span of deviceTypes remains valid for the entire liefetime of the BooleanStateSensorDevice object instance. BooleanStateSensorDevice(std::unique_ptr timerDelegate, Span deviceType) : SingleEndpointDevice(deviceType), diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index b0cf50375b3c17..4b6485dd90d5c3 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -84,7 +84,7 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr void RootNodeDevice::UnRegister(CodeDrivenDataModelProvider & provider) { - provider.RemoveEndpoint(mEndpointId); + SingleEndpointUnregistration(provider); if (mBasicInformationCluster.IsConstructed()) { provider.RemoveCluster(&mBasicInformationCluster.Cluster()); diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp index 66a4b918a5c865..3fccb660993bc2 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp @@ -39,4 +39,13 @@ CHIP_ERROR SingleEndpointDevice::SingleEndpointRegistration(EndpointId endpoint, return CHIP_NO_ERROR; } +void SingleEndpointDevice::SingleEndpointUnregistration(CodeDrivenDataModelProvider & provider) { + provider.RemoveEndpoint(mEndpointId); + if (mDescriptorCluster.IsConstructed()) + { + provider.RemoveCluster(&mDescriptorCluster.Cluster()); + mDescriptorCluster.Destroy(); + } +} + } // namespace chip::app diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h index 9d4fae04c0f134..1b528731094fc1 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h @@ -30,7 +30,7 @@ namespace chip::app { /// A device is a entity that maintains some cluster functionality. /// -/// Current implementation assumes that a device is registered on a single +/// This implementation assumes that a device is registered on a single /// endpoint. class SingleEndpointDevice : public BaseDevice { @@ -39,26 +39,27 @@ class SingleEndpointDevice : public BaseDevice EndpointId GetEndpointId() const { return mEndpointId; } - /// Register relevant clusters on the given endpoint - virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, - EndpointId parentId = kInvalidEndpointId) = 0; - - /// Remove clusters from the given provider. - /// - /// Will only be called if register has succeeded before - virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; - protected: + /// The caller creating a SingleEndpointDevice MUST ensure that the underlying data for the Span of + /// deviceTypes remains valid for the entire liefetime of the SingleEndpointDevice object instance. SingleEndpointDevice(Span deviceTypes) : BaseDevice(deviceTypes) {} /// Internal registration function for common device clusters and endpoint registration. - /// Subclasses are expected to call this + /// Device subclasses are expected to, and must only call this as part of their own device specific Register() + /// functions. This allows creation of common and device-specific clusters to be done together and + /// also to complete endpoint registration. CHIP_ERROR SingleEndpointRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); - EndpointId mEndpointId = kInvalidEndpointId; + /// Internal function to unregister a single endpoint device. This will destroy the clusters part of + /// this class, and must be called in a subclass' device-specific UnRegister() function. This allows + /// for the destruction of the general SingleEndpointDevice clusters and device-specifc clusters from + /// the subclass, as well as removal of the device endpoint from the provider to happen together. + void SingleEndpointUnregistration(CodeDrivenDataModelProvider & provider); - // Common clusters.. - LazyRegisteredServerCluster mDescriptorCluster; + /// A default value of kInvalidEndpointId is used for the endpoint ID. When this is the value of the endpoint ID, + /// it signifies that endpoint registration (and cluster creation) has not yet been completed. The endpoint + /// ID will be set after a call to SingleEndpointRegistration() has been made. + EndpointId mEndpointId = kInvalidEndpointId; }; } // namespace chip::app From 09a94f25afa89ba3d0f9872f1b89edb081f6660f Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 31 Oct 2025 16:07:11 -0400 Subject: [PATCH 28/48] Remove unique pointer for timer --- .../boolean-state-sensor/BooleanStateSensorDevice.h | 6 +++--- .../devices/device-factory/DeviceFactory.h | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index 3c81ef2463db48..f746bd873286e1 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -33,10 +33,10 @@ class BooleanStateSensorDevice : public SingleEndpointDevice /// class for the sensor types that share the same core functionality through the identify and /// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying /// data for the Span of deviceTypes remains valid for the entire liefetime of the BooleanStateSensorDevice object instance. - BooleanStateSensorDevice(std::unique_ptr timerDelegate, + BooleanStateSensorDevice(reporting::ReportScheduler::TimerDelegate * timerDelegate, Span deviceType) : SingleEndpointDevice(deviceType), - mTimerDelegate(std::move(timerDelegate)) + mTimerDelegate(timerDelegate) {} ~BooleanStateSensorDevice() override = default; @@ -47,7 +47,7 @@ class BooleanStateSensorDevice : public SingleEndpointDevice Clusters::BooleanStateCluster & BooleanState() { return mBooleanStateCluster.Cluster(); } private: - std::unique_ptr mTimerDelegate; + reporting::ReportScheduler::TimerDelegate * mTimerDelegate; LazyRegisteredServerCluster mIdentifyCluster; LazyRegisteredServerCluster mBooleanStateCluster; }; diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index b6f83360f4b789..ebf81495c7157f 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -65,16 +65,17 @@ class DeviceFactory private: std::map mRegistry; + DefaultTimerDelegate timer; DeviceFactory() { - mRegistry["contact-sensor"] = []() { + mRegistry["contact-sensor"] = [this]() { return std::make_unique( - std::make_unique(), Span(&Device::Type::kContactSensor, 1)); + &timer, Span(&Device::Type::kContactSensor, 1)); }; - mRegistry["water-leak-detector"] = []() { + mRegistry["water-leak-detector"] = [this]() { return std::make_unique( - std::make_unique(), + &timer, Span(&Device::Type::kWaterLeakDetector, 1)); }; } From 52635269233aaebbf0fe7ee53b631ecd40ff7037 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 31 Oct 2025 20:09:46 +0000 Subject: [PATCH 29/48] Restyled by whitespace --- .../devices/base-device/Device.h | 10 +++++----- .../BooleanStateSensorDevice.h | 2 +- .../devices/single-endpoint/SingleEndpointDevice.h | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index b8136711650b79..36bc7e29edd790 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -37,13 +37,13 @@ class BaseDevice : public EndpointInterface virtual ~BaseDevice() = default; /// Register relevant clusters on the given endpoint. This must only - /// be called after starting up a device for the first time. This function + /// be called after starting up a device for the first time. This function /// will create/instantiate all clusters on the device and complete endpoint registration. virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) = 0; - /// Removes a device's clusters from the given provider. This - /// must only be called when any functionality from the device + /// Removes a device's clusters from the given provider. This + /// must only be called when any functionality from the device /// is no longer needed (for example, on shutown). virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; @@ -52,8 +52,8 @@ class BaseDevice : public EndpointInterface CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; protected: - /// The caller creating a BaseDevice MUST ensure that the underlying data for the Span of - /// deviceTypes remains valid for the entire liefetime of the BaseDevice object instance. + /// The caller creating a BaseDevice MUST ensure that the underlying data for the Span of + /// deviceTypes remains valid for the entire liefetime of the BaseDevice object instance. BaseDevice(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} Span mDeviceTypes; diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index f746bd873286e1..e52d68240b6688 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -31,7 +31,7 @@ class BooleanStateSensorDevice : public SingleEndpointDevice /// This is a general class for boolean state sensor devices. The device type passed here will /// determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable /// class for the sensor types that share the same core functionality through the identify and - /// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying + /// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying /// data for the Span of deviceTypes remains valid for the entire liefetime of the BooleanStateSensorDevice object instance. BooleanStateSensorDevice(reporting::ReportScheduler::TimerDelegate * timerDelegate, Span deviceType) : diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h index 1b528731094fc1..4242c8be229abd 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h @@ -40,25 +40,25 @@ class SingleEndpointDevice : public BaseDevice EndpointId GetEndpointId() const { return mEndpointId; } protected: - /// The caller creating a SingleEndpointDevice MUST ensure that the underlying data for the Span of + /// The caller creating a SingleEndpointDevice MUST ensure that the underlying data for the Span of /// deviceTypes remains valid for the entire liefetime of the SingleEndpointDevice object instance. SingleEndpointDevice(Span deviceTypes) : BaseDevice(deviceTypes) {} /// Internal registration function for common device clusters and endpoint registration. - /// Device subclasses are expected to, and must only call this as part of their own device specific Register() - /// functions. This allows creation of common and device-specific clusters to be done together and + /// Device subclasses are expected to, and must only call this as part of their own device specific Register() + /// functions. This allows creation of common and device-specific clusters to be done together and /// also to complete endpoint registration. CHIP_ERROR SingleEndpointRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId); - /// Internal function to unregister a single endpoint device. This will destroy the clusters part of - /// this class, and must be called in a subclass' device-specific UnRegister() function. This allows - /// for the destruction of the general SingleEndpointDevice clusters and device-specifc clusters from + /// Internal function to unregister a single endpoint device. This will destroy the clusters part of + /// this class, and must be called in a subclass' device-specific UnRegister() function. This allows + /// for the destruction of the general SingleEndpointDevice clusters and device-specifc clusters from /// the subclass, as well as removal of the device endpoint from the provider to happen together. void SingleEndpointUnregistration(CodeDrivenDataModelProvider & provider); /// A default value of kInvalidEndpointId is used for the endpoint ID. When this is the value of the endpoint ID, /// it signifies that endpoint registration (and cluster creation) has not yet been completed. The endpoint - /// ID will be set after a call to SingleEndpointRegistration() has been made. + /// ID will be set after a call to SingleEndpointRegistration() has been made. EndpointId mEndpointId = kInvalidEndpointId; }; From 28da3181a84eac0fb873178d11e9852c67bffc49 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 31 Oct 2025 20:09:53 +0000 Subject: [PATCH 30/48] Restyled by clang-format --- .../devices/device-factory/DeviceFactory.h | 3 +-- .../devices/single-endpoint/SingleEndpointDevice.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index ebf81495c7157f..e9f6127d8979ab 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -75,8 +75,7 @@ class DeviceFactory }; mRegistry["water-leak-detector"] = [this]() { return std::make_unique( - &timer, - Span(&Device::Type::kWaterLeakDetector, 1)); + &timer, Span(&Device::Type::kWaterLeakDetector, 1)); }; } }; diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp index 3fccb660993bc2..02e9c777d7630c 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp @@ -21,7 +21,8 @@ using namespace chip::app::Clusters; namespace chip::app { -CHIP_ERROR SingleEndpointDevice::SingleEndpointRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId) +CHIP_ERROR SingleEndpointDevice::SingleEndpointRegistration(EndpointId endpoint, CodeDrivenDataModelProvider & provider, + EndpointId parentId) { VerifyOrReturnError(mEndpointId == kInvalidEndpointId, CHIP_ERROR_INCORRECT_STATE); mEndpointId = endpoint; @@ -39,7 +40,8 @@ CHIP_ERROR SingleEndpointDevice::SingleEndpointRegistration(EndpointId endpoint, return CHIP_NO_ERROR; } -void SingleEndpointDevice::SingleEndpointUnregistration(CodeDrivenDataModelProvider & provider) { +void SingleEndpointDevice::SingleEndpointUnregistration(CodeDrivenDataModelProvider & provider) +{ provider.RemoveEndpoint(mEndpointId); if (mDescriptorCluster.IsConstructed()) { From 1eee251e2a7e4a70c656842d146d84786fbbe0fc Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Fri, 31 Oct 2025 20:53:33 +0000 Subject: [PATCH 31/48] update comment --- .../all-devices-common/devices/base-device/Device.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 36bc7e29edd790..98b978c7a23d9e 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -43,8 +43,9 @@ class BaseDevice : public EndpointInterface EndpointId parentId = kInvalidEndpointId) = 0; /// Removes a device's clusters from the given provider. This - /// must only be called when any functionality from the device - /// is no longer needed (for example, on shutown). + /// must only be called when register has succeeded before. Expected + /// usage of this function is for when the device is no longer needed + /// (for example, on shutown), to destory the device's clusters. virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; // Endpoint interface implementation From ac626693353ab09fd9b46d0dff5e3c6f65f300a0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 31 Oct 2025 20:55:00 +0000 Subject: [PATCH 32/48] Restyled by whitespace --- .../all-devices-common/devices/base-device/Device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h index 98b978c7a23d9e..b21c3bca1f4770 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/base-device/Device.h @@ -44,7 +44,7 @@ class BaseDevice : public EndpointInterface /// Removes a device's clusters from the given provider. This /// must only be called when register has succeeded before. Expected - /// usage of this function is for when the device is no longer needed + /// usage of this function is for when the device is no longer needed /// (for example, on shutown), to destory the device's clusters. virtual void UnRegister(CodeDrivenDataModelProvider & provider) = 0; From e1d7e9c64176536b9deb7d56835ad9970e6beaba Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Mon, 3 Nov 2025 10:43:52 -0500 Subject: [PATCH 33/48] Restructure device interfaces --- .../devices/base-device/BUILD.gn | 35 ------------------- .../devices/boolean-state-sensor/BUILD.gn | 2 +- .../BooleanStateSensorDevice.h | 2 +- .../devices/device-factory/DeviceFactory.h | 4 +-- .../{single-endpoint => interface}/BUILD.gn | 21 ++++++++++- .../DeviceInterface.cpp} | 6 ++-- .../Device.h => interface/DeviceInterface.h} | 15 ++++---- .../SingleEndpointDevice.cpp | 2 +- .../SingleEndpointDevice.h | 6 ++-- .../devices/root-node/BUILD.gn | 2 +- .../devices/root-node/RootNodeDevice.h | 2 +- examples/all-devices-app/linux/main.cpp | 2 +- 12 files changed, 40 insertions(+), 59 deletions(-) delete mode 100644 examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn rename examples/all-devices-app/all-devices-common/devices/{single-endpoint => interface}/BUILD.gn (74%) rename examples/all-devices-app/all-devices-common/devices/{base-device/Device.cpp => interface/DeviceInterface.cpp} (79%) rename examples/all-devices-app/all-devices-common/devices/{base-device/Device.h => interface/DeviceInterface.h} (82%) rename examples/all-devices-app/all-devices-common/devices/{single-endpoint => interface}/SingleEndpointDevice.cpp (97%) rename examples/all-devices-app/all-devices-common/devices/{single-endpoint => interface}/SingleEndpointDevice.h (95%) diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn deleted file mode 100644 index 6f1b4ae9f08b9f..00000000000000 --- a/examples/all-devices-app/all-devices-common/devices/base-device/BUILD.gn +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2025 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") - -source_set("base-device") { - sources = [ - "Device.cpp", - "Device.h", - ] - - public_deps = [ - "${chip_root}/src/app/clusters/descriptor", - "${chip_root}/src/data-model-providers/codedriven", - "${chip_root}/src/lib/core:error", - "${chip_root}/src/lib/support", - ] - - public_configs = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", - "${chip_root}/src:includes", - ] -} diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn index b20010ad75996b..43fcc6ccfcaa23 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BUILD.gn @@ -22,7 +22,7 @@ source_set("boolean-state-sensor") { ] public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/single-endpoint:single-endpoint-device", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/interface:single-endpoint-device", "${chip_root}/src/app/clusters/boolean-state-server", "${chip_root}/src/app/clusters/identify-server", "${chip_root}/src/data-model-providers/codedriven", diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index e52d68240b6688..bf4586fb8ca375 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include namespace chip { diff --git a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h index e9f6127d8979ab..a618c1bfd9986e 100644 --- a/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h +++ b/examples/all-devices-app/all-devices-common/devices/device-factory/DeviceFactory.h @@ -37,7 +37,7 @@ namespace chip::app { class DeviceFactory { public: - using DeviceCreator = std::function()>; + using DeviceCreator = std::function()>; static DeviceFactory & GetInstance() { @@ -47,7 +47,7 @@ class DeviceFactory bool IsValidDevice(const std::string & deviceTypeArg) { return mRegistry.find(deviceTypeArg) != mRegistry.end(); } - std::unique_ptr Create(const std::string & deviceTypeArg) + std::unique_ptr Create(const std::string & deviceTypeArg) { if (IsValidDevice(deviceTypeArg)) { diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/interface/BUILD.gn similarity index 74% rename from examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn rename to examples/all-devices-app/all-devices-common/devices/interface/BUILD.gn index c989707a0938b6..21ae3792493ec3 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/interface/BUILD.gn @@ -15,6 +15,25 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +source_set("device-interface") { + sources = [ + "DeviceInterface.cpp", + "DeviceInterface.h", + ] + + public_deps = [ + "${chip_root}/src/app/clusters/descriptor", + "${chip_root}/src/data-model-providers/codedriven", + "${chip_root}/src/lib/core:error", + "${chip_root}/src/lib/support", + ] + + public_configs = [ + "${chip_root}/examples/all-devices-app/all-devices-common/devices/:includes", + "${chip_root}/src:includes", + ] +} + source_set("single-endpoint-device") { sources = [ "SingleEndpointDevice.cpp", @@ -22,7 +41,7 @@ source_set("single-endpoint-device") { ] public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/base-device", + ":device-interface", "${chip_root}/src/app/clusters/descriptor", "${chip_root}/src/data-model-providers/codedriven", "${chip_root}/src/lib/core:error", diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.cpp similarity index 79% rename from examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp rename to examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.cpp index c1067d03ef2029..c4336eba48ebd2 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.cpp +++ b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.cpp @@ -15,13 +15,13 @@ * limitations under the License. */ -#include +#include using namespace chip::app::Clusters; namespace chip::app { -CHIP_ERROR BaseDevice::DeviceTypes(ReadOnlyBufferBuilder & out) const +CHIP_ERROR DeviceInterface::DeviceTypes(ReadOnlyBufferBuilder & out) const { VerifyOrReturnValue(mDescriptorCluster.IsConstructed(), CHIP_NO_ERROR); ReturnErrorOnFailure(out.ReferenceExisting(mDeviceTypes)); @@ -29,7 +29,7 @@ CHIP_ERROR BaseDevice::DeviceTypes(ReadOnlyBufferBuilder & out) const +CHIP_ERROR DeviceInterface::ClientClusters(ReadOnlyBufferBuilder & out) const { // no bindings return CHIP_NO_ERROR; diff --git a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h similarity index 82% rename from examples/all-devices-app/all-devices-common/devices/base-device/Device.h rename to examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h index b21c3bca1f4770..50340d0191361f 100644 --- a/examples/all-devices-app/all-devices-common/devices/base-device/Device.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h @@ -27,14 +27,11 @@ namespace chip::app { -/// A device is a entity that maintains some cluster functionality. -/// -/// Current implementation assumes that a device is registered on a single -/// endpoint. -class BaseDevice : public EndpointInterface +/// A device is an entity that maintains some cluster functionality. +class DeviceInterface : public EndpointInterface { public: - virtual ~BaseDevice() = default; + virtual ~DeviceInterface() = default; /// Register relevant clusters on the given endpoint. This must only /// be called after starting up a device for the first time. This function @@ -53,9 +50,9 @@ class BaseDevice : public EndpointInterface CHIP_ERROR ClientClusters(ReadOnlyBufferBuilder & out) const override; protected: - /// The caller creating a BaseDevice MUST ensure that the underlying data for the Span of - /// deviceTypes remains valid for the entire liefetime of the BaseDevice object instance. - BaseDevice(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} + /// The caller creating a DeviceInterface MUST ensure that the underlying data for the Span of + /// deviceTypes remains valid for the entire liefetime of the DeviceInterface object instance. + DeviceInterface(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} Span mDeviceTypes; EndpointInterfaceRegistration mEndpointRegistration; diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp b/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.cpp similarity index 97% rename from examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp rename to examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.cpp index 02e9c777d7630c..380bc06eae1ebb 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include +#include using namespace chip::app::Clusters; diff --git a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h b/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h similarity index 95% rename from examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h rename to examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h index 4242c8be229abd..c019d103a5083f 100644 --- a/examples/all-devices-app/all-devices-common/devices/single-endpoint/SingleEndpointDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include @@ -32,7 +32,7 @@ namespace chip::app { /// /// This implementation assumes that a device is registered on a single /// endpoint. -class SingleEndpointDevice : public BaseDevice +class SingleEndpointDevice : public DeviceInterface { public: virtual ~SingleEndpointDevice() = default; @@ -42,7 +42,7 @@ class SingleEndpointDevice : public BaseDevice protected: /// The caller creating a SingleEndpointDevice MUST ensure that the underlying data for the Span of /// deviceTypes remains valid for the entire liefetime of the SingleEndpointDevice object instance. - SingleEndpointDevice(Span deviceTypes) : BaseDevice(deviceTypes) {} + SingleEndpointDevice(Span deviceTypes) : DeviceInterface(deviceTypes) {} /// Internal registration function for common device clusters and endpoint registration. /// Device subclasses are expected to, and must only call this as part of their own device specific Register() diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn index 2022556219a148..d7976d47c3fba8 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn +++ b/examples/all-devices-app/all-devices-common/devices/root-node/BUILD.gn @@ -22,7 +22,7 @@ source_set("root-node") { ] public_deps = [ - "${chip_root}/examples/all-devices-app/all-devices-common/devices/single-endpoint:single-endpoint-device", + "${chip_root}/examples/all-devices-app/all-devices-common/devices/interface:single-endpoint-device", "${chip_root}/src/app/clusters/access-control-server", "${chip_root}/src/app/clusters/administrator-commissioning-server", "${chip_root}/src/app/clusters/basic-information", diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h index b5c694c1c558e8..ae3aece1c56cf5 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include namespace chip { diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 3d5f88597d9c98..7bbb0d2d89103f 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -71,7 +71,7 @@ chip::app::DataModel::Provider * PopulateCodeDrivenDataModelProvider(PersistentS chip::app::CodeDrivenDataModelProvider(*delegate, attributePersistenceProvider); static WifiRootNodeDevice rootNodeDevice(&sWiFiDriver); - static std::unique_ptr constructedDevice; + static std::unique_ptr constructedDevice; rootNodeDevice.Register(kRootEndpointId, dataModelProvider, kInvalidEndpointId); constructedDevice = DeviceFactory::GetInstance().Create(AppOptions::GetDeviceType()); From b01538552349cbed144ab9ca74cd9db041ea950a Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Mon, 3 Nov 2025 14:51:59 -0500 Subject: [PATCH 34/48] Add all devices app build and basic composition test to CI --- .github/workflows/tests.yaml | 10 ++++++++++ .../devices/root-node/RootNodeDevice.cpp | 3 +-- src/python_testing/TC_DeviceBasicComposition.py | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index cbbed03ad5c417..82f47df7199ac0 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -665,6 +665,15 @@ jobs: && rm -rf out/linux-x64-all-clusters-${BUILD_VARIANT}-tsan-clang-test " + - name: Build linux-x64-all-devices-app + env: + CCACHE_DIR: "${{ github.workspace }}/.ccache" + run: >- + ./scripts/run_in_build_env.sh "./scripts/build/build_examples.py + --target linux-x64-all-devices-app-${BUILD_VARIANT}-tsan-clang-test + --pw-command-launcher=ccache build --copy-artifacts-to objdir-clone + && rm -rf out/linux-x64-all-devices-app-${BUILD_VARIANT}-tsan-clang-test" + - name: Build linux-x64-lit-icd env: CCACHE_DIR: "${{ github.workspace }}/.ccache" @@ -806,6 +815,7 @@ jobs: run: | echo -n "" >/tmp/test_env.yaml echo "ALL_CLUSTERS_APP: objdir-clone/linux-x64-all-clusters-${BUILD_VARIANT}-tsan-clang-test/chip-all-clusters-app" >> /tmp/test_env.yaml + echo "ALL_DEVICES_APP: objdir-clone/linux-x64-all-devices-app-${BUILD_VARIANT}-tsan-clang-test/chip-all-devices-app" >> /tmp/test_env.yaml echo "BRIDGE_APP: objdir-clone/linux-x64-bridge-${BUILD_VARIANT}-tsan-clang-test-unified/chip-bridge-app" >> /tmp/test_env.yaml echo "CHIP_LOCK_APP: objdir-clone/linux-x64-lock-${BUILD_VARIANT}-tsan-clang-test-unified/chip-lock-app" >> /tmp/test_env.yaml echo "CAMERA_APP: objdir-clone/linux-x64-camera/chip-camera-app" >> /tmp/test_env.yaml diff --git a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp index 4b6485dd90d5c3..8b3a3cd0b422c3 100644 --- a/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp +++ b/examples/all-devices-app/all-devices-common/devices/root-node/RootNodeDevice.cpp @@ -46,8 +46,7 @@ CHIP_ERROR RootNodeDevice::Register(EndpointId endpointId, CodeDrivenDataModelPr .Set() .Set() .Set() - .Set() - .Set(); + .Set(); ReturnErrorOnFailure(provider.AddCluster(mBasicInformationCluster.Registration())); diff --git a/src/python_testing/TC_DeviceBasicComposition.py b/src/python_testing/TC_DeviceBasicComposition.py index 0742887c6fee25..62fd693ad80b87 100644 --- a/src/python_testing/TC_DeviceBasicComposition.py +++ b/src/python_testing/TC_DeviceBasicComposition.py @@ -156,6 +156,17 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: true # quiet: true +# run16: +# app: ${ALL_DEVICES_APP} +# app-args: --discriminator 1234 --KVS kvs1 +# script-args: > +# --storage-path admin_storage.json +# --manual-code 10054912339 +# --PICS src/app/tests/suites/certification/ci-pics-values +# --trace-to json:${TRACE_TEST_JSON}.json +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# factory-reset: true +# quiet: true # === END CI TEST ARGUMENTS === # Run 1: runs through all tests @@ -173,6 +184,7 @@ # Run 13: Tests against chip-rvc app # Run 14: Tests against network-management-app # Run 15: Tests against lighting-app-data-mode-no-unique-id +# Run 16: Tests against all-devices-app import logging from dataclasses import dataclass From 9afcb3be91d4213882aa26305d409eeeab4b802c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 3 Nov 2025 20:00:01 +0000 Subject: [PATCH 35/48] Restyled by clang-format --- .../all-devices-common/devices/interface/DeviceInterface.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h index 50340d0191361f..9118d737972a0d 100644 --- a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h @@ -52,7 +52,9 @@ class DeviceInterface : public EndpointInterface protected: /// The caller creating a DeviceInterface MUST ensure that the underlying data for the Span of /// deviceTypes remains valid for the entire liefetime of the DeviceInterface object instance. - DeviceInterface(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} + DeviceInterface(Span deviceTypes) : + mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) + {} Span mDeviceTypes; EndpointInterfaceRegistration mEndpointRegistration; From 87e732fe550cd079f97a1f0098f30ee6e4ff3c98 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Mon, 3 Nov 2025 16:39:40 -0500 Subject: [PATCH 36/48] Remove build variants for CI, not currently supported --- .github/workflows/tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 82f47df7199ac0..602b58a3a1a41a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -670,9 +670,9 @@ jobs: CCACHE_DIR: "${{ github.workspace }}/.ccache" run: >- ./scripts/run_in_build_env.sh "./scripts/build/build_examples.py - --target linux-x64-all-devices-app-${BUILD_VARIANT}-tsan-clang-test + --target linux-x64-all-devices-app-tsan-clang-test --pw-command-launcher=ccache build --copy-artifacts-to objdir-clone - && rm -rf out/linux-x64-all-devices-app-${BUILD_VARIANT}-tsan-clang-test" + && rm -rf out/linux-x64-all-devices-app-tsan-clang-test" - name: Build linux-x64-lit-icd env: From 0256f6917273bff94d73d2ec17afb490998d1ea7 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Tue, 4 Nov 2025 09:23:55 -0500 Subject: [PATCH 37/48] Fix path for all devices app in CI --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 602b58a3a1a41a..37890df35df53e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -815,7 +815,7 @@ jobs: run: | echo -n "" >/tmp/test_env.yaml echo "ALL_CLUSTERS_APP: objdir-clone/linux-x64-all-clusters-${BUILD_VARIANT}-tsan-clang-test/chip-all-clusters-app" >> /tmp/test_env.yaml - echo "ALL_DEVICES_APP: objdir-clone/linux-x64-all-devices-app-${BUILD_VARIANT}-tsan-clang-test/chip-all-devices-app" >> /tmp/test_env.yaml + echo "ALL_DEVICES_APP: objdir-clone/linux-x64-all-devices-app-tsan-clang-test/all-devices-app" >> /tmp/test_env.yaml echo "BRIDGE_APP: objdir-clone/linux-x64-bridge-${BUILD_VARIANT}-tsan-clang-test-unified/chip-bridge-app" >> /tmp/test_env.yaml echo "CHIP_LOCK_APP: objdir-clone/linux-x64-lock-${BUILD_VARIANT}-tsan-clang-test-unified/chip-lock-app" >> /tmp/test_env.yaml echo "CAMERA_APP: objdir-clone/linux-x64-camera/chip-camera-app" >> /tmp/test_env.yaml From 3521dc06a748a8341b858da790bd4a7bc4e6bbe4 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Tue, 4 Nov 2025 10:10:31 -0500 Subject: [PATCH 38/48] Update device info provider used --- examples/all-devices-app/linux/BUILD.gn | 2 +- examples/all-devices-app/linux/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index a987edf00783ab..74ff033f83960d 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -38,7 +38,7 @@ executable("all-devices-app") { "${chip_root}/examples/common/tracing:commandline", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/examples/platform/linux:linux-commissionable-data-provider", - "${chip_root}/examples/providers:device_info_provider_please_do_not_reuse_as_is", + "${chip_root}/examples/providers:all_clusters_device_info_provider", "${chip_root}/src/app/persistence", "${chip_root}/src/app/persistence:default", "${chip_root}/src/data-model-providers/codedriven", diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 7bbb0d2d89103f..1ce6927194bda6 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ AppMainLoopImplementation * gMainLoopImplementation = nullptr; DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sWiFiDriver; -DeviceInfoProviderImpl gExampleDeviceInfoProvider; +AllClustersExampleDeviceInfoProviderImpl gExampleDeviceInfoProvider; // To hold SPAKE2+ verifier, discriminator, passcode LinuxCommissionableDataProvider gCommissionableDataProvider; From 00f9a30a90192ceda1bc1cb50c341fa1a33fb444 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Tue, 4 Nov 2025 10:34:31 -0500 Subject: [PATCH 39/48] Update comments --- .../all-devices-common/devices/interface/DeviceInterface.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h index 9118d737972a0d..e4829803223eeb 100644 --- a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h @@ -34,8 +34,10 @@ class DeviceInterface : public EndpointInterface virtual ~DeviceInterface() = default; /// Register relevant clusters on the given endpoint. This must only - /// be called after starting up a device for the first time. This function + /// be called once after starting up a device for the first time. This function /// will create/instantiate all clusters on the device and complete endpoint registration. + /// It should return error if there's any failure when adding the device's clusters to the provider. + /// A parentId of kInvalidEndpointId represents that there is no parent to this device virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) = 0; From a589afb7c07d32121f77cd5097f31f4ff9860cd0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 4 Nov 2025 15:35:35 +0000 Subject: [PATCH 40/48] Restyled by whitespace --- .../all-devices-common/devices/interface/DeviceInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h index e4829803223eeb..78702d34967d68 100644 --- a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h @@ -37,7 +37,7 @@ class DeviceInterface : public EndpointInterface /// be called once after starting up a device for the first time. This function /// will create/instantiate all clusters on the device and complete endpoint registration. /// It should return error if there's any failure when adding the device's clusters to the provider. - /// A parentId of kInvalidEndpointId represents that there is no parent to this device + /// A parentId of kInvalidEndpointId represents that there is no parent to this device virtual CHIP_ERROR Register(EndpointId endpoint, CodeDrivenDataModelProvider & provider, EndpointId parentId = kInvalidEndpointId) = 0; From c6210d53cdfceae06667e120fc6598209e0fe258 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 4 Nov 2025 15:35:39 +0000 Subject: [PATCH 41/48] Restyled by clang-format --- examples/all-devices-app/linux/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index 1ce6927194bda6..d298998beb7315 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -16,8 +16,8 @@ * limitations under the License. */ -#include #include +#include #include #include #include From f93e4e0f97dff56e68b08371d61294059bdaa7a4 Mon Sep 17 00:00:00 2001 From: Zaid Omer Date: Tue, 4 Nov 2025 11:22:37 -0500 Subject: [PATCH 42/48] Add new device info provider --- examples/all-devices-app/linux/BUILD.gn | 2 +- examples/all-devices-app/linux/main.cpp | 4 +- ...llDevicesExampleDeviceInfoProviderImpl.cpp | 66 +++++++++++++++++++ .../AllDevicesExampleDeviceInfoProviderImpl.h | 55 ++++++++++++++++ examples/providers/BUILD.gn | 18 +++++ 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp create mode 100644 examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h diff --git a/examples/all-devices-app/linux/BUILD.gn b/examples/all-devices-app/linux/BUILD.gn index 74ff033f83960d..e73e3b9ab4fc1d 100644 --- a/examples/all-devices-app/linux/BUILD.gn +++ b/examples/all-devices-app/linux/BUILD.gn @@ -38,7 +38,7 @@ executable("all-devices-app") { "${chip_root}/examples/common/tracing:commandline", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/examples/platform/linux:linux-commissionable-data-provider", - "${chip_root}/examples/providers:all_clusters_device_info_provider", + "${chip_root}/examples/providers:all_devices_device_info_provider", "${chip_root}/src/app/persistence", "${chip_root}/src/app/persistence:default", "${chip_root}/src/data-model-providers/codedriven", diff --git a/examples/all-devices-app/linux/main.cpp b/examples/all-devices-app/linux/main.cpp index d298998beb7315..936fddf88f6b8a 100644 --- a/examples/all-devices-app/linux/main.cpp +++ b/examples/all-devices-app/linux/main.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -46,7 +46,7 @@ AppMainLoopImplementation * gMainLoopImplementation = nullptr; DeviceLayer::NetworkCommissioning::LinuxWiFiDriver sWiFiDriver; -AllClustersExampleDeviceInfoProviderImpl gExampleDeviceInfoProvider; +AllDevicesExampleDeviceInfoProviderImpl gExampleDeviceInfoProvider; // To hold SPAKE2+ verifier, discriminator, passcode LinuxCommissionableDataProvider gCommissionableDataProvider; diff --git a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp new file mode 100644 index 00000000000000..00b270a4ecfff0 --- /dev/null +++ b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp @@ -0,0 +1,66 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include +#include +#include +#include + +#include +#include + +#include + + +namespace chip { +namespace DeviceLayer { + +AllDevicesExampleDeviceInfoProviderImpl & AllDevicesExampleDeviceInfoProviderImpl::GetDefaultInstance() +{ + static AllDevicesExampleDeviceInfoProviderImpl sInstance; + return sInstance; +} + +DeviceInfoProvider::SupportedLocalesIterator * AllDevicesExampleDeviceInfoProviderImpl::IterateSupportedLocales() +{ + return chip::Platform::New(); +} + +size_t AllDevicesExampleDeviceInfoProviderImpl::AllDevicesSupportedLocalesIteratorImpl::Count() +{ + // Hardcoded list of locales + // {("en-US") + + return kNumSupportedLocales; +} + +bool AllDevicesExampleDeviceInfoProviderImpl::AllDevicesSupportedLocalesIteratorImpl::Next(CharSpan & output) +{ + // Hardcoded list of locales + static const char * kAllSupportedLocales[kNumSupportedLocales] = { "en-US" }; + + VerifyOrReturnError(mIndex < kNumSupportedLocales, false); + output = CharSpan::fromCharString(kAllSupportedLocales[mIndex]); + mIndex++; + + return true; +} + + +} +} diff --git a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h new file mode 100644 index 00000000000000..f67a6cb3edecd9 --- /dev/null +++ b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h @@ -0,0 +1,55 @@ +/* + * + * Copyright (c) 2025 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +class AllDevicesExampleDeviceInfoProviderImpl : public AllClustersExampleDeviceInfoProviderImpl +{ +public: + AllDevicesExampleDeviceInfoProviderImpl() = default; + ~AllDevicesExampleDeviceInfoProviderImpl() override {} + + //Iterators + SupportedLocalesIterator * IterateSupportedLocales() override; + + static AllDevicesExampleDeviceInfoProviderImpl & GetDefaultInstance(); + +protected: + class AllDevicesSupportedLocalesIteratorImpl : public SupportedLocalesIterator + { + public: + AllDevicesSupportedLocalesIteratorImpl() = default; + size_t Count() override; + bool Next(CharSpan & output) override; + void Release() override { chip::Platform::Delete(this); } + + private: + static constexpr size_t kNumSupportedLocales = 1; + size_t mIndex = 0; + }; + +}; + +} +} diff --git a/examples/providers/BUILD.gn b/examples/providers/BUILD.gn index 1713432170495b..25714fadc82ec3 100644 --- a/examples/providers/BUILD.gn +++ b/examples/providers/BUILD.gn @@ -52,3 +52,21 @@ static_library("all_clusters_device_info_provider") { public_configs = [ ":include_providers_dir" ] } + +static_library("all_devices_device_info_provider") { + output_name = "libMatterAllDevicesDeviceInfoProviderExample" + output_dir = "${root_out_dir}/lib" + + sources = [ + "AllDevicesExampleDeviceInfoProviderImpl.cpp", + "AllDevicesExampleDeviceInfoProviderImpl.h", + ] + + public_deps = [ + ":all_clusters_device_info_provider", + "${chip_root}/src/lib/support", + "${chip_root}/src/platform", + ] + + public_configs = [ ":include_providers_dir" ] +} From 3c9ba8fd3d93aaad2493495935e42cf1e6aa07ab Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 4 Nov 2025 16:27:43 +0000 Subject: [PATCH 43/48] Restyled by whitespace --- examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h index f67a6cb3edecd9..e6bd8ef22c18b7 100644 --- a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h +++ b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h @@ -24,7 +24,7 @@ namespace chip { namespace DeviceLayer { -class AllDevicesExampleDeviceInfoProviderImpl : public AllClustersExampleDeviceInfoProviderImpl +class AllDevicesExampleDeviceInfoProviderImpl : public AllClustersExampleDeviceInfoProviderImpl { public: AllDevicesExampleDeviceInfoProviderImpl() = default; From 8f52e9fe93ed03b971a65b680c79e069546318cf Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 4 Nov 2025 16:27:48 +0000 Subject: [PATCH 44/48] Restyled by clang-format --- .../AllDevicesExampleDeviceInfoProviderImpl.cpp | 6 ++---- .../providers/AllDevicesExampleDeviceInfoProviderImpl.h | 9 ++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp index 00b270a4ecfff0..3d6cae6f44a058 100644 --- a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp +++ b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp @@ -26,7 +26,6 @@ #include - namespace chip { namespace DeviceLayer { @@ -61,6 +60,5 @@ bool AllDevicesExampleDeviceInfoProviderImpl::AllDevicesSupportedLocalesIterator return true; } - -} -} +} // namespace DeviceLayer +} // namespace chip diff --git a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h index e6bd8ef22c18b7..355750ff25b6b5 100644 --- a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h +++ b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.h @@ -16,10 +16,10 @@ */ #pragma once +#include #include #include #include -#include namespace chip { namespace DeviceLayer { @@ -30,7 +30,7 @@ class AllDevicesExampleDeviceInfoProviderImpl : public AllClustersExampleDeviceI AllDevicesExampleDeviceInfoProviderImpl() = default; ~AllDevicesExampleDeviceInfoProviderImpl() override {} - //Iterators + // Iterators SupportedLocalesIterator * IterateSupportedLocales() override; static AllDevicesExampleDeviceInfoProviderImpl & GetDefaultInstance(); @@ -48,8 +48,7 @@ class AllDevicesExampleDeviceInfoProviderImpl : public AllClustersExampleDeviceI static constexpr size_t kNumSupportedLocales = 1; size_t mIndex = 0; }; - }; -} -} +} // namespace DeviceLayer +} // namespace chip From bfa4f89f4e2e88338048d1c6b9c83a89e04caf46 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 6 Nov 2025 12:51:51 -0500 Subject: [PATCH 45/48] Update examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp index 3d6cae6f44a058..ddaeead8cc180a 100644 --- a/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp +++ b/examples/providers/AllDevicesExampleDeviceInfoProviderImpl.cpp @@ -43,7 +43,7 @@ DeviceInfoProvider::SupportedLocalesIterator * AllDevicesExampleDeviceInfoProvid size_t AllDevicesExampleDeviceInfoProviderImpl::AllDevicesSupportedLocalesIteratorImpl::Count() { // Hardcoded list of locales - // {("en-US") + // {("en-US")} return kNumSupportedLocales; } From af50f136a7315208eca03ba0fc4a1ca808057afc Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 6 Nov 2025 12:52:05 -0500 Subject: [PATCH 46/48] Update examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../devices/boolean-state-sensor/BooleanStateSensorDevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h index bf4586fb8ca375..fad59b0d328395 100644 --- a/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/boolean-state-sensor/BooleanStateSensorDevice.h @@ -32,7 +32,7 @@ class BooleanStateSensorDevice : public SingleEndpointDevice /// determine the type of sensor it is (contact, water leak, etc.) This is meant to be a reusable /// class for the sensor types that share the same core functionality through the identify and /// boolean state clusters. The caller creating a BooleanStateSensorDevice MUST ensure that the underlying - /// data for the Span of deviceTypes remains valid for the entire liefetime of the BooleanStateSensorDevice object instance. + /// data for the Span of deviceTypes remains valid for the entire lifetime of the BooleanStateSensorDevice object instance. BooleanStateSensorDevice(reporting::ReportScheduler::TimerDelegate * timerDelegate, Span deviceType) : SingleEndpointDevice(deviceType), From d1c1b5c249e64809a16509c1a1d3f50893383726 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 6 Nov 2025 12:52:19 -0500 Subject: [PATCH 47/48] Update examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../all-devices-common/devices/interface/DeviceInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h index 78702d34967d68..2a3f669213c904 100644 --- a/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/DeviceInterface.h @@ -53,7 +53,7 @@ class DeviceInterface : public EndpointInterface protected: /// The caller creating a DeviceInterface MUST ensure that the underlying data for the Span of - /// deviceTypes remains valid for the entire liefetime of the DeviceInterface object instance. + /// deviceTypes remains valid for the entire lifetime of the DeviceInterface object instance. DeviceInterface(Span deviceTypes) : mDeviceTypes(deviceTypes), mEndpointRegistration(*this, {}) {} From d557cba7a349fcda538d4d69f3257d6b9a97c684 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 6 Nov 2025 12:52:30 -0500 Subject: [PATCH 48/48] Update examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../all-devices-common/devices/interface/SingleEndpointDevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h b/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h index c019d103a5083f..b25ebc7d38a10c 100644 --- a/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h +++ b/examples/all-devices-app/all-devices-common/devices/interface/SingleEndpointDevice.h @@ -41,7 +41,7 @@ class SingleEndpointDevice : public DeviceInterface protected: /// The caller creating a SingleEndpointDevice MUST ensure that the underlying data for the Span of - /// deviceTypes remains valid for the entire liefetime of the SingleEndpointDevice object instance. + /// deviceTypes remains valid for the entire lifetime of the SingleEndpointDevice object instance. SingleEndpointDevice(Span deviceTypes) : DeviceInterface(deviceTypes) {} /// Internal registration function for common device clusters and endpoint registration.