Skip to content

Commit

Permalink
Do not setup ConfigurationMgr via PlatformMgr on each platform (#21075)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Sep 23, 2023
1 parent 80ab218 commit 4337720
Show file tree
Hide file tree
Showing 60 changed files with 264 additions and 91 deletions.
15 changes: 12 additions & 3 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,26 @@ class ConfigurationManager
/**
* Returns a reference to a ConfigurationManager object.
*
* Applications should use this to access the features of the ConfigurationManager.
* Applications should use this to access features of the ConfigurationManager object
* that are common to all platforms.
*/
extern ConfigurationManager & ConfigurationMgr();
ConfigurationManager & ConfigurationMgr();

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
extern ConfigurationManager & ConfigurationMgrImpl();

/**
* Sets a reference to a ConfigurationManager object.
*
* This must be called before any calls to ConfigurationMgr. If a nullptr is passed in,
* no changes will be made.
*/
extern void SetConfigurationMgr(ConfigurationManager * configurationManager);
void SetConfigurationMgr(ConfigurationManager * configurationManager);

inline CHIP_ERROR ConfigurationManager::GetLocationCapability(uint8_t & location)
{
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
// sys_reset();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Ameba/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
static void DoFactoryReset(intptr_t arg);
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
2 changes: 0 additions & 2 deletions src/platform/Ameba/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)

CHIP_ERROR err;

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

// Make sure the LwIP core lock has been initialized
err = Internal::InitLwIPCoreLock();

Expand Down
5 changes: 5 additions & 0 deletions src/platform/CYW30739/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
wiced_hal_wdog_reset_system();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/CYW30739/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
static void DoFactoryReset(intptr_t arg);
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
2 changes: 0 additions & 2 deletions src/platform/CYW30739/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
err = PersistedStorage::KeyValueStoreMgrImpl().Init();
SuccessOrExit(err);

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

/* Create the thread object. */
mThread = wiced_rtos_create_thread();
VerifyOrExit(mThread != nullptr, err = CHIP_ERROR_NO_MEMORY);
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Darwin/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,5 +496,10 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
#endif // CHIP_DISABLE_PLATFORM_KVS
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Darwin/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
void RunConfigUnitTest(void) override;
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Darwin/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
SuccessOrExit(err);
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());
#endif // CHIP_DISABLE_PLATFORM_KVS
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

mRunLoopSem = dispatch_semaphore_create(0);

Expand Down
5 changes: 5 additions & 0 deletions src/platform/EFR32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,10 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
}
#endif

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
10 changes: 9 additions & 1 deletion src/platform/EFR32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * b
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

#endif /* SL_WIFI */

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
2 changes: 0 additions & 2 deletions src/platform/EFR32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
err = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
SuccessOrExit(err);

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

#if CHIP_SYSTEM_CONFIG_USE_LWIP
// Initialize LwIP.
tcpip_init(NULL, NULL);
Expand Down
5 changes: 5 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
esp_restart();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
static void DoFactoryReset(intptr_t arg);
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
2 changes: 0 additions & 2 deletions src/platform/ESP32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s

CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

esp_err_t err;
// Arrange for CHIP-encapsulated ESP32 errors to be translated to text
Internal::ESP32Utils::RegisterESP32ErrorFormatter();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Linux/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,10 @@ CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location)
return err;
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Linux/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
static void DoFactoryReset(intptr_t arg);
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()

// Initialize the configuration system.
ReturnErrorOnFailure(Internal::PosixConfig::Init());
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());

// Call _InitChipStack() on the generic implementation base class
Expand Down
5 changes: 5 additions & 0 deletions src/platform/P6/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
NVIC_SystemReset();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/P6/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
static void DoFactoryReset(intptr_t arg);
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
2 changes: 0 additions & 2 deletions src/platform/P6/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
CHIP_ERROR err;

SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

// Make sure the LwIP core lock has been initialized
err = Internal::InitLwIPCoreLock();
SuccessOrExit(err);
Expand Down
9 changes: 7 additions & 2 deletions src/platform/SingletonConfigurationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <lib/support/CodeUtils.h>
#include <platform/ConfigurationManager.h>

namespace chip {
namespace DeviceLayer {
Expand All @@ -37,8 +38,12 @@ ConfigurationManager * gInstance = nullptr;

ConfigurationManager & ConfigurationMgr()
{
VerifyOrDie(gInstance != nullptr);
return *gInstance;
if (gInstance != nullptr)
{
return *gInstance;
}

return ConfigurationMgrImpl();
}

void SetConfigurationMgr(ConfigurationManager * configurationManager)
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Tizen/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,10 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
PosixConfig::RunConfigUnitTest();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Tizen/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
void RunConfigUnitTest(void) override;
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Tizen/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ PlatformManagerImpl PlatformManagerImpl::sInstance;
CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
{
ReturnErrorOnFailure(Internal::PosixConfig::Init());
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());

return Internal::GenericPlatformManagerImpl_POSIX<PlatformManagerImpl>::_InitChipStack();
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Zephyr/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
PlatformMgr().Shutdown();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/Zephyr/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,13 @@ inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * /
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/Zephyr/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
// Initialize the configuration system.
err = Internal::ZephyrConfig::Init();
SuccessOrExit(err);
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());

#if !CONFIG_NORDIC_SECURITY_BACKEND
// Add entropy source based on Zephyr entropy driver
Expand Down
5 changes: 5 additions & 0 deletions src/platform/android/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,10 @@ CHIP_ERROR ConfigurationManagerImpl::GetUniqueId(char * buf, size_t bufSize)
return ReadConfigValueStr(AndroidConfig::kConfigKey_UniqueId, buf, bufSize, dateLen);
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/android/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,13 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
jobject mConfigurationManagerObject = nullptr;
};

/**
* Returns the platform-specific implementation of the ConfigurationManager object.
*
* Applications can use this to gain access to features of the ConfigurationManager
* that are specific to the selected platform.
*/
ConfigurationManager & ConfigurationMgrImpl();

} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/android/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
// Initialize the configuration system.
err = Internal::AndroidConfig::Init();
SuccessOrExit(err);
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDeviceInstanceInfoProvider(&DeviceInstanceInfoProviderMgrImpl());

// Call _InitChipStack() on the generic implementation base class
Expand Down
Loading

0 comments on commit 4337720

Please sign in to comment.