Now the RCPPFramework singleton is also able to allocate the settings singleton.

This commit is contained in:
Relintai 2022-02-05 19:20:25 +01:00
parent d43b04a03c
commit ea6ae6ad41
2 changed files with 34 additions and 5 deletions

View File

@ -2,9 +2,13 @@
#include "core/error_macros.h" #include "core/error_macros.h"
#include "core/settings/settings.h"
#if DATABASES_ENABLED #if DATABASES_ENABLED
#include "database/database_manager.h" #include "database/database_manager.h"
#include "database_backends/db_init.h" #include "database_backends/db_init.h"
#include "database_modules/db_settings/db_settings.h"
#endif #endif
#if WEB_ENABLED #if WEB_ENABLED
@ -54,11 +58,7 @@ void RCPPFramework::initialize(int argc, char **argv, char **envp) {
} }
void RCPPFramework::setup_args(int argc, char **argv, char **envp) { void RCPPFramework::setup_args(int argc, char **argv, char **envp) {
// Don't use the error macros here, they might not work before initialization ERR_FAIL_COND(!_initialized);
if (!_initialized) {
printf("ERROR! RCPPFramework::set_args: You have to call initialize() first!\n");
return;
}
PlatformInitializer::arg_setup(argc, argv, envp); PlatformInitializer::arg_setup(argc, argv, envp);
} }
@ -68,6 +68,9 @@ void RCPPFramework::uninitialize() {
} }
void RCPPFramework::manage_object(Object *obj) { void RCPPFramework::manage_object(Object *obj) {
ERR_FAIL_COND(!_initialized);
ERR_FAIL_COND(obj);
_managed_objects.push_back(obj); _managed_objects.push_back(obj);
} }
@ -76,8 +79,11 @@ RCPPFramework::RCPPFramework() {
_initialized = false; _initialized = false;
allocate_settings_singleton = true;
#if DATABASES_ENABLED #if DATABASES_ENABLED
allocate_database_manager_singleton = true; allocate_database_manager_singleton = true;
allocate_db_settings_singleton = true;
#endif #endif
#if WEB_ENABLED #if WEB_ENABLED
@ -112,6 +118,24 @@ void RCPPFramework::_do_initialize() {
PlatformInitializer::allocate_all(); PlatformInitializer::allocate_all();
if (allocate_settings_singleton) {
Settings *settings = nullptr;
#if DATABASES_ENABLED
if (allocate_db_settings_singleton) {
settings = new DBSettings(true);
} else {
settings = new Settings(true);
}
#else
settings = new Settings(true);
#endif
manage_object(settings);
}
#if DATABASES_ENABLED #if DATABASES_ENABLED
if (allocate_database_manager_singleton) { if (allocate_database_manager_singleton) {
DatabaseManager *dbm = new DatabaseManager(); DatabaseManager *dbm = new DatabaseManager();

View File

@ -31,8 +31,13 @@ public:
static RCPPFramework *get_singleton(); static RCPPFramework *get_singleton();
bool allocate_settings_singleton;
#if DATABASES_ENABLED #if DATABASES_ENABLED
bool allocate_database_manager_singleton; bool allocate_database_manager_singleton;
// TODO Need a define for this
bool allocate_db_settings_singleton;
#endif #endif
#if WEB_ENABLED #if WEB_ENABLED