From 2dccf9590c65acb4a29b92285da079f83ad1d01e Mon Sep 17 00:00:00 2001 From: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com> Date: Fri, 15 Nov 2024 08:16:54 -0500 Subject: [PATCH] [SL-ONLY] Add structure for the SleepManager class (#105) --- examples/platform/silabs/SiWx917/BUILD.gn | 5 ++ examples/platform/silabs/wifi/icd/BUILD.gn | 37 +++++++++++ .../platform/silabs/wifi/icd/SleepManager.cpp | 40 ++++++++++++ .../platform/silabs/wifi/icd/SleepManager.h | 61 +++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 examples/platform/silabs/wifi/icd/BUILD.gn create mode 100644 examples/platform/silabs/wifi/icd/SleepManager.cpp create mode 100644 examples/platform/silabs/wifi/icd/SleepManager.h diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 2d6d3574ea..4ef00d2ede 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -174,6 +174,11 @@ source_set("siwx917-common") { } } + # Sl-Only: Support for the Wi-Fi Sleep Manager + if (chip_enable_icd_server) { + public_deps += [ "${silabs_common_plat_dir}/wifi/icd:sleep-manager" ] + } + # DIC if (enable_dic) { public_deps += diff --git a/examples/platform/silabs/wifi/icd/BUILD.gn b/examples/platform/silabs/wifi/icd/BUILD.gn new file mode 100644 index 0000000000..7b0e1b1fef --- /dev/null +++ b/examples/platform/silabs/wifi/icd/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2024 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") + +config("sleep-manager-config") { + include_dirs = [ "." ] + defines = [] +} + +source_set("sleep-manager") { + sources = [ + "SleepManager.cpp", + "SleepManager.h", + ] + + public_deps = [ + "${chip_root}/src/app:app", + "${chip_root}/src/app/icd/server:manager", + "${chip_root}/src/app/icd/server:observer", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] + + public_configs = [ ":sleep-manager-config" ] +} diff --git a/examples/platform/silabs/wifi/icd/SleepManager.cpp b/examples/platform/silabs/wifi/icd/SleepManager.cpp new file mode 100644 index 0000000000..8fc181ce19 --- /dev/null +++ b/examples/platform/silabs/wifi/icd/SleepManager.cpp @@ -0,0 +1,40 @@ +#include "SleepManager.h" + +using namespace chip::app; + +namespace chip { +namespace DeviceLayer { +namespace Silabs { + +// Initialize the static instance +SleepManager SleepManager::mInstance; + +CHIP_ERROR SleepManager::Init() +{ + // Initialization logic + return CHIP_NO_ERROR; +} + +void SleepManager::OnEnterActiveMode() +{ + // Execution logic for entering active mode +} + +void SleepManager::OnEnterIdleMode() +{ + // Execution logic for entering idle mode +} + +void SleepManager::OnSubscriptionEstablished(ReadHandler & aReadHandler) +{ + // Implement logic for when a subscription is established +} + +void SleepManager::OnSubscriptionTerminated(ReadHandler & aReadHandler) +{ + // Implement logic for when a subscription is terminated +} + +} // namespace Silabs +} // namespace DeviceLayer +} // namespace chip diff --git a/examples/platform/silabs/wifi/icd/SleepManager.h b/examples/platform/silabs/wifi/icd/SleepManager.h new file mode 100644 index 0000000000..80db24807c --- /dev/null +++ b/examples/platform/silabs/wifi/icd/SleepManager.h @@ -0,0 +1,61 @@ + +#pragma once + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { +namespace Silabs { + +/** + * @brief SleepManager is a singleton class that manages the sleep modes for Wi-Fi devices. + * The class contains the buisness logic associated with optimizing the sleep states based on the Matter SDK internal states + * + * The class implements two disctint optimization states; one of SIT devices and one of LIT devices + * For SIT ICDs, the logic is based on the Subscriptions established with the device. + * For LIT ICDs, the logic is based on the ICDManager operating modes. The LIT mode also utilizes the SIT mode logic. + */ +class SleepManager : public chip::app::ICDStateObserver, public chip::app::ReadHandler::ApplicationCallback +{ +public: + SleepManager(const SleepManager &) = delete; + SleepManager & operator=(const SleepManager &) = delete; + + static SleepManager & GetInstance() { return mInstance; } + + /** + * @brief Init function that configure the SleepManager APIs based on the type of ICD + * SIT ICD: Init function registers the ReadHandler Application callback to be notified when a subscription is + * established or destroyed. + * + * LIT ICD: Init function registers with the ICDManager as an observer to be notified of the ICD mode changes. + * + * @return CHIP_ERROR + */ + CHIP_ERROR Init(); + + // ICDStateObserver implementation overrides + + void OnEnterActiveMode(); + void OnEnterIdleMode(); + void OnTransitionToIdle() { /* No execution logic */ } + void OnICDModeChange() { /* No execution logic */ } + + // ReadHandler::ApplicationCallback implementation overrides + + void OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler); + void OnSubscriptionTerminated(chip::app::ReadHandler & aReadHandler); + +private: + SleepManager() = default; + ~SleepManager() = default; + + static SleepManager mInstance; +}; + +} // namespace Silabs +} // namespace DeviceLayer +} // namespace chip