From b7986bf00a258a5a9f14140d21b22a4e3855ad80 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Tue, 9 Nov 2021 15:20:27 -0500 Subject: [PATCH] Improvements from pull request comments. * Add VerifyOrDie to the ConfigurationMgr getter. * Pass a pointer rather than a reference to ConfigurationMgr. * Explicitly default the instance pointer to nullptr. * Move the singleton implementation out of each platform into a shared file. --- src/controller/tests/TestDevice.cpp | 2 +- src/include/platform/ConfigurationManager.h | 5 +- src/platform/Ameba/BUILD.gn | 1 + .../Ameba/ConfigurationManagerImpl.cpp | 14 ----- src/platform/Ameba/PlatformManagerImpl.cpp | 2 +- src/platform/Darwin/BUILD.gn | 1 + .../Darwin/ConfigurationManagerImpl.cpp | 14 ----- src/platform/Darwin/PlatformManagerImpl.cpp | 2 +- src/platform/EFR32/BUILD.gn | 1 + .../EFR32/ConfigurationManagerImpl.cpp | 14 ----- src/platform/EFR32/PlatformManagerImpl.cpp | 2 +- src/platform/ESP32/BUILD.gn | 1 + .../ESP32/ConfigurationManagerImpl.cpp | 14 ----- src/platform/ESP32/PlatformManagerImpl.cpp | 2 +- src/platform/Linux/BUILD.gn | 1 + .../Linux/ConfigurationManagerImpl.cpp | 14 ----- src/platform/Linux/PlatformManagerImpl.cpp | 2 +- src/platform/P6/BUILD.gn | 1 + src/platform/P6/ConfigurationManagerImpl.cpp | 14 ----- src/platform/P6/PlatformManagerImpl.cpp | 2 +- .../SingletonConfigurationManager.cpp | 53 +++++++++++++++++++ src/platform/Tizen/BUILD.gn | 1 + .../Tizen/ConfigurationManagerImpl.cpp | 14 ----- src/platform/Tizen/PlatformManagerImpl.cpp | 2 +- .../Zephyr/ConfigurationManagerImpl.cpp | 14 ----- src/platform/Zephyr/PlatformManagerImpl.cpp | 2 +- src/platform/android/BUILD.gn | 1 + .../android/ConfigurationManagerImpl.cpp | 14 ----- src/platform/android/PlatformManagerImpl.cpp | 2 +- src/platform/cc13x2_26x2/BUILD.gn | 1 + .../cc13x2_26x2/ConfigurationManagerImpl.cpp | 14 ----- .../cc13x2_26x2/PlatformManagerImpl.cpp | 2 +- src/platform/fake/ConfigurationManagerImpl.h | 2 +- src/platform/mbed/BUILD.gn | 1 + .../mbed/ConfigurationManagerImpl.cpp | 14 ----- src/platform/mbed/PlatformManagerImpl.cpp | 2 +- src/platform/nrfconnect/BUILD.gn | 1 + src/platform/nxp/k32w/k32w0/BUILD.gn | 1 + .../k32w/k32w0/ConfigurationManagerImpl.cpp | 14 ----- .../nxp/k32w/k32w0/PlatformManagerImpl.cpp | 2 +- src/platform/qpg/BUILD.gn | 1 + src/platform/qpg/ConfigurationManagerImpl.cpp | 14 ----- src/platform/qpg/PlatformManagerImpl.cpp | 2 +- src/platform/telink/BUILD.gn | 1 + .../raw/tests/NetworkTestHelpers.cpp | 2 +- 45 files changed, 86 insertions(+), 200 deletions(-) create mode 100644 src/platform/SingletonConfigurationManager.cpp diff --git a/src/controller/tests/TestDevice.cpp b/src/controller/tests/TestDevice.cpp index 8521471761c82c..fe4cd909a0efe6 100644 --- a/src/controller/tests/TestDevice.cpp +++ b/src/controller/tests/TestDevice.cpp @@ -45,7 +45,7 @@ using TestTransportMgr = TransportMgr; void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext) { Platform::MemoryInit(); - chip::DeviceLayer::SetConfigurationMgr(chip::DeviceLayer::ConfigurationManagerImpl::GetDefaultInstance()); + chip::DeviceLayer::SetConfigurationMgr(&chip::DeviceLayer::ConfigurationManagerImpl::GetDefaultInstance()); DeviceTransportMgr transportMgr; SessionManager sessionManager; ExchangeManager exchangeMgr; diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 42c641c5b5d526..18ffe60efb7beb 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -166,9 +166,10 @@ extern ConfigurationManager & ConfigurationMgr(); /** * Sets a reference to a ConfigurationManager object. * - * This must be called before any calls to ConfigurationMgr. + * This must be called before any calls to ConfigurationMgr. If a nullptr is passed in, + * no changes will be made. */ -extern void SetConfigurationMgr(ConfigurationManager & configurationManager); +extern void SetConfigurationMgr(ConfigurationManager * configurationManager); } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Ameba/BUILD.gn b/src/platform/Ameba/BUILD.gn index 15849c83b426f0..2626ec984d0b0b 100755 --- a/src/platform/Ameba/BUILD.gn +++ b/src/platform/Ameba/BUILD.gn @@ -21,6 +21,7 @@ assert(chip_device_platform == "ameba") static_library("Ameba") { sources = [ "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", "AmebaConfig.cpp", "AmebaConfig.h", "BLEManagerImpl.cpp", diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index a053a561f6cbf1..9e5525322536b9 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -36,20 +36,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/Ameba/PlatformManagerImpl.cpp b/src/platform/Ameba/PlatformManagerImpl.cpp index 0d71ab8481d4fa..8f010e3e7a6c0e 100644 --- a/src/platform/Ameba/PlatformManagerImpl.cpp +++ b/src/platform/Ameba/PlatformManagerImpl.cpp @@ -57,7 +57,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) CHIP_ERROR err; - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Make sure the LwIP core lock has been initialized err = Internal::InitLwIPCoreLock(); diff --git a/src/platform/Darwin/BUILD.gn b/src/platform/Darwin/BUILD.gn index d54717826a997e..4e9f4f3220a3ad 100644 --- a/src/platform/Darwin/BUILD.gn +++ b/src/platform/Darwin/BUILD.gn @@ -34,6 +34,7 @@ static_library("Darwin") { sources = [ "../DeviceSafeQueue.cpp", "../DeviceSafeQueue.h", + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "BlePlatformConfig.h", diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp index 9be47867141687..1b904ffdb1b304 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.cpp +++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp @@ -128,20 +128,6 @@ CHIP_ERROR GetMACAddressFromInterfaces(io_iterator_t primaryInterfaceIterator, u } #endif // TARGET_OS_OSX -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/Darwin/PlatformManagerImpl.cpp b/src/platform/Darwin/PlatformManagerImpl.cpp index 8d5c2a996e9f03..ea11e5afc95b35 100644 --- a/src/platform/Darwin/PlatformManagerImpl.cpp +++ b/src/platform/Darwin/PlatformManagerImpl.cpp @@ -43,7 +43,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() // Initialize the configuration system. err = Internal::PosixConfig::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); mRunLoopSem = dispatch_semaphore_create(0); diff --git a/src/platform/EFR32/BUILD.gn b/src/platform/EFR32/BUILD.gn index f18643f914f647..26652ffd3ee60e 100644 --- a/src/platform/EFR32/BUILD.gn +++ b/src/platform/EFR32/BUILD.gn @@ -26,6 +26,7 @@ if (chip_enable_openthread) { static_library("EFR32") { sources = [ "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "BlePlatformConfig.h", diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index 2d54c2aa0431e4..c8564cd9f1b4f5 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -34,20 +34,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/EFR32/PlatformManagerImpl.cpp b/src/platform/EFR32/PlatformManagerImpl.cpp index 974977b96de7a8..e1c3af86181520 100644 --- a/src/platform/EFR32/PlatformManagerImpl.cpp +++ b/src/platform/EFR32/PlatformManagerImpl.cpp @@ -44,7 +44,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::EFR32Config::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Initialize LwIP. tcpip_init(NULL, NULL); diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index 175b83e29267ed..4c481560c2d84f 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -21,6 +21,7 @@ assert(chip_device_platform == "esp32") static_library("ESP32") { sources = [ "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.h", "CHIPDevicePlatformConfig.h", "CHIPDevicePlatformEvent.h", diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index cdc251d76cea32..0254d8504d7990 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -50,20 +50,6 @@ enum // TODO: Define a Singleton instance of CHIP Group Key Store here (#1266) -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/ESP32/PlatformManagerImpl.cpp b/src/platform/ESP32/PlatformManagerImpl.cpp index f12557687ae31c..0d290acef5aecd 100644 --- a/src/platform/ESP32/PlatformManagerImpl.cpp +++ b/src/platform/ESP32/PlatformManagerImpl.cpp @@ -57,7 +57,7 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); esp_err_t err; // Arrange for CHIP-encapsulated ESP32 errors to be translated to text diff --git a/src/platform/Linux/BUILD.gn b/src/platform/Linux/BUILD.gn index 5c7516bc56119c..2c39c68668afcf 100644 --- a/src/platform/Linux/BUILD.gn +++ b/src/platform/Linux/BUILD.gn @@ -36,6 +36,7 @@ static_library("Linux") { sources = [ "../DeviceSafeQueue.cpp", "../DeviceSafeQueue.h", + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "BlePlatformConfig.h", diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index a04c2eeff2af17..1e542084216b93 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -40,20 +40,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index 2fa906fbeff837..39d00ff2da9950 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -209,7 +209,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() // Initialize the configuration system. err = Internal::PosixConfig::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Call _InitChipStack() on the generic implementation base class // to finish the initialization process. err = Internal::GenericPlatformManagerImpl_POSIX::_InitChipStack(); diff --git a/src/platform/P6/BUILD.gn b/src/platform/P6/BUILD.gn index 7269cd9a817f7b..4ee27012f2ac3e 100644 --- a/src/platform/P6/BUILD.gn +++ b/src/platform/P6/BUILD.gn @@ -26,6 +26,7 @@ if (chip_enable_openthread) { static_library("P6") { sources = [ "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "BlePlatformConfig.h", diff --git a/src/platform/P6/ConfigurationManagerImpl.cpp b/src/platform/P6/ConfigurationManagerImpl.cpp index 4311d5a0239a36..b17e84fcb23d45 100644 --- a/src/platform/P6/ConfigurationManagerImpl.cpp +++ b/src/platform/P6/ConfigurationManagerImpl.cpp @@ -36,20 +36,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/P6/PlatformManagerImpl.cpp b/src/platform/P6/PlatformManagerImpl.cpp index 2d81d3a0fcb931..c9503f243e1da7 100644 --- a/src/platform/P6/PlatformManagerImpl.cpp +++ b/src/platform/P6/PlatformManagerImpl.cpp @@ -42,7 +42,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { CHIP_ERROR err; - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Make sure the LwIP core lock has been initialized err = Internal::InitLwIPCoreLock(); diff --git a/src/platform/SingletonConfigurationManager.cpp b/src/platform/SingletonConfigurationManager.cpp new file mode 100644 index 00000000000000..0658ebfbc776bc --- /dev/null +++ b/src/platform/SingletonConfigurationManager.cpp @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2021 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. + */ + +/** + * @file + * Implements a getter and setter for a singleton ConfigurationManager object. + */ + +#include + +namespace chip { +namespace DeviceLayer { + +class ConfigurationManager; + +namespace { + +/** Singleton pointer to the ConfigurationManager implementation. + */ +ConfigurationManager * gInstance = nullptr; + +} // namespace + +ConfigurationManager & ConfigurationMgr() +{ + VerifyOrDie(gInstance != nullptr); + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager * configurationManager) +{ + if (configurationManager != nullptr) + { + gInstance = configurationManager; + } +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Tizen/BUILD.gn b/src/platform/Tizen/BUILD.gn index 6c3a046ad052d1..f066f8892819b5 100644 --- a/src/platform/Tizen/BUILD.gn +++ b/src/platform/Tizen/BUILD.gn @@ -26,6 +26,7 @@ static_library("Tizen") { sources = [ "../DeviceSafeQueue.cpp", "../DeviceSafeQueue.h", + "../SingletonConfigurationManager.cpp", "AppPreference.cpp", "AppPreference.h", "BLEManagerImpl.cpp", diff --git a/src/platform/Tizen/ConfigurationManagerImpl.cpp b/src/platform/Tizen/ConfigurationManagerImpl.cpp index 1f8715b7611a0f..237d114ca56e9f 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.cpp +++ b/src/platform/Tizen/ConfigurationManagerImpl.cpp @@ -37,20 +37,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/Tizen/PlatformManagerImpl.cpp b/src/platform/Tizen/PlatformManagerImpl.cpp index c1e12a8a54b5ae..bd4abfa8c75b0d 100644 --- a/src/platform/Tizen/PlatformManagerImpl.cpp +++ b/src/platform/Tizen/PlatformManagerImpl.cpp @@ -36,7 +36,7 @@ PlatformManagerImpl PlatformManagerImpl::sInstance; CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { ReturnErrorOnFailure(Internal::PosixConfig::Init()); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); return Internal::GenericPlatformManagerImpl_POSIX::_InitChipStack(); } diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index 9befd41bd52793..a6a743cf1588e9 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp +++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp @@ -43,20 +43,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/Zephyr/PlatformManagerImpl.cpp b/src/platform/Zephyr/PlatformManagerImpl.cpp index 37658d807bbf19..09f388058c0c03 100644 --- a/src/platform/Zephyr/PlatformManagerImpl.cpp +++ b/src/platform/Zephyr/PlatformManagerImpl.cpp @@ -72,7 +72,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::ZephyrConfig::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); #if !CONFIG_NORDIC_SECURITY_BACKEND // Add entropy source based on Zephyr entropy driver diff --git a/src/platform/android/BUILD.gn b/src/platform/android/BUILD.gn index a12d6aa55e9108..1b6cc5ea3313eb 100644 --- a/src/platform/android/BUILD.gn +++ b/src/platform/android/BUILD.gn @@ -28,6 +28,7 @@ static_library("android") { sources = [ "../DeviceSafeQueue.cpp", "../DeviceSafeQueue.h", + "../SingletonConfigurationManager.cpp", "AndroidChipPlatform-JNI.cpp", "AndroidConfig.cpp", "AndroidConfig.h", diff --git a/src/platform/android/ConfigurationManagerImpl.cpp b/src/platform/android/ConfigurationManagerImpl.cpp index c61a375fd0589e..0b9c37b55515dd 100644 --- a/src/platform/android/ConfigurationManagerImpl.cpp +++ b/src/platform/android/ConfigurationManagerImpl.cpp @@ -42,20 +42,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/android/PlatformManagerImpl.cpp b/src/platform/android/PlatformManagerImpl.cpp index fb6b7c1ae1c577..50f5d04be48420 100644 --- a/src/platform/android/PlatformManagerImpl.cpp +++ b/src/platform/android/PlatformManagerImpl.cpp @@ -43,7 +43,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() // Initialize the configuration system. err = Internal::AndroidConfig::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Call _InitChipStack() on the generic implementation base class // to finish the initialization process. diff --git a/src/platform/cc13x2_26x2/BUILD.gn b/src/platform/cc13x2_26x2/BUILD.gn index 346f1c2718601b..db40cfb1918db3 100644 --- a/src/platform/cc13x2_26x2/BUILD.gn +++ b/src/platform/cc13x2_26x2/BUILD.gn @@ -25,6 +25,7 @@ if (chip_enable_openthread) { static_library("cc13x2_26x2") { sources = [ "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", "BlePlatformConfig.h", "CC13X2_26X2Config.cpp", "CC13X2_26X2Config.h", diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp index 601a540e438aff..d7a22577288411 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp @@ -54,20 +54,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp b/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp index 003b75aa62af82..07178e46e3c866 100644 --- a/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp @@ -106,7 +106,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::CC13X2_26X2Config::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // DMM Addition DMMPolicy_Params dmmPolicyParams; diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index 4edc14e7ccc51d..cee37e551605a1 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -111,7 +111,7 @@ ConfigurationManager & ConfigurationMgr() return sInstance; } -void SetConfigurationMgr(ConfigurationManagerImpl & configurationManager) {} +void SetConfigurationMgr(ConfigurationManagerImpl * configurationManager) {} } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/mbed/BUILD.gn b/src/platform/mbed/BUILD.gn index 138cc3e6bc0cfc..beee849ddc7f41 100644 --- a/src/platform/mbed/BUILD.gn +++ b/src/platform/mbed/BUILD.gn @@ -20,6 +20,7 @@ assert(chip_device_platform == "mbed") static_library("mbed") { sources = [ + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "ConfigurationManagerImpl.cpp", diff --git a/src/platform/mbed/ConfigurationManagerImpl.cpp b/src/platform/mbed/ConfigurationManagerImpl.cpp index 01ea9324724828..bd78fb8e27573c 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.cpp +++ b/src/platform/mbed/ConfigurationManagerImpl.cpp @@ -42,20 +42,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/mbed/PlatformManagerImpl.cpp b/src/platform/mbed/PlatformManagerImpl.cpp index e30a8110637a7e..a76ea42dda9138 100644 --- a/src/platform/mbed/PlatformManagerImpl.cpp +++ b/src/platform/mbed/PlatformManagerImpl.cpp @@ -91,7 +91,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) tcpip_init(NULL, NULL); #endif - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Call up to the base class _InitChipStack() to perform the bulk of the initialization. auto err = GenericPlatformManagerImpl::_InitChipStack(); diff --git a/src/platform/nrfconnect/BUILD.gn b/src/platform/nrfconnect/BUILD.gn index 7f6cb034e92174..83f00cf1d82e30 100644 --- a/src/platform/nrfconnect/BUILD.gn +++ b/src/platform/nrfconnect/BUILD.gn @@ -20,6 +20,7 @@ assert(chip_device_platform == "nrfconnect") static_library("nrfconnect") { sources = [ + "../SingletonConfigurationManager.cpp", "../Zephyr/BLEManagerImpl.cpp", "../Zephyr/ConfigurationManagerImpl.cpp", "../Zephyr/KeyValueStoreManagerImpl.cpp", diff --git a/src/platform/nxp/k32w/k32w0/BUILD.gn b/src/platform/nxp/k32w/k32w0/BUILD.gn index 10628fd4466e5c..0a37f9caf71408 100644 --- a/src/platform/nxp/k32w/k32w0/BUILD.gn +++ b/src/platform/nxp/k32w/k32w0/BUILD.gn @@ -25,6 +25,7 @@ if (chip_enable_openthread) { static_library("k32w0") { sources = [ "../../../FreeRTOS/SystemTimeSupport.cpp", + "../../../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "CHIPDevicePlatformConfig.h", diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp index 34333af3a24815..9c17cc1290c09b 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp @@ -39,20 +39,6 @@ using namespace ::chip::DeviceLayer::Internal; // TODO: Define a Singleton instance of CHIP Group Key Store here -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp index ca147fb76c39a0..567274e3052ca8 100644 --- a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp @@ -58,7 +58,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::K32WConfig::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Initialize LwIP. tcpip_init(NULL, NULL); diff --git a/src/platform/qpg/BUILD.gn b/src/platform/qpg/BUILD.gn index a4abfeb93e0284..c3526b4756b838 100644 --- a/src/platform/qpg/BUILD.gn +++ b/src/platform/qpg/BUILD.gn @@ -25,6 +25,7 @@ if (chip_enable_openthread) { static_library("qpg") { sources = [ "../FreeRTOS/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", "BLEManagerImpl.cpp", "BLEManagerImpl.h", "BlePlatformConfig.h", diff --git a/src/platform/qpg/ConfigurationManagerImpl.cpp b/src/platform/qpg/ConfigurationManagerImpl.cpp index 9f5caffb21431e..c8c059017d7cb4 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.cpp +++ b/src/platform/qpg/ConfigurationManagerImpl.cpp @@ -41,20 +41,6 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton pointer to the ConfigurationManager implementation. - */ -ConfigurationManager * gInstance; - -ConfigurationManager & ConfigurationMgr() -{ - return *gInstance; -} - -void SetConfigurationMgr(ConfigurationManager & configurationManager) -{ - gInstance = &configurationManager; -} - ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() { static ConfigurationManagerImpl sInstance; diff --git a/src/platform/qpg/PlatformManagerImpl.cpp b/src/platform/qpg/PlatformManagerImpl.cpp index f64b790dada37a..ff6e38aafc853d 100644 --- a/src/platform/qpg/PlatformManagerImpl.cpp +++ b/src/platform/qpg/PlatformManagerImpl.cpp @@ -40,7 +40,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::QPGConfig::Init(); SuccessOrExit(err); - SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); // Initialize LwIP. tcpip_init(NULL, NULL); diff --git a/src/platform/telink/BUILD.gn b/src/platform/telink/BUILD.gn index 77e03b15879532..539a8d93775747 100644 --- a/src/platform/telink/BUILD.gn +++ b/src/platform/telink/BUILD.gn @@ -20,6 +20,7 @@ assert(chip_device_platform == "telink") static_library("telink") { sources = [ + "../SingletonConfigurationManager.cpp", "../Zephyr/BLEManagerImpl.cpp", "../Zephyr/ConfigurationManagerImpl.cpp", "../Zephyr/KeyValueStoreManagerImpl.cpp", diff --git a/src/transport/raw/tests/NetworkTestHelpers.cpp b/src/transport/raw/tests/NetworkTestHelpers.cpp index 8a2002e75edcdd..280cd6b84d0a75 100644 --- a/src/transport/raw/tests/NetworkTestHelpers.cpp +++ b/src/transport/raw/tests/NetworkTestHelpers.cpp @@ -30,7 +30,7 @@ namespace Test { CHIP_ERROR IOContext::Init() { CHIP_ERROR err = Platform::MemoryInit(); - chip::DeviceLayer::SetConfigurationMgr(chip::DeviceLayer::ConfigurationManagerImpl::GetDefaultInstance()); + chip::DeviceLayer::SetConfigurationMgr(&chip::DeviceLayer::ConfigurationManagerImpl::GetDefaultInstance()); gSystemLayer.Init();