forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SL-ONLY] Add ApplicationSleepManager structure for the selective lis…
…tenning implementation (project-chip#131) Co-authored-by: Ricardo Casallas <77841255+rcasallas-silabs@users.noreply.github.com>
- Loading branch information
1 parent
575d44c
commit c16843b
Showing
9 changed files
with
298 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/******************************************************************************* | ||
* @file ApplicationSleepManager.cpp | ||
* @brief Implementation for the buisness logic around Optimizing Wi-Fi sleep states | ||
******************************************************************************* | ||
* # License | ||
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b> | ||
******************************************************************************* | ||
* | ||
* The licensor of this software is Silicon Laboratories Inc. Your use of this | ||
* software is governed by the terms of Silicon Labs Master Software License | ||
* Agreement (MSLA) available at | ||
* www.silabs.com/about-us/legal/master-software-license-agreement. This | ||
* software is distributed to you in Source Code format and is governed by the | ||
* sections of the MSLA applicable to Source Code. | ||
* | ||
******************************************************************************/ | ||
|
||
#include "ApplicationSleepManager.h" | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Silabs { | ||
|
||
ApplicationSleepManager ApplicationSleepManager::mInstance; | ||
|
||
CHIP_ERROR ApplicationSleepManager::Init() | ||
{ | ||
VerifyOrReturnError(mFabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT, ChipLogError(AppServer, "FabricTable is null")); | ||
VerifyOrReturnError(mSubscriptionsInfoProvider != nullptr, CHIP_ERROR_INVALID_ARGUMENT, | ||
ChipLogError(AppServer, "SubscriptionsInfoProvider is null")); | ||
VerifyOrReturnError(mCommissioningWindowManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT, | ||
ChipLogError(AppServer, "CommissioningWindowManager is null")); | ||
VerifyOrReturnError(mWifiSleepManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT, | ||
ChipLogError(AppServer, "WifiSleepManager is null")); | ||
|
||
ReturnErrorOnFailure(mFabricTable->AddFabricDelegate(this)); | ||
|
||
// Register WifiSleepManager::ApplicationCallback | ||
mWifiSleepManager->SetApplicationCallback(this); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void ApplicationSleepManager::OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler) | ||
{ | ||
mWifiSleepManager->VerifyAndTransitionToLowPowerMode(); | ||
} | ||
|
||
void ApplicationSleepManager::OnSubscriptionTerminated(chip::app::ReadHandler & aReadHandler) | ||
{ | ||
mWifiSleepManager->VerifyAndTransitionToLowPowerMode(); | ||
} | ||
|
||
CHIP_ERROR ApplicationSleepManager::OnSubscriptionRequested(chip::app::ReadHandler & aReadHandler, | ||
chip::Transport::SecureSession & aSecureSession) | ||
{ | ||
// Nothing to execute for the ApplicationSleepManager | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void ApplicationSleepManager::OnFabricRemoved(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) | ||
{ | ||
mWifiSleepManager->VerifyAndTransitionToLowPowerMode(); | ||
} | ||
|
||
void ApplicationSleepManager::OnFabricCommitted(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) | ||
{ | ||
mWifiSleepManager->VerifyAndTransitionToLowPowerMode(); | ||
} | ||
|
||
bool ApplicationSleepManager::CanGoToLIBasedSleep() | ||
{ | ||
// TODO: Implement your logic here | ||
|
||
ChipLogProgress(AppServer, "CanGoToLIBasedSleep was called!"); | ||
return false; | ||
} | ||
|
||
} // namespace Silabs | ||
} // namespace app | ||
} // namespace chip |
138 changes: 138 additions & 0 deletions
138
examples/platform/silabs/wifi/icd/ApplicationSleepManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/******************************************************************************* | ||
* @file ApplicationSleepManager.h | ||
* @brief Header for the buisness logic around Optimizing Wi-Fi sleep states | ||
******************************************************************************* | ||
* # License | ||
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b> | ||
******************************************************************************* | ||
* | ||
* The licensor of this software is Silicon Laboratories Inc. Your use of this | ||
* software is governed by the terms of Silicon Labs Master Software License | ||
* Agreement (MSLA) available at | ||
* www.silabs.com/about-us/legal/master-software-license-agreement. This | ||
* software is distributed to you in Source Code format and is governed by the | ||
* sections of the MSLA applicable to Source Code. | ||
* | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <app/ReadHandler.h> | ||
#include <app/SubscriptionsInfoProvider.h> | ||
#include <app/server/CommissioningWindowManager.h> | ||
#include <credentials/FabricTable.h> | ||
#include <platform/silabs/wifi/icd/WifiSleepManager.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Silabs { | ||
|
||
class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallback, | ||
public chip::DeviceLayer::Silabs::WifiSleepManager::ApplicationCallback, | ||
public chip::FabricTable::Delegate | ||
{ | ||
public: | ||
static ApplicationSleepManager & GetInstance() { return mInstance; } | ||
|
||
/** | ||
* @brief Init function validates that the necessary pointers where correctly set | ||
* before registering the object with the FabricTable and the WifiSleepManager. | ||
* | ||
* Init function does not register with the InteractionModelEngine since depending on the whole interation model engine | ||
* complexifies unit testing when we can use the SubscriptionInfoProvider which provides the necessary APIs. | ||
* | ||
* | ||
* @return CHIP_ERROR CHIP_NO_ERROR if the init succeed | ||
* CHIP_ERROR_INVALID_ARGUMENT, if the fabricTable, subscriptionsInfoProvider or commissioningWindowManager, | ||
* wifiSleepManager were not set correctly | ||
* other, if the FabricTable::AddFabricDelegate failed | ||
*/ | ||
CHIP_ERROR Init(); | ||
|
||
ApplicationSleepManager & SetFabricTable(chip::FabricTable * fabricTable) | ||
{ | ||
mFabricTable = fabricTable; | ||
return *this; | ||
} | ||
|
||
ApplicationSleepManager & SetSubscriptionInfoProvider(chip::app::SubscriptionsInfoProvider * subscriptionsInfoProvider) | ||
{ | ||
mSubscriptionsInfoProvider = subscriptionsInfoProvider; | ||
return *this; | ||
} | ||
|
||
ApplicationSleepManager & SetCommissioningWindowManager(chip::CommissioningWindowManager * commissioningWindowManager) | ||
{ | ||
mCommissioningWindowManager = commissioningWindowManager; | ||
return *this; | ||
} | ||
|
||
ApplicationSleepManager & SetWifiSleepManager(chip::DeviceLayer::Silabs::WifiSleepManager * wifiSleepManager) | ||
{ | ||
mWifiSleepManager = wifiSleepManager; | ||
return *this; | ||
} | ||
|
||
// ReadHandler::ApplicationCallback implementation | ||
|
||
/** | ||
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode. | ||
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to | ||
* determine in which low power state the Wi-Fi device can transition to. | ||
*/ | ||
void OnSubscriptionTerminated(chip::app::ReadHandler & aReadHandler); | ||
|
||
/** | ||
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode. | ||
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to | ||
* determine in which low power state the Wi-Fi device can transition to. | ||
*/ | ||
void OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler); | ||
|
||
CHIP_ERROR OnSubscriptionRequested(chip::app::ReadHandler & aReadHandler, chip::Transport::SecureSession & aSecureSession); | ||
|
||
// WifiSleepManager::ApplicationCallback implementation | ||
|
||
/** | ||
* @brief TODO | ||
* | ||
* @return true | ||
* @return false | ||
*/ | ||
bool CanGoToLIBasedSleep() override; | ||
|
||
// FabricTable::Delegate implementation | ||
|
||
/** | ||
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode. | ||
* The VerifyAndTransitionToLowPowerMode function is responsible of queriyng the ApplicationSleepManager to | ||
* determine in which low power state the Wi-Fi device can transition to. | ||
*/ | ||
void OnFabricRemoved(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override; | ||
|
||
/** | ||
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode. | ||
* The VerifyAndTransitionToLowPowerMode function is responsible of queriyng the ApplicationSleepManager to | ||
* determine in which low power state the Wi-Fi device can transition to. | ||
*/ | ||
void OnFabricCommitted(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override; | ||
|
||
void OnFabricUpdated(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override {} | ||
|
||
private: | ||
ApplicationSleepManager() = default; | ||
~ApplicationSleepManager() = default; | ||
|
||
ApplicationSleepManager(const ApplicationSleepManager &) = delete; | ||
ApplicationSleepManager & operator=(const ApplicationSleepManager &) = delete; | ||
|
||
static ApplicationSleepManager mInstance; | ||
chip::FabricTable * mFabricTable = nullptr; | ||
chip::app::SubscriptionsInfoProvider * mSubscriptionsInfoProvider = nullptr; | ||
chip::CommissioningWindowManager * mCommissioningWindowManager = nullptr; | ||
chip::DeviceLayer::Silabs::WifiSleepManager * mWifiSleepManager = nullptr; | ||
}; | ||
|
||
} // namespace Silabs | ||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#****************************************************************************** | ||
# @file BUILD.gn | ||
# @brief BUILD.gn to build the Application Sleep Manager implementation | ||
#****************************************************************************** | ||
# # License | ||
# <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b> | ||
#****************************************************************************** | ||
# | ||
# The licensor of this software is Silicon Laboratories Inc. Your use of this | ||
# software is governed by the terms of Silicon Labs Master Software License | ||
# Agreement (MSLA) available at | ||
# www.silabs.com/about-us/legal/master-software-license-agreement. This | ||
# software is distributed to you in Source Code format and is governed by the | ||
# sections of the MSLA applicable to Source Code. | ||
# | ||
#*****************************************************************************/ | ||
|
||
import("//build_overrides/chip.gni") | ||
|
||
config("app-sleep-manager-config") { | ||
include_dirs = [ "." ] | ||
defines = [ "SL_MATTER_ENABLE_APP_SLEEP_MANAGER=1" ] | ||
} | ||
|
||
source_set("app-sleep-manager") { | ||
sources = [ | ||
"ApplicationSleepManager.cpp", | ||
"ApplicationSleepManager.h", | ||
] | ||
|
||
deps = [ | ||
"${chip_root}/src/app", | ||
"${chip_root}/src/app/server:server", | ||
"${chip_root}/src/lib/core", | ||
"${chip_root}/src/platform/silabs/wifi:wifi-platform", | ||
] | ||
|
||
public_configs = [ ":app-sleep-manager-config" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters