From e9be5b51542ffa14f25903850d3c784c87dc43d2 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Thu, 21 Oct 2021 16:20:09 -0400 Subject: [PATCH 01/10] Add the setter for the ConfigurationManager. Also remove the implementation getter. --- src/include/platform/ConfigurationManager.h | 12 ++++---- .../Ameba/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/Ameba/ConfigurationManagerImpl.h | 29 ------------------- .../Darwin/ConfigurationManagerImpl.cpp | 14 +++++++-- .../Darwin/ConfigurationManagerImpl.h | 29 ------------------- .../EFR32/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/EFR32/ConfigurationManagerImpl.h | 29 ------------------- .../ESP32/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/ESP32/ConfigurationManagerImpl.h | 29 ------------------- .../Linux/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/Linux/ConfigurationManagerImpl.h | 29 ------------------- src/platform/P6/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/P6/ConfigurationManagerImpl.h | 29 +------------------ .../Tizen/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/Tizen/ConfigurationManagerImpl.h | 29 ------------------- .../Zephyr/ConfigurationManagerImpl.cpp | 14 +++++++-- .../Zephyr/ConfigurationManagerImpl.h | 29 ------------------- .../android/ConfigurationManagerImpl.cpp | 14 +++++++-- .../android/ConfigurationManagerImpl.h | 29 ------------------- .../cc13x2_26x2/ConfigurationManagerImpl.cpp | 14 +++++++-- .../cc13x2_26x2/ConfigurationManagerImpl.h | 29 ------------------- src/platform/fake/BUILD.gn | 1 - .../fake/ConfigurationManagerImpl.cpp | 29 ------------------- src/platform/fake/ConfigurationManagerImpl.h | 29 ++++--------------- .../mbed/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/mbed/ConfigurationManagerImpl.h | 29 ------------------- .../k32w/k32w0/ConfigurationManagerImpl.cpp | 14 +++++++-- .../nxp/k32w/k32w0/ConfigurationManagerImpl.h | 29 ------------------- src/platform/qpg/ConfigurationManagerImpl.cpp | 14 +++++++-- src/platform/qpg/ConfigurationManagerImpl.h | 29 ------------------- 30 files changed, 167 insertions(+), 463 deletions(-) delete mode 100644 src/platform/fake/ConfigurationManagerImpl.cpp diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 579250666a6254..88cf64a68cd666 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -151,20 +151,18 @@ class ConfigurationManager }; /** - * Returns a reference to the public interface of the ConfigurationManager singleton object. + * Returns a reference to a ConfigurationManager object. * - * chip application should use this to access features of the ConfigurationManager object - * that are common to all platforms. + * Applications should use this to access the features of the ConfigurationManager. */ extern ConfigurationManager & ConfigurationMgr(); /** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. + * Sets a reference to a ConfigurationManager object. * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the selected platform. + * This must be called before any calls to ConfigurationMgr. */ -extern ConfigurationManagerImpl & ConfigurationMgrImpl(); +extern void SetConfigurationMgr(ConfigurationManager & configurationManager); } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index 6109380ba61ae3..2d13bd48a0bdba 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -36,9 +36,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/Ameba/ConfigurationManagerImpl.h b/src/platform/Ameba/ConfigurationManagerImpl.h index 22323887c43d05..34b73b3e1500b7 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.h +++ b/src/platform/Ameba/ConfigurationManagerImpl.h @@ -67,39 +67,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the Ameba platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp index 5bcf9057759515..d9fc8f5b5d7809 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.cpp +++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp @@ -128,9 +128,19 @@ CHIP_ERROR GetMACAddressFromInterfaces(io_iterator_t primaryInterfaceIterator, u } #endif // TARGET_OS_OSX -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/Darwin/ConfigurationManagerImpl.h b/src/platform/Darwin/ConfigurationManagerImpl.h index c2732af625b423..d45d9714b0a41f 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.h +++ b/src/platform/Darwin/ConfigurationManagerImpl.h @@ -53,36 +53,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the ESP32 platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index 506f593ef06b14..a938ad559e7cc7 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -34,9 +34,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/EFR32/ConfigurationManagerImpl.h b/src/platform/EFR32/ConfigurationManagerImpl.h index 3ee8754f8fbcb8..fc08e9eb20f2d9 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/platform/EFR32/ConfigurationManagerImpl.h @@ -55,40 +55,11 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the ESP32 platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 649f65c6c796fd..8becfc47163920 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -50,9 +50,19 @@ enum // TODO: Define a Singleton instance of CHIP Group Key Store here (#1266) -/** Singleton instance of the ConfigurationManager implementation object for the ESP32. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 2c143b90976bd3..97c2d3524365a6 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -74,39 +74,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the ESP32 platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index fde80ab6dfb5fe..1af787458c5f03 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -40,9 +40,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/Linux/ConfigurationManagerImpl.h b/src/platform/Linux/ConfigurationManagerImpl.h index e0fc2188bd7c3f..1560321734a03d 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.h +++ b/src/platform/Linux/ConfigurationManagerImpl.h @@ -68,39 +68,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr() -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the ESP32 platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl() -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/P6/ConfigurationManagerImpl.cpp b/src/platform/P6/ConfigurationManagerImpl.cpp index 7d90c3696432c4..7046842c80bfcd 100644 --- a/src/platform/P6/ConfigurationManagerImpl.cpp +++ b/src/platform/P6/ConfigurationManagerImpl.cpp @@ -36,9 +36,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object for the PSoC6. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/P6/ConfigurationManagerImpl.h b/src/platform/P6/ConfigurationManagerImpl.h index f7f136420cc5c2..f80f8d9ec4770c 100644 --- a/src/platform/P6/ConfigurationManagerImpl.h +++ b/src/platform/P6/ConfigurationManagerImpl.h @@ -56,37 +56,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the PSoC6 platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Tizen/ConfigurationManagerImpl.cpp b/src/platform/Tizen/ConfigurationManagerImpl.cpp index 5a940cadda1c5b..9a642fc2093ff5 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.cpp +++ b/src/platform/Tizen/ConfigurationManagerImpl.cpp @@ -37,9 +37,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init(void) { diff --git a/src/platform/Tizen/ConfigurationManagerImpl.h b/src/platform/Tizen/ConfigurationManagerImpl.h index 73c0002b815d33..2b4a025bf440e4 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.h +++ b/src/platform/Tizen/ConfigurationManagerImpl.h @@ -54,36 +54,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the Tizen platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index 397f9eca54fdd9..b421860b4e09c0 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp +++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp @@ -43,9 +43,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.h b/src/platform/Zephyr/ConfigurationManagerImpl.h index bad5c73cc7b4aa..1c7d2eabd14423 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.h +++ b/src/platform/Zephyr/ConfigurationManagerImpl.h @@ -54,40 +54,11 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the nRF Connect SDK platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - inline bool ConfigurationManagerImpl::CanFactoryReset() { return true; diff --git a/src/platform/android/ConfigurationManagerImpl.cpp b/src/platform/android/ConfigurationManagerImpl.cpp index 6303bb5b8e5a0f..85d94e7e8f7b2b 100644 --- a/src/platform/android/ConfigurationManagerImpl.cpp +++ b/src/platform/android/ConfigurationManagerImpl.cpp @@ -42,9 +42,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} void ConfigurationManagerImpl::InitializeWithObject(jobject managerObject) { diff --git a/src/platform/android/ConfigurationManagerImpl.h b/src/platform/android/ConfigurationManagerImpl.h index 7135deb968fcaf..4c4fcc93c00a54 100644 --- a/src/platform/android/ConfigurationManagerImpl.h +++ b/src/platform/android/ConfigurationManagerImpl.h @@ -64,13 +64,6 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); @@ -78,27 +71,5 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana jobject mConfigurationManagerObject = nullptr; }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr() -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the Android platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl() -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp index e2048bde305401..e46e008a7eead3 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp @@ -54,9 +54,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h index b892304ad70227..a1c0d2d3afa4d4 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h @@ -52,40 +52,11 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the CC1352 SoC - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; diff --git a/src/platform/fake/BUILD.gn b/src/platform/fake/BUILD.gn index 9c4d008f11300f..93d4425e604f66 100644 --- a/src/platform/fake/BUILD.gn +++ b/src/platform/fake/BUILD.gn @@ -21,7 +21,6 @@ assert(chip_device_platform == "fake") static_library("fake") { sources = [ "CHIPDevicePlatformEvent.h", - "ConfigurationManagerImpl.cpp", "ConfigurationManagerImpl.h", "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", diff --git a/src/platform/fake/ConfigurationManagerImpl.cpp b/src/platform/fake/ConfigurationManagerImpl.cpp deleted file mode 100644 index f0176a55738348..00000000000000 --- a/src/platform/fake/ConfigurationManagerImpl.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * All rights reserved. - * - * 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. - */ - -#include - -namespace chip { -namespace DeviceLayer { - -/** Singleton instance of the ConfigurationManager implementation object. - */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; - -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index af8ac5c6c2bbfb..c3cbb5835c3fe0 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -27,6 +27,7 @@ namespace DeviceLayer { */ class ConfigurationManagerImpl final : public ConfigurationManager { +public: virtual ~ConfigurationManagerImpl() = default; private: @@ -96,35 +97,15 @@ class ConfigurationManagerImpl final : public ConfigurationManager } // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) +ConfigurationManager & ConfigurationMgr() { - return ConfigurationManagerImpl::sInstance; + static ConfigurationManagerImpl sInstance; + return sInstance; } -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the ESP32 platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} +void SetConfigurationMgr(ConfigurationManagerImpl & configurationManager) {} } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/mbed/ConfigurationManagerImpl.cpp b/src/platform/mbed/ConfigurationManagerImpl.cpp index f6e7c387c05dfe..b919c525861cbe 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.cpp +++ b/src/platform/mbed/ConfigurationManagerImpl.cpp @@ -42,9 +42,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/mbed/ConfigurationManagerImpl.h b/src/platform/mbed/ConfigurationManagerImpl.h index ca60444f3c0f5f..215aa22bf10232 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.h +++ b/src/platform/mbed/ConfigurationManagerImpl.h @@ -53,39 +53,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the nRF Connect SDK platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp index a5bbaffcecd011..d631f2d798f899 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp @@ -39,9 +39,19 @@ using namespace ::chip::DeviceLayer::Internal; // TODO: Define a Singleton instance of CHIP Group Key Store here -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h index 14ea2c923f8d3b..fe6f2b45d63687 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h @@ -55,40 +55,11 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * Chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * Chio applications can use this to gain access to features of the ConfigurationManager - * that are specific to the K32W platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; diff --git a/src/platform/qpg/ConfigurationManagerImpl.cpp b/src/platform/qpg/ConfigurationManagerImpl.cpp index 5a85e537c6be5c..3765e1e6d36634 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.cpp +++ b/src/platform/qpg/ConfigurationManagerImpl.cpp @@ -41,9 +41,19 @@ namespace DeviceLayer { using namespace ::chip::DeviceLayer::Internal; -/** Singleton instance of the ConfigurationManager implementation object. +/** Singleton pointer to the ConfigurationManager implementation. */ -ConfigurationManagerImpl ConfigurationManagerImpl::sInstance; +ConfigurationManager * gInstance; + +ConfigurationManager & ConfigurationMgr() +{ + return *gInstance; +} + +void SetConfigurationMgr(ConfigurationManager & configurationManager) +{ + gInstance = &configurationManager; +} CHIP_ERROR ConfigurationManagerImpl::Init() { diff --git a/src/platform/qpg/ConfigurationManagerImpl.h b/src/platform/qpg/ConfigurationManagerImpl.h index b3e57733347a67..f5661e47c5bd5b 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.h +++ b/src/platform/qpg/ConfigurationManagerImpl.h @@ -53,40 +53,11 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. - // ===== Members for internal use by the following friends. - - friend ConfigurationManager & ConfigurationMgr(void); - friend ConfigurationManagerImpl & ConfigurationMgrImpl(void); - - static ConfigurationManagerImpl sInstance; - // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); }; -/** - * Returns the public interface of the ConfigurationManager singleton object. - * - * chip applications should use this to access features of the ConfigurationManager object - * that are common to all platforms. - */ -inline ConfigurationManager & ConfigurationMgr(void) -{ - return ConfigurationManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the ConfigurationManager singleton object. - * - * chip applications can use this to gain access to features of the ConfigurationManager - * that are specific to the platform. - */ -inline ConfigurationManagerImpl & ConfigurationMgrImpl(void) -{ - return ConfigurationManagerImpl::sInstance; -} - inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; From f18578c3767eb9025dfbabee75ea30d0395f3a59 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Fri, 29 Oct 2021 16:02:37 -0400 Subject: [PATCH 02/10] Remove uses of ConfigurationMgrImpl. Promote the reboot count, boot reason, and operational hours methods to the ConfigurationManager interface. --- src/include/platform/ConfigurationManager.h | 6 ++++ .../GenericConfigurationManagerImpl.cpp | 36 +++++++++++++++++++ .../GenericConfigurationManagerImpl.h | 6 ++++ src/platform/ESP32/ConfigurationManagerImpl.h | 8 ++--- src/platform/ESP32/PlatformManagerImpl.cpp | 8 ++--- src/platform/Linux/ConfigurationManagerImpl.h | 12 +++---- src/platform/Linux/PlatformManagerImpl.cpp | 22 ++++++------ .../android/AndroidChipPlatform-JNI.cpp | 6 +++- src/platform/fake/ConfigurationManagerImpl.h | 6 ++++ 9 files changed, 84 insertions(+), 26 deletions(-) diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 88cf64a68cd666..42c641c5b5d526 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -100,6 +100,12 @@ class ConfigurationManager virtual CHIP_ERROR StoreRegulatoryLocation(uint32_t location) = 0; virtual CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) = 0; virtual CHIP_ERROR StoreBreadcrumb(uint64_t breadcrumb) = 0; + virtual CHIP_ERROR GetRebootCount(uint32_t & rebootCount) = 0; + virtual CHIP_ERROR StoreRebootCount(uint32_t rebootCount) = 0; + virtual CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) = 0; + virtual CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) = 0; + virtual CHIP_ERROR GetBootReasons(uint32_t & bootReasons) = 0; + virtual CHIP_ERROR StoreBootReasons(uint32_t bootReasons) = 0; virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp index ae9068179d7e11..ef8f91f08742eb 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp @@ -343,6 +343,42 @@ CHIP_ERROR GenericConfigurationManagerImpl::StoreBreadcrumb(uint64_t return Impl()->WriteConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb); } +template +CHIP_ERROR GenericConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::GetBootReasons(uint32_t & bootReasons) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreBootReasons(uint32_t bootReasons) +{ + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +} + #if CHIP_ENABLE_ROTATING_DEVICE_ID template CHIP_ERROR GenericConfigurationManagerImpl::GetLifetimeCounter(uint16_t & lifetimeCounter) diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index 380b9540d0f86f..42a64c7781a32f 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -97,6 +97,12 @@ class GenericConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) override; CHIP_ERROR GetBreadcrumb(uint64_t & breadcrumb) override; CHIP_ERROR StoreBreadcrumb(uint64_t breadcrumb) override; + CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; + CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; + CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; + CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; + CHIP_ERROR GetBootReasons(uint32_t & bootReasons) override; + CHIP_ERROR StoreBootReasons(uint32_t bootReasons) override; #if !defined(NDEBUG) CHIP_ERROR RunUnitTests(void) override; #endif diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 97c2d3524365a6..abdbabfc089cd3 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -50,10 +50,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana private Internal::ESP32Config { public: - CHIP_ERROR GetRebootCount(uint32_t & rebootCount); - CHIP_ERROR StoreRebootCount(uint32_t rebootCount); - CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours); - CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours); + CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; + CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; + CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; + CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; private: // Allow the GenericConfigurationManagerImpl base class to access helper methods and types diff --git a/src/platform/ESP32/PlatformManagerImpl.cpp b/src/platform/ESP32/PlatformManagerImpl.cpp index 9236f51ee98d4a..202099931e4a90 100644 --- a/src/platform/ESP32/PlatformManagerImpl.cpp +++ b/src/platform/ESP32/PlatformManagerImpl.cpp @@ -131,9 +131,9 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() { uint32_t totalOperationalHours = 0; - if (ConfigurationMgrImpl().GetTotalOperationalHours(totalOperationalHours) == CHIP_NO_ERROR) + if (ConfigurationMgr().GetTotalOperationalHours(totalOperationalHours) == CHIP_NO_ERROR) { - ConfigurationMgrImpl().StoreTotalOperationalHours(totalOperationalHours + static_cast(upTime / 3600)); + ConfigurationMgr().StoreTotalOperationalHours(totalOperationalHours + static_cast(upTime / 3600)); } else { @@ -170,7 +170,7 @@ CHIP_ERROR PlatformManagerImpl::_GetRebootCount(uint16_t & rebootCount) { uint32_t count = 0; - CHIP_ERROR err = ConfigurationMgrImpl().GetRebootCount(count); + CHIP_ERROR err = ConfigurationMgr().GetRebootCount(count); if (err == CHIP_NO_ERROR) { @@ -201,7 +201,7 @@ CHIP_ERROR PlatformManagerImpl::_GetTotalOperationalHours(uint32_t & totalOperat if (_GetUpTime(upTime) == CHIP_NO_ERROR) { uint32_t totalHours = 0; - if (ConfigurationMgrImpl().GetTotalOperationalHours(totalHours) == CHIP_NO_ERROR) + if (ConfigurationMgr().GetTotalOperationalHours(totalHours) == CHIP_NO_ERROR) { VerifyOrReturnError(upTime / 3600 <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); totalOperationalHours = totalHours + static_cast(upTime / 3600); diff --git a/src/platform/Linux/ConfigurationManagerImpl.h b/src/platform/Linux/ConfigurationManagerImpl.h index 1560321734a03d..f4c6aaf221115e 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.h +++ b/src/platform/Linux/ConfigurationManagerImpl.h @@ -38,12 +38,12 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana private Internal::PosixConfig { public: - CHIP_ERROR GetRebootCount(uint32_t & rebootCount); - CHIP_ERROR StoreRebootCount(uint32_t rebootCount); - CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours); - CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours); - CHIP_ERROR GetBootReasons(uint32_t & bootReasons); - CHIP_ERROR StoreBootReasons(uint32_t bootReasons); + CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; + CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; + CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; + CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; + CHIP_ERROR GetBootReasons(uint32_t & bootReasons) override; + CHIP_ERROR StoreBootReasons(uint32_t bootReasons) override; private: // Allow the GenericConfigurationManagerImpl base class to access helper methods and types diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index a4231fa396d4b6..ab9ae6ff283fd2 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -60,27 +60,27 @@ void SignalHandler(int signum) switch (signum) { case SIGINT: - ConfigurationMgrImpl().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_RESET); + ConfigurationMgr().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_RESET); err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED; break; case SIGHUP: - ConfigurationMgrImpl().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_BROWN_OUT_RESET); + ConfigurationMgr().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_BROWN_OUT_RESET); err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED; break; case SIGTERM: - ConfigurationMgrImpl().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_POWER_ON_REBOOT); + ConfigurationMgr().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_POWER_ON_REBOOT); err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED; break; case SIGUSR1: - ConfigurationMgrImpl().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_HARDWARE_WATCHDOG_RESET); + ConfigurationMgr().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_HARDWARE_WATCHDOG_RESET); err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED; break; case SIGUSR2: - ConfigurationMgrImpl().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_WATCHDOG_RESET); + ConfigurationMgr().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_WATCHDOG_RESET); err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED; break; case SIGTSTP: - ConfigurationMgrImpl().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_UPDATE_COMPLETED); + ConfigurationMgr().StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_UPDATE_COMPLETED); err = CHIP_ERROR_REBOOT_SIGNAL_RECEIVED; break; default: @@ -230,9 +230,9 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() { uint32_t totalOperationalHours = 0; - if (ConfigurationMgrImpl().GetTotalOperationalHours(totalOperationalHours) == CHIP_NO_ERROR) + if (ConfigurationMgr().GetTotalOperationalHours(totalOperationalHours) == CHIP_NO_ERROR) { - ConfigurationMgrImpl().StoreTotalOperationalHours(totalOperationalHours + static_cast(upTime / 3600)); + ConfigurationMgr().StoreTotalOperationalHours(totalOperationalHours + static_cast(upTime / 3600)); } else { @@ -289,7 +289,7 @@ CHIP_ERROR PlatformManagerImpl::_GetRebootCount(uint16_t & rebootCount) { uint32_t count = 0; - CHIP_ERROR err = ConfigurationMgrImpl().GetRebootCount(count); + CHIP_ERROR err = ConfigurationMgr().GetRebootCount(count); if (err == CHIP_NO_ERROR) { @@ -320,7 +320,7 @@ CHIP_ERROR PlatformManagerImpl::_GetTotalOperationalHours(uint32_t & totalOperat if (_GetUpTime(upTime) == CHIP_NO_ERROR) { uint32_t totalHours = 0; - if (ConfigurationMgrImpl().GetTotalOperationalHours(totalHours) == CHIP_NO_ERROR) + if (ConfigurationMgr().GetTotalOperationalHours(totalHours) == CHIP_NO_ERROR) { VerifyOrReturnError(upTime / 3600 <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); totalOperationalHours = totalHours + static_cast(upTime / 3600); @@ -334,7 +334,7 @@ CHIP_ERROR PlatformManagerImpl::_GetBootReasons(uint8_t & bootReasons) { uint32_t reason = 0; - CHIP_ERROR err = ConfigurationMgrImpl().GetBootReasons(reason); + CHIP_ERROR err = ConfigurationMgr().GetBootReasons(reason); if (err == CHIP_NO_ERROR) { diff --git a/src/platform/android/AndroidChipPlatform-JNI.cpp b/src/platform/android/AndroidChipPlatform-JNI.cpp index 785ed89cb42638..f06ab44fd046b7 100644 --- a/src/platform/android/AndroidChipPlatform-JNI.cpp +++ b/src/platform/android/AndroidChipPlatform-JNI.cpp @@ -207,7 +207,11 @@ JNI_METHOD(void, setKeyValueStoreManager)(JNIEnv * env, jclass self, jobject man JNI_METHOD(void, setConfigurationManager)(JNIEnv * env, jclass self, jobject manager) { chip::DeviceLayer::StackLock lock; - chip::DeviceLayer::ConfigurationMgrImpl().InitializeWithObject(manager); + chip::DeviceLayer::ConfigurationManagerImpl * configurationManagerImpl = + reinterpret_cast(&chip::DeviceLayer::ConfigurationMgr()); + if (configurationManagerImpl != nullptr) { + configurationManagerImpl->InitializeWithObject(manager); + } } // for ServiceResolver diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index c3cbb5835c3fe0..08b31933e74587 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -80,6 +80,12 @@ class ConfigurationManagerImpl final : public ConfigurationManager CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetBreadcrumb(uint64_t & breadcrumb) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StoreBreadcrumb(uint64_t breadcrumb) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetBootReasons(uint32_t & bootReasons) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR StoreBootReasons(uint32_t bootReasons) override { return CHIP_ERROR_NOT_IMPLEMENTED; } #if !defined(NDEBUG) CHIP_ERROR RunUnitTests(void) override { return CHIP_ERROR_NOT_IMPLEMENTED; } #endif From f0a3630754b2c550e50ba4550aec87f0fc7caf5c Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Fri, 29 Oct 2021 15:33:00 -0400 Subject: [PATCH 03/10] Add a static instance getter to the ConfigurationManagerImpl. --- src/platform/Ameba/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/Ameba/ConfigurationManagerImpl.h | 5 +++++ src/platform/Darwin/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/Darwin/ConfigurationManagerImpl.h | 4 ++++ src/platform/EFR32/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/EFR32/ConfigurationManagerImpl.h | 4 ++++ src/platform/ESP32/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/ESP32/ConfigurationManagerImpl.h | 1 + src/platform/Linux/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/Linux/ConfigurationManagerImpl.h | 1 + src/platform/P6/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/P6/ConfigurationManagerImpl.h | 4 ++++ src/platform/Tizen/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/Tizen/ConfigurationManagerImpl.h | 4 ++++ src/platform/Zephyr/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/Zephyr/ConfigurationManagerImpl.h | 4 ++++ src/platform/android/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/android/ConfigurationManagerImpl.h | 1 + src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/cc13x2_26x2/ConfigurationManagerImpl.h | 4 ++++ src/platform/mbed/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/mbed/ConfigurationManagerImpl.h | 4 ++++ src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h | 4 ++++ src/platform/qpg/ConfigurationManagerImpl.cpp | 6 ++++++ src/platform/qpg/ConfigurationManagerImpl.h | 4 ++++ 26 files changed, 122 insertions(+) diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index 2d13bd48a0bdba..a053a561f6cbf1 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -50,6 +50,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/Ameba/ConfigurationManagerImpl.h b/src/platform/Ameba/ConfigurationManagerImpl.h index 34b73b3e1500b7..0ce2f381764275 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.h +++ b/src/platform/Ameba/ConfigurationManagerImpl.h @@ -50,6 +50,11 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // the implementation methods provided by this class. friend class ConfigurationManager; +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + +private: // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp index d9fc8f5b5d7809..9be47867141687 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.cpp +++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp @@ -142,6 +142,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/Darwin/ConfigurationManagerImpl.h b/src/platform/Darwin/ConfigurationManagerImpl.h index d45d9714b0a41f..c3177ec5808335 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.h +++ b/src/platform/Darwin/ConfigurationManagerImpl.h @@ -42,6 +42,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index a938ad559e7cc7..2d54c2aa0431e4 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -48,6 +48,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/EFR32/ConfigurationManagerImpl.h b/src/platform/EFR32/ConfigurationManagerImpl.h index fc08e9eb20f2d9..438d9683308bdc 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/platform/EFR32/ConfigurationManagerImpl.h @@ -43,6 +43,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 8becfc47163920..cdc251d76cea32 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -64,6 +64,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index abdbabfc089cd3..8cc6904ced1844 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -54,6 +54,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; + static ConfigurationManagerImpl & GetDefaultInstance(); private: // Allow the GenericConfigurationManagerImpl base class to access helper methods and types diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index 1af787458c5f03..a04c2eeff2af17 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -54,6 +54,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/Linux/ConfigurationManagerImpl.h b/src/platform/Linux/ConfigurationManagerImpl.h index f4c6aaf221115e..39355ef1415d0c 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.h +++ b/src/platform/Linux/ConfigurationManagerImpl.h @@ -44,6 +44,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; CHIP_ERROR GetBootReasons(uint32_t & bootReasons) override; CHIP_ERROR StoreBootReasons(uint32_t bootReasons) override; + static ConfigurationManagerImpl & GetDefaultInstance(); private: // Allow the GenericConfigurationManagerImpl base class to access helper methods and types diff --git a/src/platform/P6/ConfigurationManagerImpl.cpp b/src/platform/P6/ConfigurationManagerImpl.cpp index 7046842c80bfcd..4311d5a0239a36 100644 --- a/src/platform/P6/ConfigurationManagerImpl.cpp +++ b/src/platform/P6/ConfigurationManagerImpl.cpp @@ -50,6 +50,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/platform/P6/ConfigurationManagerImpl.h b/src/platform/P6/ConfigurationManagerImpl.h index f80f8d9ec4770c..0e84ede105bcda 100644 --- a/src/platform/P6/ConfigurationManagerImpl.h +++ b/src/platform/P6/ConfigurationManagerImpl.h @@ -44,6 +44,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/Tizen/ConfigurationManagerImpl.cpp b/src/platform/Tizen/ConfigurationManagerImpl.cpp index 9a642fc2093ff5..1f8715b7611a0f 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.cpp +++ b/src/platform/Tizen/ConfigurationManagerImpl.cpp @@ -51,6 +51,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init(void) { return Internal::GenericConfigurationManagerImpl::Init(); diff --git a/src/platform/Tizen/ConfigurationManagerImpl.h b/src/platform/Tizen/ConfigurationManagerImpl.h index 2b4a025bf440e4..6b8c8ce4d5faf7 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.h +++ b/src/platform/Tizen/ConfigurationManagerImpl.h @@ -43,6 +43,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index b421860b4e09c0..9befd41bd52793 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp +++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp @@ -57,6 +57,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.h b/src/platform/Zephyr/ConfigurationManagerImpl.h index 1c7d2eabd14423..6781fc2d561a28 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.h +++ b/src/platform/Zephyr/ConfigurationManagerImpl.h @@ -42,6 +42,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/android/ConfigurationManagerImpl.cpp b/src/platform/android/ConfigurationManagerImpl.cpp index 85d94e7e8f7b2b..c61a375fd0589e 100644 --- a/src/platform/android/ConfigurationManagerImpl.cpp +++ b/src/platform/android/ConfigurationManagerImpl.cpp @@ -56,6 +56,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + void ConfigurationManagerImpl::InitializeWithObject(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); diff --git a/src/platform/android/ConfigurationManagerImpl.h b/src/platform/android/ConfigurationManagerImpl.h index 4c4fcc93c00a54..a785a9997a0ea8 100644 --- a/src/platform/android/ConfigurationManagerImpl.h +++ b/src/platform/android/ConfigurationManagerImpl.h @@ -46,6 +46,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana public: void InitializeWithObject(jobject managerObject); + static ConfigurationManagerImpl & GetDefaultInstance(); private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp index e46e008a7eead3..601a540e438aff 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp @@ -68,6 +68,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h index a1c0d2d3afa4d4..c07ad7ada33868 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h @@ -40,6 +40,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // defined on this class. friend class Internal::GenericConfigurationManagerImpl; +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/mbed/ConfigurationManagerImpl.cpp b/src/platform/mbed/ConfigurationManagerImpl.cpp index b919c525861cbe..01ea9324724828 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.cpp +++ b/src/platform/mbed/ConfigurationManagerImpl.cpp @@ -56,6 +56,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { return CHIP_NO_ERROR; diff --git a/src/platform/mbed/ConfigurationManagerImpl.h b/src/platform/mbed/ConfigurationManagerImpl.h index 215aa22bf10232..9e8173a01633ac 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.h +++ b/src/platform/mbed/ConfigurationManagerImpl.h @@ -41,6 +41,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp index d631f2d798f899..34333af3a24815 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp @@ -53,6 +53,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h index fe6f2b45d63687..c6443c52e6c798 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h @@ -43,6 +43,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. diff --git a/src/platform/qpg/ConfigurationManagerImpl.cpp b/src/platform/qpg/ConfigurationManagerImpl.cpp index 3765e1e6d36634..9f5caffb21431e 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.cpp +++ b/src/platform/qpg/ConfigurationManagerImpl.cpp @@ -55,6 +55,12 @@ void SetConfigurationMgr(ConfigurationManager & configurationManager) gInstance = &configurationManager; } +ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() +{ + static ConfigurationManagerImpl sInstance; + return sInstance; +} + CHIP_ERROR ConfigurationManagerImpl::Init() { CHIP_ERROR err; diff --git a/src/platform/qpg/ConfigurationManagerImpl.h b/src/platform/qpg/ConfigurationManagerImpl.h index f5661e47c5bd5b..d07c46746c4f84 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.h +++ b/src/platform/qpg/ConfigurationManagerImpl.h @@ -41,6 +41,10 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana friend class Internal::GenericConfigurationManagerImpl; #endif +public: + // This returns an instance of this class. + static ConfigurationManagerImpl & GetDefaultInstance(); + private: // ===== Members that implement the ConfigurationManager public interface. From 62036fa4a5dc013abf8066f7f0cd12126afca9f8 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Fri, 29 Oct 2021 15:33:33 -0400 Subject: [PATCH 04/10] Set the default ConfigurationManager instance in the platform manager. --- src/platform/Ameba/PlatformManagerImpl.cpp | 2 ++ src/platform/Darwin/PlatformManagerImpl.cpp | 1 + src/platform/EFR32/PlatformManagerImpl.cpp | 1 + src/platform/ESP32/PlatformManagerImpl.cpp | 2 ++ src/platform/Linux/PlatformManagerImpl.cpp | 1 + src/platform/P6/PlatformManagerImpl.cpp | 2 ++ src/platform/Tizen/PlatformManagerImpl.cpp | 1 + src/platform/Zephyr/PlatformManagerImpl.cpp | 1 + src/platform/android/PlatformManagerImpl.cpp | 1 + src/platform/cc13x2_26x2/PlatformManagerImpl.cpp | 1 + src/platform/mbed/PlatformManagerImpl.cpp | 2 ++ src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp | 1 + src/platform/qpg/PlatformManagerImpl.cpp | 1 + 13 files changed, 17 insertions(+) diff --git a/src/platform/Ameba/PlatformManagerImpl.cpp b/src/platform/Ameba/PlatformManagerImpl.cpp index 0eaf536fdee771..0d71ab8481d4fa 100644 --- a/src/platform/Ameba/PlatformManagerImpl.cpp +++ b/src/platform/Ameba/PlatformManagerImpl.cpp @@ -57,6 +57,8 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) CHIP_ERROR err; + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + // Make sure the LwIP core lock has been initialized err = Internal::InitLwIPCoreLock(); diff --git a/src/platform/Darwin/PlatformManagerImpl.cpp b/src/platform/Darwin/PlatformManagerImpl.cpp index 348ef48a21221a..8d5c2a996e9f03 100644 --- a/src/platform/Darwin/PlatformManagerImpl.cpp +++ b/src/platform/Darwin/PlatformManagerImpl.cpp @@ -43,6 +43,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() // Initialize the configuration system. err = Internal::PosixConfig::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); mRunLoopSem = dispatch_semaphore_create(0); diff --git a/src/platform/EFR32/PlatformManagerImpl.cpp b/src/platform/EFR32/PlatformManagerImpl.cpp index 61fe7b2954489d..974977b96de7a8 100644 --- a/src/platform/EFR32/PlatformManagerImpl.cpp +++ b/src/platform/EFR32/PlatformManagerImpl.cpp @@ -44,6 +44,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::EFR32Config::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); // Initialize LwIP. tcpip_init(NULL, NULL); diff --git a/src/platform/ESP32/PlatformManagerImpl.cpp b/src/platform/ESP32/PlatformManagerImpl.cpp index 202099931e4a90..f12557687ae31c 100644 --- a/src/platform/ESP32/PlatformManagerImpl.cpp +++ b/src/platform/ESP32/PlatformManagerImpl.cpp @@ -57,6 +57,8 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + esp_err_t err; // Arrange for CHIP-encapsulated ESP32 errors to be translated to text Internal::ESP32Utils::RegisterESP32ErrorFormatter(); diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index ab9ae6ff283fd2..2fa906fbeff837 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -209,6 +209,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() // Initialize the configuration system. err = Internal::PosixConfig::Init(); SuccessOrExit(err); + 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/PlatformManagerImpl.cpp b/src/platform/P6/PlatformManagerImpl.cpp index 168cc7560231c1..2d81d3a0fcb931 100644 --- a/src/platform/P6/PlatformManagerImpl.cpp +++ b/src/platform/P6/PlatformManagerImpl.cpp @@ -42,6 +42,8 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { CHIP_ERROR err; + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + // Make sure the LwIP core lock has been initialized err = Internal::InitLwIPCoreLock(); SuccessOrExit(err); diff --git a/src/platform/Tizen/PlatformManagerImpl.cpp b/src/platform/Tizen/PlatformManagerImpl.cpp index f4a1dc50d08328..c1e12a8a54b5ae 100644 --- a/src/platform/Tizen/PlatformManagerImpl.cpp +++ b/src/platform/Tizen/PlatformManagerImpl.cpp @@ -36,6 +36,7 @@ PlatformManagerImpl PlatformManagerImpl::sInstance; CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { ReturnErrorOnFailure(Internal::PosixConfig::Init()); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); return Internal::GenericPlatformManagerImpl_POSIX::_InitChipStack(); } diff --git a/src/platform/Zephyr/PlatformManagerImpl.cpp b/src/platform/Zephyr/PlatformManagerImpl.cpp index 6ced08cff90f32..37658d807bbf19 100644 --- a/src/platform/Zephyr/PlatformManagerImpl.cpp +++ b/src/platform/Zephyr/PlatformManagerImpl.cpp @@ -72,6 +72,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::ZephyrConfig::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); #if !CONFIG_NORDIC_SECURITY_BACKEND // Add entropy source based on Zephyr entropy driver diff --git a/src/platform/android/PlatformManagerImpl.cpp b/src/platform/android/PlatformManagerImpl.cpp index 21b3509807426e..fb6b7c1ae1c577 100644 --- a/src/platform/android/PlatformManagerImpl.cpp +++ b/src/platform/android/PlatformManagerImpl.cpp @@ -43,6 +43,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() // Initialize the configuration system. err = Internal::AndroidConfig::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); // Call _InitChipStack() on the generic implementation base class // to finish the initialization process. diff --git a/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp b/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp index dea57bed5800b5..003b75aa62af82 100644 --- a/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/PlatformManagerImpl.cpp @@ -106,6 +106,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::CC13X2_26X2Config::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); // DMM Addition DMMPolicy_Params dmmPolicyParams; diff --git a/src/platform/mbed/PlatformManagerImpl.cpp b/src/platform/mbed/PlatformManagerImpl.cpp index 0dc462ccca1659..e30a8110637a7e 100644 --- a/src/platform/mbed/PlatformManagerImpl.cpp +++ b/src/platform/mbed/PlatformManagerImpl.cpp @@ -91,6 +91,8 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) tcpip_init(NULL, NULL); #endif + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); + // Call up to the base class _InitChipStack() to perform the bulk of the initialization. auto err = GenericPlatformManagerImpl::_InitChipStack(); SuccessOrExit(err); diff --git a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp index cfcc6ad007e264..ca147fb76c39a0 100644 --- a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp @@ -58,6 +58,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::K32WConfig::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); // Initialize LwIP. tcpip_init(NULL, NULL); diff --git a/src/platform/qpg/PlatformManagerImpl.cpp b/src/platform/qpg/PlatformManagerImpl.cpp index 4397237f528d13..f64b790dada37a 100644 --- a/src/platform/qpg/PlatformManagerImpl.cpp +++ b/src/platform/qpg/PlatformManagerImpl.cpp @@ -40,6 +40,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) // Initialize the configuration system. err = Internal::QPGConfig::Init(); SuccessOrExit(err); + SetConfigurationMgr(ConfigurationManagerImpl::GetDefaultInstance()); // Initialize LwIP. tcpip_init(NULL, NULL); From 62ddf5cf5960c7897f839e9d46b075ca5226ba41 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Fri, 29 Oct 2021 15:32:28 -0400 Subject: [PATCH 05/10] Update the tests to set a ConfigurationManager instance. --- src/controller/tests/TestDevice.cpp | 2 ++ src/transport/raw/tests/NetworkTestHelpers.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/controller/tests/TestDevice.cpp b/src/controller/tests/TestDevice.cpp index 5e6bd910246b3d..8521471761c82c 100644 --- a/src/controller/tests/TestDevice.cpp +++ b/src/controller/tests/TestDevice.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ using TestTransportMgr = TransportMgr; void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext) { Platform::MemoryInit(); + chip::DeviceLayer::SetConfigurationMgr(chip::DeviceLayer::ConfigurationManagerImpl::GetDefaultInstance()); DeviceTransportMgr transportMgr; SessionManager sessionManager; ExchangeManager exchangeMgr; diff --git a/src/transport/raw/tests/NetworkTestHelpers.cpp b/src/transport/raw/tests/NetworkTestHelpers.cpp index f4a9ab18ea8305..8a2002e75edcdd 100644 --- a/src/transport/raw/tests/NetworkTestHelpers.cpp +++ b/src/transport/raw/tests/NetworkTestHelpers.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace chip { namespace Test { @@ -29,6 +30,7 @@ namespace Test { CHIP_ERROR IOContext::Init() { CHIP_ERROR err = Platform::MemoryInit(); + chip::DeviceLayer::SetConfigurationMgr(chip::DeviceLayer::ConfigurationManagerImpl::GetDefaultInstance()); gSystemLayer.Init(); From c89a32ee7603bf5a178b469fac61bd0471cd48ac Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Wed, 27 Oct 2021 15:45:50 -0400 Subject: [PATCH 06/10] Allow subclasses of the platform ConfigurationManagerImpls. --- src/platform/Ameba/ConfigurationManagerImpl.h | 4 ++-- src/platform/Darwin/ConfigurationManagerImpl.h | 4 ++-- src/platform/EFR32/ConfigurationManagerImpl.h | 4 ++-- src/platform/ESP32/ConfigurationManagerImpl.h | 8 ++++---- src/platform/Linux/ConfigurationManagerImpl.h | 4 ++-- src/platform/P6/ConfigurationManagerImpl.h | 4 ++-- src/platform/Tizen/ConfigurationManagerImpl.h | 4 ++-- src/platform/Zephyr/ConfigurationManagerImpl.h | 4 ++-- src/platform/android/ConfigurationManagerImpl.h | 4 ++-- src/platform/cc13x2_26x2/ConfigurationManagerImpl.h | 4 ++-- src/platform/fake/ConfigurationManagerImpl.h | 2 +- src/platform/mbed/ConfigurationManagerImpl.h | 4 ++-- src/platform/qpg/ConfigurationManagerImpl.h | 4 ++-- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/platform/Ameba/ConfigurationManagerImpl.h b/src/platform/Ameba/ConfigurationManagerImpl.h index 0ce2f381764275..13068895ff654f 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.h +++ b/src/platform/Ameba/ConfigurationManagerImpl.h @@ -34,8 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Ameba platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::AmebaConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::AmebaConfig { public: CHIP_ERROR GetRebootCount(uint32_t & rebootCount); diff --git a/src/platform/Darwin/ConfigurationManagerImpl.h b/src/platform/Darwin/ConfigurationManagerImpl.h index c3177ec5808335..193155cbc3cf9f 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.h +++ b/src/platform/Darwin/ConfigurationManagerImpl.h @@ -33,8 +33,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Darwin platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::PosixConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::PosixConfig { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/EFR32/ConfigurationManagerImpl.h b/src/platform/EFR32/ConfigurationManagerImpl.h index 438d9683308bdc..5e88832e761076 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/platform/EFR32/ConfigurationManagerImpl.h @@ -34,8 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the EFR32 platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::EFR32Config +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::EFR32Config { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 8cc6904ced1844..445783f05e15ac 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -41,13 +41,13 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the ESP32 platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - public Internal::GenericConnectivityManagerImpl_BLE, + public Internal::GenericConnectivityManagerImpl_BLE, #else - public Internal::GenericConnectivityManagerImpl_NoBLE, + public Internal::GenericConnectivityManagerImpl_NoBLE, #endif - private Internal::ESP32Config + private Internal::ESP32Config { public: CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; diff --git a/src/platform/Linux/ConfigurationManagerImpl.h b/src/platform/Linux/ConfigurationManagerImpl.h index 39355ef1415d0c..2ce06c5b213655 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.h +++ b/src/platform/Linux/ConfigurationManagerImpl.h @@ -34,8 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Linux platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::PosixConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::PosixConfig { public: CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; diff --git a/src/platform/P6/ConfigurationManagerImpl.h b/src/platform/P6/ConfigurationManagerImpl.h index 0e84ede105bcda..da07d8d4904212 100644 --- a/src/platform/P6/ConfigurationManagerImpl.h +++ b/src/platform/P6/ConfigurationManagerImpl.h @@ -35,8 +35,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the PSoC6 platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::P6Config +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::P6Config { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/Tizen/ConfigurationManagerImpl.h b/src/platform/Tizen/ConfigurationManagerImpl.h index 6b8c8ce4d5faf7..88fb2d7001c969 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.h +++ b/src/platform/Tizen/ConfigurationManagerImpl.h @@ -34,8 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Tizen platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::PosixConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::PosixConfig { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.h b/src/platform/Zephyr/ConfigurationManagerImpl.h index 6781fc2d561a28..92a8aff3c5771e 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.h +++ b/src/platform/Zephyr/ConfigurationManagerImpl.h @@ -33,8 +33,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Zephyr platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::ZephyrConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::ZephyrConfig { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/android/ConfigurationManagerImpl.h b/src/platform/android/ConfigurationManagerImpl.h index a785a9997a0ea8..91b048cb3301af 100644 --- a/src/platform/android/ConfigurationManagerImpl.h +++ b/src/platform/android/ConfigurationManagerImpl.h @@ -35,8 +35,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Android platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::AndroidConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::AndroidConfig { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h index c07ad7ada33868..febdb5d11adfb7 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h @@ -33,8 +33,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the CC13X2_26X2 platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::CC13X2_26X2Config +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::CC13X2_26X2Config { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index 08b31933e74587..4edc14e7ccc51d 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -25,7 +25,7 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the fake platform. */ -class ConfigurationManagerImpl final : public ConfigurationManager +class ConfigurationManagerImpl : public ConfigurationManager { public: virtual ~ConfigurationManagerImpl() = default; diff --git a/src/platform/mbed/ConfigurationManagerImpl.h b/src/platform/mbed/ConfigurationManagerImpl.h index 9e8173a01633ac..7acc0c2ab5e068 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.h +++ b/src/platform/mbed/ConfigurationManagerImpl.h @@ -32,8 +32,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Zephyr platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::MbedConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::MbedConfig { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. diff --git a/src/platform/qpg/ConfigurationManagerImpl.h b/src/platform/qpg/ConfigurationManagerImpl.h index d07c46746c4f84..c6f08abe227850 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.h +++ b/src/platform/qpg/ConfigurationManagerImpl.h @@ -32,8 +32,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::QPGConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, + private Internal::QPGConfig { // Allow the GenericConfigurationManagerImpl base class to access helper methods and types // defined on this class. From 1e1af8b5849941d71e404326c914fe15832ef715 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Tue, 2 Nov 2021 16:40:12 -0400 Subject: [PATCH 07/10] Re-fix Ameba's ConfigurationManagerImpl. --- src/platform/Ameba/ConfigurationManagerImpl.h | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/platform/Ameba/ConfigurationManagerImpl.h b/src/platform/Ameba/ConfigurationManagerImpl.h index 13068895ff654f..c51ea2eb30175d 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.h +++ b/src/platform/Ameba/ConfigurationManagerImpl.h @@ -37,19 +37,6 @@ namespace DeviceLayer { class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, private Internal::AmebaConfig { -public: - CHIP_ERROR GetRebootCount(uint32_t & rebootCount); - CHIP_ERROR StoreRebootCount(uint32_t rebootCount); - CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours); - CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours); - CHIP_ERROR GetBootReasons(uint32_t & bootReasons); - CHIP_ERROR StoreBootReasons(uint32_t bootReasons); - -private: - // Allow the ConfigurationManager interface class to delegate method calls to - // the implementation methods provided by this class. - friend class ConfigurationManager; - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -69,6 +56,12 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp void InitiateFactoryReset(void) override; CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) override; CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; + CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; + CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; + CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; + CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; + CHIP_ERROR GetBootReasons(uint32_t & bootReasons) override; + CHIP_ERROR StoreBootReasons(uint32_t bootReasons) override; // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. From 1dea46049c2118851eda4a7be7fc731bad05f14f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Nov 2021 18:12:51 +0000 Subject: [PATCH 08/10] Restyled by clang-format --- src/platform/android/AndroidChipPlatform-JNI.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/platform/android/AndroidChipPlatform-JNI.cpp b/src/platform/android/AndroidChipPlatform-JNI.cpp index f06ab44fd046b7..fd2cbd20dd7f8b 100644 --- a/src/platform/android/AndroidChipPlatform-JNI.cpp +++ b/src/platform/android/AndroidChipPlatform-JNI.cpp @@ -208,8 +208,9 @@ JNI_METHOD(void, setConfigurationManager)(JNIEnv * env, jclass self, jobject man { chip::DeviceLayer::StackLock lock; chip::DeviceLayer::ConfigurationManagerImpl * configurationManagerImpl = - reinterpret_cast(&chip::DeviceLayer::ConfigurationMgr()); - if (configurationManagerImpl != nullptr) { + reinterpret_cast(&chip::DeviceLayer::ConfigurationMgr()); + if (configurationManagerImpl != nullptr) + { configurationManagerImpl->InitializeWithObject(manager); } } From b7986bf00a258a5a9f14140d21b22a4e3855ad80 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Tue, 9 Nov 2021 15:20:27 -0500 Subject: [PATCH 09/10] 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(); From 23d3b8f7ed47814d4c31aa96a5a466037a79b43f Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Tue, 9 Nov 2021 16:02:00 -0500 Subject: [PATCH 10/10] Update Ameba platform to remove the new uses of ConfigurationMgrImpl. --- src/platform/Ameba/PlatformManagerImpl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platform/Ameba/PlatformManagerImpl.cpp b/src/platform/Ameba/PlatformManagerImpl.cpp index 8f010e3e7a6c0e..000824271da1d2 100644 --- a/src/platform/Ameba/PlatformManagerImpl.cpp +++ b/src/platform/Ameba/PlatformManagerImpl.cpp @@ -88,9 +88,9 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() { uint32_t totalOperationalHours = 0; - if (ConfigurationMgrImpl().GetTotalOperationalHours(totalOperationalHours) == CHIP_NO_ERROR) + if (ConfigurationMgr().GetTotalOperationalHours(totalOperationalHours) == CHIP_NO_ERROR) { - ConfigurationMgrImpl().StoreTotalOperationalHours(totalOperationalHours + static_cast(upTime / 3600)); + ConfigurationMgr().StoreTotalOperationalHours(totalOperationalHours + static_cast(upTime / 3600)); } else { @@ -126,7 +126,7 @@ CHIP_ERROR PlatformManagerImpl::_GetRebootCount(uint16_t & rebootCount) { uint32_t count = 0; - CHIP_ERROR err = ConfigurationMgrImpl().GetRebootCount(count); + CHIP_ERROR err = ConfigurationMgr().GetRebootCount(count); if (err == CHIP_NO_ERROR) { @@ -157,7 +157,7 @@ CHIP_ERROR PlatformManagerImpl::_GetTotalOperationalHours(uint32_t & totalOperat if (_GetUpTime(upTime) == CHIP_NO_ERROR) { uint32_t totalHours = 0; - if (ConfigurationMgrImpl().GetTotalOperationalHours(totalHours) == CHIP_NO_ERROR) + if (ConfigurationMgr().GetTotalOperationalHours(totalHours) == CHIP_NO_ERROR) { VerifyOrReturnError(upTime / 3600 <= UINT32_MAX, CHIP_ERROR_INVALID_INTEGER_VALUE); totalOperationalHours = totalHours + static_cast(upTime / 3600); @@ -172,7 +172,7 @@ CHIP_ERROR PlatformManagerImpl::_GetBootReasons(uint8_t & bootReasons) { uint32_t reason = 0; - CHIP_ERROR err = ConfigurationMgrImpl().GetBootReasons(reason); + CHIP_ERROR err = ConfigurationMgr().GetBootReasons(reason); if (err == CHIP_NO_ERROR) {