|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Project CHIP Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 12 | + * or implied. See the License for the specific language governing permissions and limitations under the License. |
| 13 | + */ |
| 14 | +#pragma once |
| 15 | + |
| 16 | +#include <app/ReadHandler.h> |
| 17 | +#include <app/icd/server/ICDManager.h> |
| 18 | +#include <app/icd/server/ICDStateObserver.h> |
| 19 | +#include <lib/core/CHIPError.h> |
| 20 | + |
| 21 | +namespace chip { |
| 22 | +namespace DeviceLayer { |
| 23 | +namespace Silabs { |
| 24 | + |
| 25 | +/** |
| 26 | + * @brief SleepManager is a singleton class that manages the sleep modes for Wi-Fi devices. |
| 27 | + * The class contains the buisness logic associated with optimizing the sleep states based on the Matter SDK internal states |
| 28 | + * |
| 29 | + * The class implements two disctint optimization states; one of SIT devices and one of LIT devices |
| 30 | + * For SIT ICDs, the logic is based on the Subscriptions established with the device. |
| 31 | + * For LIT ICDs, the logic is based on the ICDManager operating modes. The LIT mode also utilizes the SIT mode logic. |
| 32 | + */ |
| 33 | +class SleepManager : public chip::app::ICDStateObserver, public chip::app::ReadHandler::ApplicationCallback |
| 34 | +{ |
| 35 | +public: |
| 36 | + SleepManager(const SleepManager &) = delete; |
| 37 | + SleepManager & operator=(const SleepManager &) = delete; |
| 38 | + |
| 39 | + static SleepManager & GetInstance() { return mInstance; } |
| 40 | + |
| 41 | + /** |
| 42 | + * @brief Init function that configure the SleepManager APIs based on the type of ICD |
| 43 | + * SIT ICD: Init function registers the ReadHandler Application callback to be notified when a subscription is |
| 44 | + * established or destroyed. |
| 45 | + * |
| 46 | + * LIT ICD: Init function registers with the ICDManager as an observer to be notified of the ICD mode changes. |
| 47 | + * |
| 48 | + * @return CHIP_ERROR |
| 49 | + */ |
| 50 | + CHIP_ERROR Init(); |
| 51 | + |
| 52 | + // ICDSateObserver implementation overrides |
| 53 | + |
| 54 | + void OnEnterActiveMode() override; |
| 55 | + void OnEnterIdleMode() override; |
| 56 | + void OnTransitionToIdle() override { /* No execution logic */ } |
| 57 | + void OnICDModeChange() override { /* No execution logic */ } |
| 58 | + |
| 59 | + // ReadHandler::ApplicationCallback implementation overrides |
| 60 | + |
| 61 | + void OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler); |
| 62 | + void OnSubscriptionTerminated(chip::app::ReadHandler & aReadHandler); |
| 63 | + |
| 64 | +private: |
| 65 | + SleepManager() = default; |
| 66 | + ~SleepManager() = default; |
| 67 | + |
| 68 | + static SleepManager mInstance; |
| 69 | +}; |
| 70 | + |
| 71 | +} // namespace Silabs |
| 72 | +} // namespace DeviceLayer |
| 73 | +} // namespace chip |
0 commit comments