Skip to content

Commit

Permalink
[SL-ONLY] Add structure for the SleepManager class (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs authored Nov 15, 2024
1 parent b6cebf6 commit 2dccf95
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 +=
Expand Down
37 changes: 37 additions & 0 deletions examples/platform/silabs/wifi/icd/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
40 changes: 40 additions & 0 deletions examples/platform/silabs/wifi/icd/SleepManager.cpp
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions examples/platform/silabs/wifi/icd/SleepManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

#pragma once

#include <app/ReadHandler.h>
#include <app/icd/server/ICDManager.h>
#include <app/icd/server/ICDStateObserver.h>
#include <lib/core/CHIPError.h>

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

0 comments on commit 2dccf95

Please sign in to comment.