Proper termination and initialization of the ConfigManager.

This commit is contained in:
BenDol 2014-04-02 00:30:17 +13:00
parent 547b18db9a
commit 5204e3ac03
4 changed files with 30 additions and 7 deletions

View File

@ -24,3 +24,6 @@ Module
dofile 'inputmessage' dofile 'inputmessage'
dofile 'outputmessage' dofile 'outputmessage'
@onUnload: |
g_settings = nil

View File

@ -90,6 +90,9 @@ void Application::init(std::vector<std::string>& args)
m_startupOptions = startupOptions; m_startupOptions = startupOptions;
// initialize configs
g_configs.init();
// initialize resources // initialize resources
g_resources.init(args[0].c_str()); g_resources.init(args[0].c_str());
@ -125,11 +128,8 @@ void Application::terminate()
Connection::terminate(); Connection::terminate();
#endif #endif
// save configurations // release configs
ConfigPtr settings = g_configs.getSettings(); g_configs.terminate();
if(settings) {
settings->save();
}
// release resources // release resources
g_resources.terminate(); g_resources.terminate();

View File

@ -24,11 +24,29 @@
ConfigManager g_configs; ConfigManager g_configs;
ConfigManager::ConfigManager() void ConfigManager::init()
{ {
m_settings = ConfigPtr(new Config()); m_settings = ConfigPtr(new Config());
} }
void ConfigManager::terminate()
{
if(m_settings) {
// ensure settings are saved
m_settings->save();
m_settings->unload();
m_settings = nullptr;
}
for(ConfigPtr config : m_configs) {
config->unload();
config = nullptr;
}
m_configs.clear();
}
ConfigPtr ConfigManager::getSettings() ConfigPtr ConfigManager::getSettings()
{ {
return m_settings; return m_settings;
@ -79,6 +97,7 @@ bool ConfigManager::unload(const std::string& file)
if(config) { if(config) {
config->unload(); config->unload();
m_configs.remove(config); m_configs.remove(config);
config = nullptr;
return true; return true;
} }
return false; return false;

View File

@ -29,7 +29,8 @@
class ConfigManager class ConfigManager
{ {
public: public:
ConfigManager(); void init();
void terminate();
ConfigPtr getSettings(); ConfigPtr getSettings();
ConfigPtr get(const std::string& file); ConfigPtr get(const std::string& file);