diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index f76663cc195675..38e534093d1599 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -18,6 +18,7 @@ import("${chip_root}/src/platform/device.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("common_flags.gni") +import("icd/icd.gni") declare_args() { # Enable strict schema checks. @@ -210,6 +211,10 @@ static_library("app") { "${nlio_root}:nlio", ] + if (chip_enable_icd_server) { + public_deps += [ "${chip_root}/src/app/icd:server-srcs" ] + } + cflags = [ "-Wconversion" ] public_configs = [ "${chip_root}/src:includes" ] diff --git a/src/app/icd/BUILD.gn b/src/app/icd/BUILD.gn new file mode 100644 index 00000000000000..63157175f12e7b --- /dev/null +++ b/src/app/icd/BUILD.gn @@ -0,0 +1,53 @@ +# 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("icd.gni") + +# ICD Server sources and configurations + +# ICD Manager source-set is broken out of the main source-set to enable unit tests +# All sources and configurations used by the ICDManager need to go in this source-set +source_set("manager-srcs") { + sources = [ + "ICDManager.cpp", + "ICDManager.h", + ] + + public_deps = [ "${chip_root}/src/lib/core" ] +} + +# ICD Server Configuration +# All configurations necessary to the ICD Server featureset need to in this configuration +config("server-config") { + defines = [ "CHIP_CONFIG_ENABLE_ICD_SERVER" ] +} + +# servers-srcs source-set contains all the sources and configurations necessary to build the ICD Server functionality +# All sources, configurations and dependencies necessary for the ICD Server featureset need to go in this source-set +# +# The ICD Server featureset is enabled with the chip_enable_icd_server in the src/app/BUILD.gn file +source_set("server-srcs") { + sources = [ + "ICDEventManager.cpp", + "ICDEventManager.h", + ] + + public_deps = [ + ":manager-srcs", + "${chip_root}/src/platform:platform", + ] + + public_configs = [ ":server-config" ] +} diff --git a/src/app/icd/ICDEventManager.cpp b/src/app/icd/ICDEventManager.cpp new file mode 100644 index 00000000000000..827276b81ebcfb --- /dev/null +++ b/src/app/icd/ICDEventManager.cpp @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2023 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::DeviceLayer; + +namespace chip { +namespace app { + +CHIP_ERROR ICDEventManager::Init(ICDManager * icdManager) +{ + VerifyOrReturnError(icdManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + mICDManager = icdManager; + + PlatformMgr().AddEventHandler(ICDEventHandler, reinterpret_cast(nullptr)); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR ICDEventManager::Shutdown() +{ + PlatformMgr().RemoveEventHandler(ICDEventHandler, reinterpret_cast(nullptr)); + mICDManager = nullptr; + + return CHIP_NO_ERROR; +} + +void ICDEventManager::ICDEventHandler(const ChipDeviceEvent * event, intptr_t arg) +{ + // TODO +} + +} // namespace app +} // namespace chip diff --git a/src/app/icd/ICDEventManager.h b/src/app/icd/ICDEventManager.h new file mode 100644 index 00000000000000..c6a305d24d57a9 --- /dev/null +++ b/src/app/icd/ICDEventManager.h @@ -0,0 +1,55 @@ +/* + * + * Copyright (c) 2023 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 { + +/** + * @brief ICDEventManager class is responsible of processing Platform Events that affect an ICD's behaviour + * The class registers an Event Handler with the Platform Manager and dispatches the processing to the ICDManager class. + */ +class ICDEventManager +{ + +public: + ICDEventManager() = default; + + /** + * @brief Initialisation function of the ICDEventManager. + * Init function MUST be called before using the object + */ + CHIP_ERROR Init(ICDManager * icdManager); + CHIP_ERROR Shutdown(); + +private: + /** + * @brief Event Handler callback given to the PlatformManager + * Function dispatchs the event to the ICDManager member + */ + static void ICDEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + + ICDManager * mICDManager; +}; + +} // namespace app +} // namespace chip diff --git a/src/app/icd/ICDManager.cpp b/src/app/icd/ICDManager.cpp new file mode 100644 index 00000000000000..a71ca14457c546 --- /dev/null +++ b/src/app/icd/ICDManager.cpp @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2023 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 + +namespace chip { +namespace app { + +ICDManager::ICDManager() {} + +} // namespace app +} // namespace chip diff --git a/src/app/icd/ICDManager.h b/src/app/icd/ICDManager.h new file mode 100644 index 00000000000000..8c8e55916c3fa8 --- /dev/null +++ b/src/app/icd/ICDManager.h @@ -0,0 +1,34 @@ +/* + * + * Copyright (c) 2023 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 + +namespace chip { +namespace app { + +/** + * @brief ICD Manager is responsible of processing the events and triggering the correct action for an ICD + */ +class ICDManager +{ +public: + ICDManager(); + +private: +}; + +} // namespace app +} // namespace chip diff --git a/src/app/icd/icd.gni b/src/app/icd/icd.gni new file mode 100644 index 00000000000000..4d1dfac7eeb2f3 --- /dev/null +++ b/src/app/icd/icd.gni @@ -0,0 +1,23 @@ +# Copyright (c) 2023 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. + +declare_args() { + # Matter SDK Configuration flag to enable ICD server functionality + # TODO - Add Specifics when the design is refined + chip_enable_icd_server = false + + # Matter SDK Configuration flag to enable ICD client functionality + # TODO - Add Specifics when the design is refined + chip_enable_icd_client = false +} diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 75a4262716f5a8..0793832d17271c 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -247,6 +247,10 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) } #endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT +#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER + mICDEventManager.Init(&mICDManager); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + // This initializes clusters, so should come after lower level initialization. InitDataModelHandler(); @@ -484,6 +488,9 @@ void Server::Shutdown() mAccessControl.Finish(); Access::ResetAccessControlToDefault(); Credentials::SetGroupDataProvider(nullptr); +#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER + mICDEventManager.Shutdown(); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER mAttributePersister.Shutdown(); // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code chip::Platform::MemoryShutdown(); diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 7eea447e20dc45..d2cdaacb7f48ea 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -65,6 +65,11 @@ #endif #include +#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER +#include // nogncheck +#include // nogncheck +#endif + namespace chip { constexpr size_t kMaxBlePendingPackets = 1; @@ -595,6 +600,10 @@ class Server Inet::InterfaceId mInterfaceId; System::Clock::Microseconds64 mInitTimestamp; +#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER + app::ICDEventManager mICDEventManager; + app::ICDManager mICDManager; +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER }; } // namespace chip diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index 1f7ad407339ca8..d18188b333325d 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -121,6 +121,7 @@ chip_test_suite("tests") { "TestEventPathParams.cpp", "TestExtensionFieldSets.cpp", "TestFabricScopedEventLogging.cpp", + "TestICDManager.cpp", "TestInteractionModelEngine.cpp", "TestMessageDef.cpp", "TestNumericAttributeTraits.cpp", @@ -170,6 +171,7 @@ chip_test_suite("tests") { ":scenes-table-test-srcs", "${chip_root}/src/app", "${chip_root}/src/app/common:cluster-objects", + "${chip_root}/src/app/icd:manager-srcs", "${chip_root}/src/app/tests:helpers", "${chip_root}/src/app/util/mock:mock_ember", "${chip_root}/src/lib/core", diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp new file mode 100644 index 00000000000000..6fdaeedf45a73f --- /dev/null +++ b/src/app/tests/TestICDManager.cpp @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2023 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 + +int TestICDManager() +{ + static nlTest sTests[] = { NL_TEST_SENTINEL() }; + + nlTestSuite cmSuite = { "TestICDManager", &sTests[0], nullptr, nullptr }; + + nlTestRunner(&cmSuite, nullptr); + return (nlTestRunnerStats(&cmSuite)); +} + +CHIP_REGISTER_TEST_SUITE(TestICDManager)