From a416b487ccc535c8a7d261296c4126230caa31bc Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 2 Aug 2024 16:05:06 +0530 Subject: [PATCH] Add setter API for SupportedModesManager --- .../include/static-supported-modes-manager.h | 10 +++++----- .../src/static-supported-modes-manager.cpp | 7 +------ .../mode-select-server/mode-select-server.cpp | 11 +++++++++++ .../mode-select-server/supported-modes-manager.h | 4 +++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h b/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h index b4ce50b8cd49a3..04da9724a0b8e1 100644 --- a/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h +++ b/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h @@ -31,7 +31,7 @@ namespace ModeSelect { * This implementation statically defines the options. */ -class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager +class StaticSupportedModesManager : public SupportedModesManager { using ModeOptionStructType = Structs::ModeOptionStruct::Type; using storage_value_type = const ModeOptionStructType; @@ -52,7 +52,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp static const EndpointSpanPair supportedOptionsByEndpoints[MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT]; public: - static const StaticSupportedModesManager instance; + static StaticSupportedModesManager instance; SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override; @@ -61,13 +61,13 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp ~StaticSupportedModesManager(){}; - StaticSupportedModesManager() {} + StaticSupportedModesManager() { + ModeSelect::setSupportedModesManager(&instance); + } static inline const StaticSupportedModesManager & getStaticSupportedModesManagerInstance() { return instance; } }; -const SupportedModesManager * getSupportedModesManager(); - } // namespace ModeSelect } // namespace Clusters } // namespace app diff --git a/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp b/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp index 4060d4be85ec9c..7012adf2cd8ea3 100644 --- a/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp @@ -39,7 +39,7 @@ const StaticSupportedModesManager::EndpointSpanPair EndpointSpanPair(1, Span(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1 }; -const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); +StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager(); SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const { @@ -76,8 +76,3 @@ Status StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointI ChipLogProgress(Zcl, "Cannot find the mode %u", mode); return Status::InvalidCommand; } - -const ModeSelect::SupportedModesManager * ModeSelect::getSupportedModesManager() -{ - return &StaticSupportedModesManager::instance; -} diff --git a/src/app/clusters/mode-select-server/mode-select-server.cpp b/src/app/clusters/mode-select-server/mode-select-server.cpp index dceb72767bfb14..e19be3a82dfaab 100644 --- a/src/app/clusters/mode-select-server/mode-select-server.cpp +++ b/src/app/clusters/mode-select-server/mode-select-server.cpp @@ -49,6 +49,17 @@ using BootReasonType = GeneralDiagnostics::BootReasonEnum; static InteractionModel::Status verifyModeValue(const EndpointId endpointId, const uint8_t newMode); +ModeSelect::SupportedModesManager *sSupportedModesManager = nullptr; + +const SupportedModesManager * ModeSelect::getSupportedModesManager() +{ + return sSupportedModesManager; +} + +void ModeSelect::setSupportedModesManager(ModeSelect::SupportedModesManager * aSupportedModesManager) +{ + sSupportedModesManager = aSupportedModesManager; +} namespace { inline bool areStartUpModeAndCurrentModeNonVolatile(EndpointId endpoint); diff --git a/src/app/clusters/mode-select-server/supported-modes-manager.h b/src/app/clusters/mode-select-server/supported-modes-manager.h index 3c36f188cb4a0e..d3ed1cb8bdb91a 100644 --- a/src/app/clusters/mode-select-server/supported-modes-manager.h +++ b/src/app/clusters/mode-select-server/supported-modes-manager.h @@ -34,7 +34,6 @@ class SupportedModesManager { using ModeOptionStructType = Structs::ModeOptionStruct::Type; - public: /** * A class that can return the supported ModeOptions for a specific endpoint. @@ -80,10 +79,13 @@ class SupportedModesManager const ModeOptionStructType ** dataPtr) const = 0; virtual ~SupportedModesManager() {} + }; const SupportedModesManager * getSupportedModesManager(); +void setSupportedModesManager(SupportedModesManager * aSupportedModesManager); + } // namespace ModeSelect } // namespace Clusters } // namespace app