From 2143ea565e7c5015eeb6661e024503117c372866 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Wed, 17 Nov 2021 10:17:50 -0500 Subject: [PATCH] Remove GenericConfigurationManagerImpl's CRTP (#11784) * Explicitly add the config value methods to the generic configuration manager's as a protected interface. Add the config class as a template parameter. * Remove the ImplClass from the GenericConfigurationManagerImpl template. * Minor cleanup. * Restyling with clang-format. * Apply the same changes to the other platforms. * Fix Linux with the same changes. * Fix remaining platforms. * Remove the Key namespacing since it's already defined in the superclass. This fixes the doxygen generation. * Remove the explicit template definitions. --- .../GenericConfigurationManagerImpl.cpp | 202 +++++++++--------- .../GenericConfigurationManagerImpl.h | 48 +++-- .../Ameba/ConfigurationManagerImpl.cpp | 92 ++++++-- src/platform/Ameba/ConfigurationManagerImpl.h | 23 +- .../Darwin/ConfigurationManagerImpl.cpp | 66 +++++- .../Darwin/ConfigurationManagerImpl.h | 23 +- .../EFR32/ConfigurationManagerImpl.cpp | 68 +++++- src/platform/EFR32/ConfigurationManagerImpl.h | 23 +- .../ESP32/ConfigurationManagerImpl.cpp | 86 ++++++-- src/platform/ESP32/ConfigurationManagerImpl.h | 27 ++- .../Linux/ConfigurationManagerImpl.cpp | 100 +++++++-- src/platform/Linux/ConfigurationManagerImpl.h | 23 +- src/platform/Linux/PosixConfig.h | 1 - src/platform/P6/ConfigurationManagerImpl.cpp | 64 +++++- src/platform/P6/ConfigurationManagerImpl.h | 23 +- .../Tizen/ConfigurationManagerImpl.cpp | 62 +++++- src/platform/Tizen/ConfigurationManagerImpl.h | 23 +- .../Zephyr/ConfigurationManagerImpl.cpp | 62 +++++- .../Zephyr/ConfigurationManagerImpl.h | 27 ++- src/platform/android/AndroidConfig.h | 4 +- .../android/ConfigurationManagerImpl.cpp | 60 ++++++ .../android/ConfigurationManagerImpl.h | 23 +- .../cc13x2_26x2/ConfigurationManagerImpl.cpp | 66 +++++- .../cc13x2_26x2/ConfigurationManagerImpl.h | 21 +- .../mbed/ConfigurationManagerImpl.cpp | 64 +++++- src/platform/mbed/ConfigurationManagerImpl.h | 22 +- .../k32w/k32w0/ConfigurationManagerImpl.cpp | 68 +++++- .../nxp/k32w/k32w0/ConfigurationManagerImpl.h | 23 +- src/platform/nxp/k32w/k32w0/K32W0Config.cpp | 2 + src/platform/qpg/ConfigurationManagerImpl.cpp | 72 ++++++- src/platform/qpg/ConfigurationManagerImpl.h | 23 +- 31 files changed, 1186 insertions(+), 305 deletions(-) diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp index 4ea6ff3515640f..83aa127fab0a05 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp @@ -44,8 +44,8 @@ namespace chip { namespace DeviceLayer { namespace Internal { -template -CHIP_ERROR GenericConfigurationManagerImpl::Init() +template +CHIP_ERROR GenericConfigurationManagerImpl::Init() { #if CHIP_ENABLE_ROTATING_DEVICE_ID mLifetimePersistedCounter.Init(CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY); @@ -54,36 +54,36 @@ CHIP_ERROR GenericConfigurationManagerImpl::Init() return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetVendorName(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetVendorName(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME); return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetProductName(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetProductName(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME); return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetFirmwareRevisionString(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetFirmwareRevisionString(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING); return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetSerialNumber(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetSerialNumber(char * buf, size_t bufSize) { CHIP_ERROR err; size_t serialNumLen = 0; // without counting null-terminator - err = Impl()->ReadConfigValueStr(ImplClass::kConfigKey_SerialNum, buf, bufSize, serialNumLen); + err = ReadConfigValueStr(ConfigClass::kConfigKey_SerialNum, buf, bufSize, serialNumLen); #ifdef CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER if (CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER[0] != 0 && err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -103,26 +103,26 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetSerialNumber(char * bu return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreSerialNumber(const char * serialNum, size_t serialNumLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreSerialNumber(const char * serialNum, size_t serialNumLen) { - return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_SerialNum, serialNum, serialNumLen); + return WriteConfigValueStr(ConfigClass::kConfigKey_SerialNum, serialNum, serialNumLen); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; } -template -CHIP_ERROR GenericConfigurationManagerImpl::StorePrimaryWiFiMACAddress(const uint8_t * buf) +template +CHIP_ERROR GenericConfigurationManagerImpl::StorePrimaryWiFiMACAddress(const uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryMACAddress(MutableByteSpan buf) { if (buf.size() != ConfigurationManager::kPrimaryMACAddressLength) return CHIP_ERROR_INVALID_ARGUMENT; @@ -149,8 +149,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetPrimaryMACAddress(Muta return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetPrimary802154MACAddress(uint8_t * buf) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetPrimary802154MACAddress(uint8_t * buf) { #if CHIP_DEVICE_CONFIG_ENABLE_THREAD return ThreadStackManager().GetPrimary802154MACAddress(buf); @@ -159,27 +159,27 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetPrimary802154MACAddres #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD } -template -CHIP_ERROR GenericConfigurationManagerImpl::StorePrimary802154MACAddress(const uint8_t * buf) +template +CHIP_ERROR GenericConfigurationManagerImpl::StorePrimary802154MACAddress(const uint8_t * buf) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductRevisionString(char * buf, size_t bufSize) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductRevisionString(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION_STRING); return CHIP_NO_ERROR; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductRevision(uint16_t & productRev) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductRevision(uint16_t & productRev) { CHIP_ERROR err; uint32_t val; - err = Impl()->ReadConfigValue(ImplClass::kConfigKey_ProductRevision, val); + err = ReadConfigValue(ConfigClass::kConfigKey_ProductRevision, val); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { productRev = static_cast(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION); @@ -193,14 +193,15 @@ inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductRevision return err; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::StoreProductRevision(uint16_t productRev) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::StoreProductRevision(uint16_t productRev) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_ProductRevision, static_cast(productRev)); + return WriteConfigValue(ConfigClass::kConfigKey_ProductRevision, static_cast(productRev)); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetManufacturingDate(uint16_t & year, uint8_t & month, + uint8_t & dayOfMonth) { CHIP_ERROR err; enum @@ -211,7 +212,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetManufacturingDate(uint size_t dateLen; char * parseEnd; - err = Impl()->ReadConfigValueStr(ImplClass::kConfigKey_ManufacturingDate, dateStr, sizeof(dateStr), dateLen); + err = ReadConfigValueStr(ConfigClass::kConfigKey_ManufacturingDate, dateStr, sizeof(dateStr), dateLen); SuccessOrExit(err); VerifyOrExit(dateLen == kDateStringLength, err = CHIP_ERROR_INVALID_ARGUMENT); @@ -239,14 +240,14 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetManufacturingDate(uint return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) { - return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_ManufacturingDate, mfgDate, mfgDateLen); + return WriteConfigValueStr(ConfigClass::kConfigKey_ManufacturingDate, mfgDate, mfgDateLen); } -template -void GenericConfigurationManagerImpl::InitiateFactoryReset() +template +void GenericConfigurationManagerImpl::InitiateFactoryReset() { #if CHIP_ENABLE_ROTATING_DEVICE_ID _IncrementLifetimeCounter(); @@ -254,12 +255,12 @@ void GenericConfigurationManagerImpl::InitiateFactoryReset() // Inheriting classes should call this method so the lifetime counter is updated if necessary. } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetSetupPinCode(uint32_t & setupPinCode) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetSetupPinCode(uint32_t & setupPinCode) { CHIP_ERROR err; - err = Impl()->ReadConfigValue(ImplClass::kConfigKey_SetupPinCode, setupPinCode); + err = ReadConfigValue(ConfigClass::kConfigKey_SetupPinCode, setupPinCode); #if defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -273,19 +274,19 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetSetupPinCode(uint32_t return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreSetupPinCode(uint32_t setupPinCode) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreSetupPinCode(uint32_t setupPinCode) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_SetupPinCode, setupPinCode); + return WriteConfigValue(ConfigClass::kConfigKey_SetupPinCode, setupPinCode); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetSetupDiscriminator(uint16_t & setupDiscriminator) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetSetupDiscriminator(uint16_t & setupDiscriminator) { CHIP_ERROR err; uint32_t val; - err = Impl()->ReadConfigValue(ImplClass::kConfigKey_SetupDiscriminator, val); + err = ReadConfigValue(ConfigClass::kConfigKey_SetupDiscriminator, val); #if defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { @@ -301,46 +302,46 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetSetupDiscriminator(uin return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreSetupDiscriminator(uint16_t setupDiscriminator) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreSetupDiscriminator(uint16_t setupDiscriminator) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_SetupDiscriminator, static_cast(setupDiscriminator)); + return WriteConfigValue(ConfigClass::kConfigKey_SetupDiscriminator, static_cast(setupDiscriminator)); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetRegulatoryLocation(uint32_t & location) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetRegulatoryLocation(uint32_t & location) { - return Impl()->ReadConfigValue(ImplClass::kConfigKey_RegulatoryLocation, location); + return ReadConfigValue(ConfigClass::kConfigKey_RegulatoryLocation, location); } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreRegulatoryLocation(uint32_t location) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreRegulatoryLocation(uint32_t location) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_RegulatoryLocation, location); + return WriteConfigValue(ConfigClass::kConfigKey_RegulatoryLocation, location); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) { - return Impl()->ReadConfigValueStr(ImplClass::kConfigKey_CountryCode, buf, bufSize, codeLen); + return ReadConfigValueStr(ConfigClass::kConfigKey_CountryCode, buf, bufSize, codeLen); } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreCountryCode(const char * code, size_t codeLen) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreCountryCode(const char * code, size_t codeLen) { - return Impl()->WriteConfigValueStr(ImplClass::kConfigKey_CountryCode, code, codeLen); + return WriteConfigValueStr(ConfigClass::kConfigKey_CountryCode, code, codeLen); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetBreadcrumb(uint64_t & breadcrumb) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetBreadcrumb(uint64_t & breadcrumb) { - return Impl()->ReadConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb); + return ReadConfigValue(ConfigClass::kConfigKey_Breadcrumb, breadcrumb); } -template -CHIP_ERROR GenericConfigurationManagerImpl::StoreBreadcrumb(uint64_t breadcrumb) +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreBreadcrumb(uint64_t breadcrumb) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_Breadcrumb, breadcrumb); + return WriteConfigValue(ConfigClass::kConfigKey_Breadcrumb, breadcrumb); } template @@ -379,8 +380,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::StoreBootReasons(uint32_t return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetLifetimeCounter(uint16_t & lifetimeCounter) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetLifetimeCounter(uint16_t & lifetimeCounter) { #if CHIP_ENABLE_ROTATING_DEVICE_ID lifetimeCounter = static_cast(mLifetimePersistedCounter.GetValue()); @@ -390,8 +391,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetLifetimeCounter(uint16 #endif } -template -CHIP_ERROR GenericConfigurationManagerImpl::_IncrementLifetimeCounter() +template +CHIP_ERROR GenericConfigurationManagerImpl::_IncrementLifetimeCounter() { #if CHIP_ENABLE_ROTATING_DEVICE_ID return mLifetimePersistedCounter.Advance(); @@ -400,21 +401,21 @@ CHIP_ERROR GenericConfigurationManagerImpl::_IncrementLifetimeCounter #endif } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetFailSafeArmed(bool & val) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetFailSafeArmed(bool & val) { - return Impl()->ReadConfigValue(ImplClass::kConfigKey_FailSafeArmed, val); + return ReadConfigValue(ConfigClass::kConfigKey_FailSafeArmed, val); } -template -CHIP_ERROR GenericConfigurationManagerImpl::SetFailSafeArmed(bool val) +template +CHIP_ERROR GenericConfigurationManagerImpl::SetFailSafeArmed(bool val) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_FailSafeArmed, val); + return WriteConfigValue(ConfigClass::kConfigKey_FailSafeArmed, val); } -template +template CHIP_ERROR -GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) +GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) { CHIP_ERROR err; uint16_t id; @@ -438,8 +439,8 @@ GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble:: return err; } -template -bool GenericConfigurationManagerImpl::IsFullyProvisioned() +template +bool GenericConfigurationManagerImpl::IsFullyProvisioned() { #if CHIP_BYPASS_RENDEZVOUS return true; @@ -456,8 +457,8 @@ bool GenericConfigurationManagerImpl::IsFullyProvisioned() #endif // CHIP_BYPASS_RENDEZVOUS } -template -bool GenericConfigurationManagerImpl::IsCommissionableDeviceTypeEnabled() +template +bool GenericConfigurationManagerImpl::IsCommissionableDeviceTypeEnabled() { #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE return true; @@ -466,48 +467,48 @@ bool GenericConfigurationManagerImpl::IsCommissionableDeviceTypeEnabl #endif } -template -bool GenericConfigurationManagerImpl::IsCommissionableDeviceNameEnabled() +template +bool GenericConfigurationManagerImpl::IsCommissionableDeviceNameEnabled() { return CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME == 1; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetCommissionableDeviceName(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetCommissionableDeviceName(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_NAME); return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetInitialPairingInstruction(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetInitialPairingInstruction(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_PAIRING_INITIAL_INSTRUCTION), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_PAIRING_INITIAL_INSTRUCTION); return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetSecondaryPairingInstruction(char * buf, size_t bufSize) +template +CHIP_ERROR GenericConfigurationManagerImpl::GetSecondaryPairingInstruction(char * buf, size_t bufSize) { ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_PAIRING_SECONDARY_INSTRUCTION), CHIP_ERROR_BUFFER_TOO_SMALL); strcpy(buf, CHIP_DEVICE_CONFIG_PAIRING_SECONDARY_INSTRUCTION); return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::RunUnitTests() +template +CHIP_ERROR GenericConfigurationManagerImpl::RunUnitTests() { #if !defined(NDEBUG) ChipLogProgress(DeviceLayer, "Running configuration unit test"); - Impl()->RunConfigUnitTest(); + RunConfigUnitTest(); #endif return CHIP_NO_ERROR; } -template -void GenericConfigurationManagerImpl::LogDeviceConfig() +template +void GenericConfigurationManagerImpl::LogDeviceConfig() { CHIP_ERROR err; @@ -588,9 +589,6 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() } } -// Fully instantiate the generic implementation class in whatever compilation unit includes this file. -template class GenericConfigurationManagerImpl; - } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index 26c9e10a5b6604..7c707737edf142 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -44,10 +44,9 @@ namespace Internal { * * This template contains implementations of select features from the ConfigurationManager abstract * interface that are suitable for use on all platforms. It is intended to be inherited (directly - * or indirectly) by the ConfigurationManagerImpl class, which also appears as the template's ImplClass - * parameter. + * or indirectly) by the ConfigurationManagerImpl class. */ -template +template class GenericConfigurationManagerImpl : public ConfigurationManager { public: @@ -114,50 +113,59 @@ class GenericConfigurationManagerImpl : public ConfigurationManager #endif CHIP_ERROR PersistProvisioningData(ProvisioningDataSet & provData); -private: - ImplClass * Impl() { return static_cast(this); } + // Methods to read and write configuration values, as well as run the configuration unit test. + typedef typename ConfigClass::Key Key; + virtual CHIP_ERROR ReadConfigValue(Key key, bool & val) = 0; + virtual CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) = 0; + virtual CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) = 0; + virtual CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) = 0; + virtual CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) = 0; + virtual CHIP_ERROR WriteConfigValue(Key key, bool val) = 0; + virtual CHIP_ERROR WriteConfigValue(Key key, uint32_t val) = 0; + virtual CHIP_ERROR WriteConfigValue(Key key, uint64_t val) = 0; + virtual CHIP_ERROR WriteConfigValueStr(Key key, const char * str) = 0; + virtual CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) = 0; + virtual CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) = 0; + virtual void RunConfigUnitTest(void) = 0; }; -// Instruct the compiler to instantiate the template only when explicitly told to do so. -extern template class Internal::GenericConfigurationManagerImpl; - -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) { vendorId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID); return CHIP_NO_ERROR; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductId(uint16_t & productId) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetProductId(uint16_t & productId) { productId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID); return CHIP_NO_ERROR; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetFirmwareRevision(uint16_t & firmwareRev) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetFirmwareRevision(uint16_t & firmwareRev) { firmwareRev = static_cast(CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION); return CHIP_NO_ERROR; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetDeviceTypeId(uint16_t & deviceType) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetDeviceTypeId(uint16_t & deviceType) { deviceType = static_cast(CHIP_DEVICE_CONFIG_DEVICE_TYPE); return CHIP_NO_ERROR; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetInitialPairingHint(uint16_t & pairingHint) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetInitialPairingHint(uint16_t & pairingHint) { pairingHint = static_cast(CHIP_DEVICE_CONFIG_PAIRING_INITIAL_HINT); return CHIP_NO_ERROR; } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetSecondaryPairingHint(uint16_t & pairingHint) +template +inline CHIP_ERROR GenericConfigurationManagerImpl::GetSecondaryPairingHint(uint16_t & pairingHint) { pairingHint = static_cast(CHIP_DEVICE_CONFIG_PAIRING_SECONDARY_HINT); return CHIP_NO_ERROR; diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index 9e5525322536b9..8d67c147029300 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -49,14 +49,14 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Force initialization of NVS namespaces if they doesn't already exist. - err = EnsureNamespace(kConfigNamespace_ChipFactory); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipFactory); SuccessOrExit(err); - err = EnsureNamespace(kConfigNamespace_ChipConfig); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipConfig); SuccessOrExit(err); - err = EnsureNamespace(kConfigNamespace_ChipCounters); + err = AmebaConfig::EnsureNamespace(AmebaConfig::kConfigNamespace_ChipCounters); SuccessOrExit(err); - if (ConfigValueExists(kCounterKey_RebootCount)) + if (AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_RebootCount)) { err = GetRebootCount(rebootCount); SuccessOrExit(err); @@ -71,20 +71,20 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(err); } - if (!ConfigValueExists(kCounterKey_TotalOperationalHours)) + if (!AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_TotalOperationalHours)) { err = StoreTotalOperationalHours(0); SuccessOrExit(err); } - if (!ConfigValueExists(kCounterKey_BootReason)) + if (!AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_BootReason)) { err = StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_UNSPECIFIED); SuccessOrExit(err); } // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); // If the fail-safe was armed when the device last shutdown, initiate a factory reset. @@ -101,32 +101,32 @@ CHIP_ERROR ConfigurationManagerImpl::Init() CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount) { - return ReadConfigValue(kCounterKey_RebootCount, rebootCount); + return ReadConfigValue(AmebaConfig::kCounterKey_RebootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount) { - return WriteConfigValue(kCounterKey_RebootCount, rebootCount); + return WriteConfigValue(AmebaConfig::kCounterKey_RebootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours) { - return ReadConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours); + return ReadConfigValue(AmebaConfig::kCounterKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours) { - return WriteConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours); + return WriteConfigValue(AmebaConfig::kCounterKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::GetBootReasons(uint32_t & bootReasons) { - return ReadConfigValue(kCounterKey_BootReason, bootReasons); + return ReadConfigValue(AmebaConfig::kCounterKey_BootReason, bootReasons); } CHIP_ERROR ConfigurationManagerImpl::StoreBootReasons(uint32_t bootReasons) { - return WriteConfigValue(kCounterKey_BootReason, bootReasons); + return WriteConfigValue(AmebaConfig::kCounterKey_BootReason, bootReasons); } CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) @@ -156,7 +156,7 @@ void ConfigurationManagerImpl::InitiateFactoryReset() CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - AmebaConfig::Key configKey{ kConfigNamespace_ChipCounters, key }; + AmebaConfig::Key configKey{ AmebaConfig::kConfigNamespace_ChipCounters, key }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -168,10 +168,70 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - AmebaConfig::Key configKey{ kConfigNamespace_ChipCounters, key }; + AmebaConfig::Key configKey{ AmebaConfig::kConfigNamespace_ChipCounters, key }; return WriteConfigValue(configKey, value); } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return AmebaConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return AmebaConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return AmebaConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return AmebaConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return AmebaConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return AmebaConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return AmebaConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return AmebaConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return AmebaConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return AmebaConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return AmebaConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + AmebaConfig::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; @@ -179,7 +239,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ChipLogProgress(DeviceLayer, "Performing factory reset"); // Erase all values in the chip-config NVS namespace. - err = ClearNamespace(kConfigNamespace_ChipConfig); + err = AmebaConfig::ClearNamespace(AmebaConfig::kConfigNamespace_ChipConfig); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "ClearNamespace(ChipConfig) failed: %s", chip::ErrorStr(err)); diff --git a/src/platform/Ameba/ConfigurationManagerImpl.h b/src/platform/Ameba/ConfigurationManagerImpl.h index c51ea2eb30175d..3470b312830c34 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.h +++ b/src/platform/Ameba/ConfigurationManagerImpl.h @@ -34,20 +34,13 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Ameba platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::AmebaConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { 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 - friend class Internal::GenericConfigurationManagerImpl; -#endif - // ===== Members that implement the ConfigurationManager public interface. CHIP_ERROR Init(void) override; @@ -65,6 +58,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp index 1b904ffdb1b304..3011c9e97ea266 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.cpp +++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp @@ -139,7 +139,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() CHIP_ERROR err; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); exit: @@ -177,7 +177,7 @@ void ConfigurationManagerImpl::InitiateFactoryReset() CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - PosixConfig::Key configKey{ kConfigNamespace_ChipCounters, key }; + PosixConfig::Key configKey{ PosixConfig::kConfigNamespace_ChipCounters, key }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -189,9 +189,69 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - PosixConfig::Key configKey{ kConfigNamespace_ChipCounters, key }; + PosixConfig::Key configKey{ PosixConfig::kConfigNamespace_ChipCounters, key }; return WriteConfigValue(configKey, value); } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return PosixConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return PosixConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return PosixConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return PosixConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return PosixConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + PosixConfig::RunConfigUnitTest(); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Darwin/ConfigurationManagerImpl.h b/src/platform/Darwin/ConfigurationManagerImpl.h index 193155cbc3cf9f..364ffdd035e533 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.h +++ b/src/platform/Darwin/ConfigurationManagerImpl.h @@ -33,15 +33,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Darwin platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::PosixConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -57,6 +50,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; }; } // namespace DeviceLayer diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index c8564cd9f1b4f5..b667afc31b7a4b 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -46,7 +46,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); // TODO: Initialize the global GroupKeyStore object here (#1626) @@ -81,7 +81,7 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: // (where persistedStorageKey represents an index to the counter). CHIP_ERROR err; - err = ReadConfigValueCounter(persistedStorageKey, value); + err = EFR32Config::ReadConfigValueCounter(persistedStorageKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; @@ -99,7 +99,7 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform // (where persistedStorageKey represents an index to the counter). CHIP_ERROR err; - err = WriteConfigValueCounter(persistedStorageKey, value); + err = EFR32Config::WriteConfigValueCounter(persistedStorageKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; @@ -110,13 +110,73 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform return err; } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return EFR32Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return EFR32Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return EFR32Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return EFR32Config::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return EFR32Config::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return EFR32Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return EFR32Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return EFR32Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return EFR32Config::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return EFR32Config::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return EFR32Config::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + EFR32Config::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = FactoryResetConfig(); + err = EFR32Config::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", chip::ErrorStr(err)); diff --git a/src/platform/EFR32/ConfigurationManagerImpl.h b/src/platform/EFR32/ConfigurationManagerImpl.h index 5e88832e761076..34037e17cfd67e 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.h +++ b/src/platform/EFR32/ConfigurationManagerImpl.h @@ -34,15 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the EFR32 platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::EFR32Config +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -59,6 +52,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 0254d8504d7990..6dc84c130ea5b8 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -63,14 +63,14 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Force initialization of NVS namespaces if they doesn't already exist. - err = EnsureNamespace(kConfigNamespace_ChipFactory); + err = ESP32Config::EnsureNamespace(ESP32Config::kConfigNamespace_ChipFactory); SuccessOrExit(err); - err = EnsureNamespace(kConfigNamespace_ChipConfig); + err = ESP32Config::EnsureNamespace(ESP32Config::kConfigNamespace_ChipConfig); SuccessOrExit(err); - err = EnsureNamespace(kConfigNamespace_ChipCounters); + err = ESP32Config::EnsureNamespace(ESP32Config::kConfigNamespace_ChipCounters); SuccessOrExit(err); - if (ConfigValueExists(kCounterKey_RebootCount)) + if (ESP32Config::ConfigValueExists(ESP32Config::kCounterKey_RebootCount)) { err = GetRebootCount(rebootCount); SuccessOrExit(err); @@ -85,14 +85,14 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(err); } - if (!ConfigValueExists(kCounterKey_TotalOperationalHours)) + if (!ESP32Config::ConfigValueExists(ESP32Config::kCounterKey_TotalOperationalHours)) { err = StoreTotalOperationalHours(0); SuccessOrExit(err); } // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); // TODO: Initialize the global GroupKeyStore object here (#1266) @@ -126,22 +126,22 @@ CHIP_ERROR ConfigurationManagerImpl::Init() CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount) { - return ReadConfigValue(kCounterKey_RebootCount, rebootCount); + return ReadConfigValue(ESP32Config::kCounterKey_RebootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount) { - return WriteConfigValue(kCounterKey_RebootCount, rebootCount); + return WriteConfigValue(ESP32Config::kCounterKey_RebootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours) { - return ReadConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours); + return ReadConfigValue(ESP32Config::kCounterKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours) { - return WriteConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours); + return WriteConfigValue(ESP32Config::kCounterKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) @@ -187,7 +187,7 @@ void ConfigurationManagerImpl::InitiateFactoryReset() CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - ESP32Config::Key configKey{ kConfigNamespace_ChipCounters, key }; + ESP32Config::Key configKey{ ESP32Config::kConfigNamespace_ChipCounters, key }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -199,10 +199,70 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - ESP32Config::Key configKey{ kConfigNamespace_ChipCounters, key }; + ESP32Config::Key configKey{ ESP32Config::kConfigNamespace_ChipCounters, key }; return WriteConfigValue(configKey, value); } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return ESP32Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return ESP32Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return ESP32Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return ESP32Config::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return ESP32Config::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return ESP32Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return ESP32Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return ESP32Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return ESP32Config::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return ESP32Config::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return ESP32Config::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + ESP32Config::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; @@ -210,7 +270,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ChipLogProgress(DeviceLayer, "Performing factory reset"); // Erase all values in the chip-config NVS namespace. - err = ClearNamespace(kConfigNamespace_ChipConfig); + err = ESP32Config::ClearNamespace(ESP32Config::kConfigNamespace_ChipConfig); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "ClearNamespace(ChipConfig) failed: %s", chip::ErrorStr(err)); diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 445783f05e15ac..01e31473a31ada 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -41,13 +41,12 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the ESP32 platform. */ -class ConfigurationManagerImpl : 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 { public: CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; @@ -57,12 +56,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp static ConfigurationManagerImpl & GetDefaultInstance(); private: - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - // ===== Members that implement the ConfigurationManager public interface. CHIP_ERROR Init(void) override; @@ -75,6 +68,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index 1e542084216b93..0e579de76fa61e 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -53,18 +53,18 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Force initialization of NVS namespaces if they doesn't already exist. - err = EnsureNamespace(kConfigNamespace_ChipFactory); + err = PosixConfig::EnsureNamespace(PosixConfig::kConfigNamespace_ChipFactory); SuccessOrExit(err); - err = EnsureNamespace(kConfigNamespace_ChipConfig); + err = PosixConfig::EnsureNamespace(PosixConfig::kConfigNamespace_ChipConfig); SuccessOrExit(err); - err = EnsureNamespace(kConfigNamespace_ChipCounters); + err = PosixConfig::EnsureNamespace(PosixConfig::kConfigNamespace_ChipCounters); SuccessOrExit(err); // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); - if (ConfigValueExists(kCounterKey_RebootCount)) + if (PosixConfig::ConfigValueExists(PosixConfig::kCounterKey_RebootCount)) { err = GetRebootCount(rebootCount); SuccessOrExit(err); @@ -79,13 +79,13 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(err); } - if (!ConfigValueExists(kCounterKey_TotalOperationalHours)) + if (!PosixConfig::ConfigValueExists(PosixConfig::kCounterKey_TotalOperationalHours)) { err = StoreTotalOperationalHours(0); SuccessOrExit(err); } - if (!ConfigValueExists(kCounterKey_BootReason)) + if (!PosixConfig::ConfigValueExists(PosixConfig::kCounterKey_BootReason)) { err = StoreBootReasons(EMBER_ZCL_BOOT_REASON_TYPE_UNSPECIFIED); SuccessOrExit(err); @@ -144,7 +144,7 @@ void ConfigurationManagerImpl::InitiateFactoryReset() CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - PosixConfig::Key configKey{ kConfigNamespace_ChipCounters, key }; + PosixConfig::Key configKey{ PosixConfig::kConfigNamespace_ChipCounters, key }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -156,7 +156,7 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - PosixConfig::Key configKey{ kConfigNamespace_ChipCounters, key }; + PosixConfig::Key configKey{ PosixConfig::kConfigNamespace_ChipCounters, key }; return WriteConfigValue(configKey, value); } @@ -166,7 +166,7 @@ CHIP_ERROR ConfigurationManagerImpl::GetWiFiStationSecurityType(WiFiAuthSecurity CHIP_ERROR err; uint32_t secTypeInt; - err = ReadConfigValue(kConfigKey_WiFiStationSecType, secTypeInt); + err = ReadConfigValue(PosixConfig::kConfigKey_WiFiStationSecType, secTypeInt); if (err == CHIP_NO_ERROR) { secType = static_cast(secTypeInt); @@ -185,13 +185,13 @@ CHIP_ERROR ConfigurationManagerImpl::UpdateWiFiStationSecurityType(WiFiAuthSecur if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || (err == CHIP_NO_ERROR && secType != curSecType)) { uint32_t secTypeInt = static_cast(secType); - err = WriteConfigValue(kConfigKey_WiFiStationSecType, secTypeInt); + err = WriteConfigValue(PosixConfig::kConfigKey_WiFiStationSecType, secTypeInt); } SuccessOrExit(err); } else { - err = ClearConfigValue(kConfigKey_WiFiStationSecType); + err = PosixConfig::ClearConfigValue(PosixConfig::kConfigKey_WiFiStationSecType); SuccessOrExit(err); } @@ -200,19 +200,79 @@ CHIP_ERROR ConfigurationManagerImpl::UpdateWiFiStationSecurityType(WiFiAuthSecur } #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return PosixConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return PosixConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return PosixConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return PosixConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return PosixConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + PosixConfig::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = FactoryResetConfig(); + err = PosixConfig::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "Failed to factory reset configurations: %s", ErrorStr(err)); } - err = FactoryResetCounters(); + err = PosixConfig::FactoryResetCounters(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "Failed to factory reset counters: %s", ErrorStr(err)); @@ -232,32 +292,32 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount) { - return ReadConfigValue(kCounterKey_RebootCount, rebootCount); + return ReadConfigValue(PosixConfig::kCounterKey_RebootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount) { - return WriteConfigValue(kCounterKey_RebootCount, rebootCount); + return WriteConfigValue(PosixConfig::kCounterKey_RebootCount, rebootCount); } CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours) { - return ReadConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours); + return ReadConfigValue(PosixConfig::kCounterKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours) { - return WriteConfigValue(kCounterKey_TotalOperationalHours, totalOperationalHours); + return WriteConfigValue(PosixConfig::kCounterKey_TotalOperationalHours, totalOperationalHours); } CHIP_ERROR ConfigurationManagerImpl::GetBootReasons(uint32_t & bootReasons) { - return ReadConfigValue(kCounterKey_BootReason, bootReasons); + return ReadConfigValue(PosixConfig::kCounterKey_BootReason, bootReasons); } CHIP_ERROR ConfigurationManagerImpl::StoreBootReasons(uint32_t bootReasons) { - return WriteConfigValue(kCounterKey_BootReason, bootReasons); + return WriteConfigValue(PosixConfig::kCounterKey_BootReason, bootReasons); } } // namespace DeviceLayer diff --git a/src/platform/Linux/ConfigurationManagerImpl.h b/src/platform/Linux/ConfigurationManagerImpl.h index 2ce06c5b213655..80de9b5b1ad0fa 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.h +++ b/src/platform/Linux/ConfigurationManagerImpl.h @@ -34,8 +34,7 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Linux platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::PosixConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { public: CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; @@ -47,12 +46,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp static ConfigurationManagerImpl & GetDefaultInstance(); private: - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - // ===== Members that implement the ConfigurationManager public interface. CHIP_ERROR Init() override; @@ -69,6 +62,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/Linux/PosixConfig.h b/src/platform/Linux/PosixConfig.h index c2c861d59c8a11..50988a5b06dc41 100644 --- a/src/platform/Linux/PosixConfig.h +++ b/src/platform/Linux/PosixConfig.h @@ -103,7 +103,6 @@ class PosixConfig static CHIP_ERROR FactoryResetCounters(); static void RunConfigUnitTest(); -protected: // NVS Namespace helper functions. static CHIP_ERROR EnsureNamespace(const char * ns); static CHIP_ERROR ClearNamespace(const char * ns); diff --git a/src/platform/P6/ConfigurationManagerImpl.cpp b/src/platform/P6/ConfigurationManagerImpl.cpp index b17e84fcb23d45..067ca9ab4f749b 100644 --- a/src/platform/P6/ConfigurationManagerImpl.cpp +++ b/src/platform/P6/ConfigurationManagerImpl.cpp @@ -48,7 +48,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); VerifyOrReturnError(CHIP_NO_ERROR == err, err); // If the fail-safe was armed when the device last shutdown, initiate a factory reset. @@ -109,13 +109,73 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform return PersistedStorage::KeyValueStoreMgr().Put(key, static_cast(&value), 4); } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return P6Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return P6Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return P6Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return P6Config::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return P6Config::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return P6Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return P6Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return P6Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return P6Config::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return P6Config::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return P6Config::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + P6Config::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = FactoryResetConfig(); + err = P6Config::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); diff --git a/src/platform/P6/ConfigurationManagerImpl.h b/src/platform/P6/ConfigurationManagerImpl.h index da07d8d4904212..8aae8d9227f44c 100644 --- a/src/platform/P6/ConfigurationManagerImpl.h +++ b/src/platform/P6/ConfigurationManagerImpl.h @@ -35,15 +35,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the PSoC6 platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::P6Config +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -60,6 +53,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/Tizen/ConfigurationManagerImpl.cpp b/src/platform/Tizen/ConfigurationManagerImpl.cpp index 237d114ca56e9f..1091beb7aa34e5 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.cpp +++ b/src/platform/Tizen/ConfigurationManagerImpl.cpp @@ -45,7 +45,7 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance() CHIP_ERROR ConfigurationManagerImpl::Init(void) { - return Internal::GenericConfigurationManagerImpl::Init(); + return Internal::GenericConfigurationManagerImpl::Init(); } CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) @@ -70,5 +70,65 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return PosixConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return PosixConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return PosixConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return PosixConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return PosixConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return PosixConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return PosixConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + PosixConfig::RunConfigUnitTest(); +} + } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Tizen/ConfigurationManagerImpl.h b/src/platform/Tizen/ConfigurationManagerImpl.h index 88fb2d7001c969..5777de744550b6 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.h +++ b/src/platform/Tizen/ConfigurationManagerImpl.h @@ -34,15 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Tizen platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::PosixConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -58,6 +51,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; }; } // namespace DeviceLayer diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index a6a743cf1588e9..068b3117f69dbc 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp +++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp @@ -55,7 +55,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); // TODO: Initialize the global GroupKeyStore object here @@ -89,6 +89,66 @@ void ConfigurationManagerImpl::InitiateFactoryReset() PlatformMgr().ScheduleWork(DoFactoryReset); } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return ZephyrConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return ZephyrConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return ZephyrConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return ZephyrConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return ZephyrConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return ZephyrConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return ZephyrConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return ZephyrConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return ZephyrConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return ZephyrConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return ZephyrConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + ZephyrConfig::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { ChipLogProgress(DeviceLayer, "Performing factory reset"); diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.h b/src/platform/Zephyr/ConfigurationManagerImpl.h index 92a8aff3c5771e..a9f0346c906a24 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.h +++ b/src/platform/Zephyr/ConfigurationManagerImpl.h @@ -33,15 +33,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Zephyr platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::ZephyrConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -58,6 +51,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); @@ -70,12 +77,12 @@ inline bool ConfigurationManagerImpl::CanFactoryReset() inline CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - return ReadConfigValueCounter(key, value); + return Internal::ZephyrConfig::ReadConfigValueCounter(key, value); } inline CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - return WriteConfigValueCounter(key, value); + return Internal::ZephyrConfig::WriteConfigValueCounter(key, value); } inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * /* buf */) diff --git a/src/platform/android/AndroidConfig.h b/src/platform/android/AndroidConfig.h index 49635c6abaed49..319da320af9cee 100644 --- a/src/platform/android/AndroidConfig.h +++ b/src/platform/android/AndroidConfig.h @@ -97,12 +97,12 @@ class AndroidConfig static void RunConfigUnitTest(); + static void InitializeWithObject(jobject managerObject); + protected: // NVS Namespace helper functions. static CHIP_ERROR EnsureNamespace(const char * ns); static CHIP_ERROR ClearNamespace(const char * ns); - - static void InitializeWithObject(jobject managerObject); }; struct AndroidConfig::Key diff --git a/src/platform/android/ConfigurationManagerImpl.cpp b/src/platform/android/ConfigurationManagerImpl.cpp index 0b9c37b55515dd..3c61769abd0cd0 100644 --- a/src/platform/android/ConfigurationManagerImpl.cpp +++ b/src/platform/android/ConfigurationManagerImpl.cpp @@ -86,6 +86,66 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return AndroidConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return AndroidConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return AndroidConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return AndroidConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return AndroidConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return AndroidConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return AndroidConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return AndroidConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return AndroidConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return AndroidConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return AndroidConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + AndroidConfig::RunConfigUnitTest(); +} + #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION CHIP_ERROR ConfigurationManagerImpl::GetWiFiStationSecurityType(WiFiAuthSecurityType & secType) { diff --git a/src/platform/android/ConfigurationManagerImpl.h b/src/platform/android/ConfigurationManagerImpl.h index 91b048cb3301af..a8ee9fbca5c896 100644 --- a/src/platform/android/ConfigurationManagerImpl.h +++ b/src/platform/android/ConfigurationManagerImpl.h @@ -35,15 +35,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Android platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::AndroidConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: void InitializeWithObject(jobject managerObject); static ConfigurationManagerImpl & GetDefaultInstance(); @@ -65,6 +58,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp index d7a22577288411..0981df0169d9d5 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp @@ -89,7 +89,7 @@ void ConfigurationManagerImpl::InitiateFactoryReset() CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - CC13X2_26X2Config::Key configKey{ { kCC13X2_26X2ChipCounters_Sysid, key } }; + CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2ChipCounters_Sysid, key } }; CHIP_ERROR err = ReadConfigValue(configKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -101,17 +101,77 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - CC13X2_26X2Config::Key configKey{ { kCC13X2_26X2ChipCounters_Sysid, key } }; + CC13X2_26X2Config::Key configKey{ { CC13X2_26X2Config::kCC13X2_26X2ChipCounters_Sysid, key } }; return WriteConfigValue(configKey, value); } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return CC13X2_26X2Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return CC13X2_26X2Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return CC13X2_26X2Config::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return CC13X2_26X2Config::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return CC13X2_26X2Config::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return CC13X2_26X2Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return CC13X2_26X2Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return CC13X2_26X2Config::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return CC13X2_26X2Config::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return CC13X2_26X2Config::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return CC13X2_26X2Config::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + CC13X2_26X2Config::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = FactoryResetConfig(); + err = CC13X2_26X2Config::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h index febdb5d11adfb7..ad44199c34ddb5 100644 --- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h +++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.h @@ -33,13 +33,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the CC13X2_26X2 platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::CC13X2_26X2Config +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. - friend class Internal::GenericConfigurationManagerImpl; - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -56,6 +51,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/mbed/ConfigurationManagerImpl.cpp b/src/platform/mbed/ConfigurationManagerImpl.cpp index bd78fb8e27573c..f169f9885f2659 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.cpp +++ b/src/platform/mbed/ConfigurationManagerImpl.cpp @@ -110,13 +110,73 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) { - return WriteCounter(key, value); + return MbedConfig::WriteCounter(key, value); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return MbedConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return MbedConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return MbedConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return MbedConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return MbedConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return MbedConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return MbedConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return MbedConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return MbedConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return MbedConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return MbedConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + MbedConfig::RunConfigUnitTest(); } void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { ChipLogProgress(DeviceLayer, "Performing factory reset"); - const CHIP_ERROR err = FactoryResetConfig(); + const CHIP_ERROR err = MbedConfig::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); diff --git a/src/platform/mbed/ConfigurationManagerImpl.h b/src/platform/mbed/ConfigurationManagerImpl.h index 7acc0c2ab5e068..ad99477da305fa 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.h +++ b/src/platform/mbed/ConfigurationManagerImpl.h @@ -32,14 +32,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the Zephyr platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::MbedConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif public: // This returns an instance of this class. @@ -57,6 +51,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp index 9c17cc1290c09b..6bf016200e6aa7 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp @@ -51,7 +51,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); // TODO: Initialize the global GroupKeyStore object here @@ -84,7 +84,7 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: { CHIP_ERROR err; - err = ReadConfigValueCounter(persistedStorageKey, value); + err = K32WConfig::ReadConfigValueCounter(persistedStorageKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; @@ -102,7 +102,7 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform // (where persistedStorageKey represents an index to the counter). CHIP_ERROR err; - err = WriteConfigValueCounter(persistedStorageKey, value); + err = K32WConfig::WriteConfigValueCounter(persistedStorageKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; @@ -113,13 +113,73 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform return err; } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return K32WConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return K32WConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return K32WConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return K32WConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return K32WConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return K32WConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return K32WConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return K32WConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return K32WConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return K32WConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return K32WConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + K32WConfig::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = FactoryResetConfig(); + err = K32WConfig::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h index c6443c52e6c798..aa3a6fd6af8ef3 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h @@ -34,15 +34,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the K32W platform. */ -class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl, - private Internal::K32WConfig +class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -59,6 +52,20 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg); diff --git a/src/platform/nxp/k32w/k32w0/K32W0Config.cpp b/src/platform/nxp/k32w/k32w0/K32W0Config.cpp index 8cb9da2ff26185..bf4910285160c4 100644 --- a/src/platform/nxp/k32w/k32w0/K32W0Config.cpp +++ b/src/platform/nxp/k32w/k32w0/K32W0Config.cpp @@ -468,6 +468,8 @@ CHIP_ERROR K32WConfig::ForEachRecord(Key firstKey, Key lastKey, bool addNewRecor return err; } +void K32WConfig::RunConfigUnitTest() {} + } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/qpg/ConfigurationManagerImpl.cpp b/src/platform/qpg/ConfigurationManagerImpl.cpp index c8c059017d7cb4..130f1a9876c68e 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.cpp +++ b/src/platform/qpg/ConfigurationManagerImpl.cpp @@ -53,7 +53,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() bool failSafeArmed; // Initialize the generic implementation base class. - err = Internal::GenericConfigurationManagerImpl::Init(); + err = Internal::GenericConfigurationManagerImpl::Init(); SuccessOrExit(err); // If the fail-safe was armed when the device last shutdown, initiate a factory reset. @@ -83,9 +83,9 @@ CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform: uint32_t & value) { CHIP_ERROR err; - uintmax_t recordKey = persistedStorageKey + kConfigKey_GroupKeyBase; + uintmax_t recordKey = persistedStorageKey + QPGConfig::kConfigKey_GroupKeyBase; - VerifyOrExit(recordKey <= kConfigKey_GroupKeyMax, err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + VerifyOrExit(recordKey <= QPGConfig::kConfigKey_GroupKeyMax, err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); err = ReadConfigValue(persistedStorageKey, value); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) @@ -103,9 +103,9 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform { CHIP_ERROR err; - uintmax_t recordKey = persistedStorageKey + kConfigKey_GroupKeyBase; + uintmax_t recordKey = persistedStorageKey + QPGConfig::kConfigKey_GroupKeyBase; - VerifyOrExit(recordKey <= kConfigKey_GroupKeyMax, err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); + VerifyOrExit(recordKey <= QPGConfig::kConfigKey_GroupKeyMax, err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); err = WriteConfigValue(persistedStorageKey, value); SuccessOrExit(err); @@ -114,6 +114,66 @@ CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform return err; } +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, bool & val) +{ + return QPGConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint32_t & val) +{ + return QPGConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValue(Key key, uint64_t & val) +{ + return QPGConfig::ReadConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) +{ + return QPGConfig::ReadConfigValueStr(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) +{ + return QPGConfig::ReadConfigValueBin(key, buf, bufSize, outLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, bool val) +{ + return QPGConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint32_t val) +{ + return QPGConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValue(Key key, uint64_t val) +{ + return QPGConfig::WriteConfigValue(key, val); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str) +{ + return QPGConfig::WriteConfigValueStr(key, str); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueStr(Key key, const char * str, size_t strLen) +{ + return QPGConfig::WriteConfigValueStr(key, str, strLen); +} + +CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) +{ + return QPGConfig::WriteConfigValueBin(key, data, dataLen); +} + +void ConfigurationManagerImpl::RunConfigUnitTest(void) +{ + QPGConfig::RunConfigUnitTest(); +} + void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; @@ -121,7 +181,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ChipLogProgress(DeviceLayer, "Performing factory reset"); - err = FactoryResetConfig(); + err = QPGConfig::FactoryResetConfig(); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err)); diff --git a/src/platform/qpg/ConfigurationManagerImpl.h b/src/platform/qpg/ConfigurationManagerImpl.h index c6f08abe227850..d267c89bfcd57b 100644 --- a/src/platform/qpg/ConfigurationManagerImpl.h +++ b/src/platform/qpg/ConfigurationManagerImpl.h @@ -32,15 +32,8 @@ namespace DeviceLayer { /** * Concrete implementation of the ConfigurationManager singleton object for the platform. */ -class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl, - private Internal::QPGConfig +class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImpl { - // Allow the GenericConfigurationManagerImpl base class to access helper methods and types - // defined on this class. -#ifndef DOXYGEN_SHOULD_SKIP_THIS - friend class Internal::GenericConfigurationManagerImpl; -#endif - public: // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); @@ -57,6 +50,20 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>. + // ===== Members that implement the GenericConfigurationManagerImpl protected interface. + CHIP_ERROR ReadConfigValue(Key key, bool & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint32_t & val) override; + CHIP_ERROR ReadConfigValue(Key key, uint64_t & val) override; + CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) override; + CHIP_ERROR WriteConfigValue(Key key, bool val) override; + CHIP_ERROR WriteConfigValue(Key key, uint32_t val) override; + CHIP_ERROR WriteConfigValue(Key key, uint64_t val) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override; + CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override; + CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override; + void RunConfigUnitTest(void) override; + // ===== Private members reserved for use by this class only. static void DoFactoryReset(intptr_t arg);