2022-02-05 17:22:59 +01:00
|
|
|
#include "rcpp_framework.h"
|
|
|
|
|
|
|
|
#include "core/error_macros.h"
|
|
|
|
|
2022-02-05 19:20:25 +01:00
|
|
|
#include "core/settings/settings.h"
|
|
|
|
|
2022-02-05 17:22:59 +01:00
|
|
|
#if DATABASES_ENABLED
|
2022-02-05 18:26:32 +01:00
|
|
|
#include "database/database_manager.h"
|
2022-02-05 17:22:59 +01:00
|
|
|
#include "database_backends/db_init.h"
|
2022-02-05 19:20:25 +01:00
|
|
|
|
|
|
|
#include "database_modules/db_settings/db_settings.h"
|
2022-02-05 17:22:59 +01:00
|
|
|
#endif
|
|
|
|
|
2022-02-05 18:31:00 +01:00
|
|
|
#if WEB_ENABLED
|
2022-02-05 18:39:27 +01:00
|
|
|
#include "web/file_cache.h"
|
2022-02-05 18:31:00 +01:00
|
|
|
#include "web/http/session_manager.h"
|
|
|
|
#endif
|
|
|
|
|
2022-02-05 17:22:59 +01:00
|
|
|
#include "platform/platform_initializer.h"
|
|
|
|
|
|
|
|
// Backends
|
|
|
|
#include "crypto_backends/hash_hashlib/setup.h"
|
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
void RCPPFramework::create() {
|
|
|
|
new RCPPFramework();
|
|
|
|
}
|
|
|
|
void RCPPFramework::destroy() {
|
2022-02-05 19:48:41 +01:00
|
|
|
_instance->uninitialize();
|
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
delete _instance;
|
|
|
|
}
|
2022-02-05 17:22:59 +01:00
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
void RCPPFramework::create_and_init() {
|
2022-02-05 17:22:59 +01:00
|
|
|
new RCPPFramework();
|
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
RCPPFramework::get_singleton()->initialize();
|
|
|
|
}
|
2022-02-05 17:22:59 +01:00
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
void RCPPFramework::create_and_init(int argc, char **argv, char **envp) {
|
|
|
|
new RCPPFramework();
|
2022-02-05 17:22:59 +01:00
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
RCPPFramework::get_singleton()->initialize();
|
|
|
|
RCPPFramework::get_singleton()->setup_args(argc, argv, envp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCPPFramework::initialize() {
|
|
|
|
if (_initialized) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_ERR("(RCPPFramework) has already beed initialized!");
|
2022-02-05 18:17:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_initialized = true;
|
|
|
|
|
|
|
|
_do_initialize();
|
2022-02-05 17:22:59 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 18:41:51 +01:00
|
|
|
void RCPPFramework::initialize(int argc, char **argv, char **envp) {
|
|
|
|
initialize();
|
|
|
|
setup_args(argc, argv, envp);
|
|
|
|
}
|
|
|
|
|
2022-02-05 18:17:36 +01:00
|
|
|
void RCPPFramework::setup_args(int argc, char **argv, char **envp) {
|
2022-02-05 19:20:25 +01:00
|
|
|
ERR_FAIL_COND(!_initialized);
|
2022-02-05 17:22:59 +01:00
|
|
|
|
|
|
|
PlatformInitializer::arg_setup(argc, argv, envp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCPPFramework::uninitialize() {
|
2022-02-05 19:48:41 +01:00
|
|
|
_do_uninitialize();
|
2022-02-05 17:22:59 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 19:29:20 +01:00
|
|
|
void RCPPFramework::load() {
|
|
|
|
#if DATABASES_ENABLED
|
|
|
|
if (allocate_settings_singleton && allocate_db_settings_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Loading DBSettings singleton!");
|
|
|
|
|
2022-02-05 19:29:20 +01:00
|
|
|
DBSettings::get_singleton()->load();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WEB_ENABLED
|
|
|
|
if (allocate_session_manager_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Loading SessionManager singleton!");
|
|
|
|
|
2022-02-05 19:29:20 +01:00
|
|
|
::SessionManager::get_singleton()->load_sessions();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allocate_file_cache_singleton && www_root != "") {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Loading FileCache singleton!");
|
|
|
|
|
2022-02-05 19:29:20 +01:00
|
|
|
FileCache::get_singleton()->wwwroot = www_root;
|
|
|
|
FileCache::get_singleton()->wwwroot_refresh_cache();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCPPFramework::migrate() {
|
|
|
|
#if DATABASES_ENABLED
|
|
|
|
if (allocate_settings_singleton && allocate_db_settings_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Migrating DBSettings singleton!");
|
|
|
|
|
2022-02-05 19:29:20 +01:00
|
|
|
DBSettings::get_singleton()->migrate();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WEB_ENABLED
|
|
|
|
if (allocate_session_manager_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Migrating SessionManager singleton!");
|
|
|
|
|
2022-02-05 19:29:20 +01:00
|
|
|
::SessionManager::get_singleton()->migrate();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-02-05 17:22:59 +01:00
|
|
|
void RCPPFramework::manage_object(Object *obj) {
|
2022-02-05 19:20:25 +01:00
|
|
|
ERR_FAIL_COND(!_initialized);
|
2022-02-05 19:29:20 +01:00
|
|
|
ERR_FAIL_COND(!obj);
|
2022-02-05 19:20:25 +01:00
|
|
|
|
2022-02-05 17:22:59 +01:00
|
|
|
_managed_objects.push_back(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCPPFramework::RCPPFramework() {
|
|
|
|
_instance = this;
|
2022-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
_initialized = false;
|
2022-02-05 18:26:32 +01:00
|
|
|
|
2022-02-05 19:20:25 +01:00
|
|
|
allocate_settings_singleton = true;
|
|
|
|
|
2022-02-05 18:26:32 +01:00
|
|
|
#if DATABASES_ENABLED
|
|
|
|
allocate_database_manager_singleton = true;
|
2022-02-05 19:20:25 +01:00
|
|
|
allocate_db_settings_singleton = true;
|
2022-02-05 18:26:32 +01:00
|
|
|
#endif
|
2022-02-05 18:31:00 +01:00
|
|
|
|
|
|
|
#if WEB_ENABLED
|
|
|
|
allocate_session_manager_singleton = true;
|
2022-02-05 18:39:27 +01:00
|
|
|
allocate_file_cache_singleton = true;
|
2022-02-05 18:31:00 +01:00
|
|
|
#endif
|
2022-02-05 17:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RCPPFramework::~RCPPFramework() {
|
2022-02-05 18:17:36 +01:00
|
|
|
// delete in reverse order added
|
2022-02-05 17:22:59 +01:00
|
|
|
for (int i = _managed_objects.size() - 1; i >= 0; --i) {
|
|
|
|
delete _managed_objects[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
_managed_objects.clear();
|
|
|
|
|
|
|
|
_instance = nullptr;
|
2022-02-05 19:48:41 +01:00
|
|
|
|
|
|
|
RLOG_MSG("(RCPPFramework) uninitialized!");
|
2022-02-05 17:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RCPPFramework *RCPPFramework::get_singleton() {
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCPPFramework *RCPPFramework::_instance = nullptr;
|
2022-02-05 18:17:36 +01:00
|
|
|
|
|
|
|
void RCPPFramework::_do_initialize() {
|
|
|
|
#if DATABASES_ENABLED
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Initializing database backends!");
|
2022-02-05 18:17:36 +01:00
|
|
|
initialize_database_backends();
|
|
|
|
#endif
|
|
|
|
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Initializing hash providers!");
|
2022-02-05 18:17:36 +01:00
|
|
|
backend_hash_hashlib_install_providers();
|
|
|
|
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Initializing platforms!");
|
2022-02-05 18:17:36 +01:00
|
|
|
PlatformInitializer::allocate_all();
|
2022-02-05 18:26:32 +01:00
|
|
|
|
2022-02-05 19:20:25 +01:00
|
|
|
if (allocate_settings_singleton) {
|
|
|
|
|
|
|
|
Settings *settings = nullptr;
|
|
|
|
|
|
|
|
#if DATABASES_ENABLED
|
|
|
|
if (allocate_db_settings_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Allocating Settings (DBSettings) singleton!");
|
2022-02-05 19:20:25 +01:00
|
|
|
settings = new DBSettings(true);
|
|
|
|
} else {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Allocating Settings (Settings) singleton!");
|
2022-02-05 19:20:25 +01:00
|
|
|
settings = new Settings(true);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
settings = new Settings(true);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
manage_object(settings);
|
|
|
|
}
|
|
|
|
|
2022-02-05 18:26:32 +01:00
|
|
|
#if DATABASES_ENABLED
|
|
|
|
if (allocate_database_manager_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Allocating DatabaseManager singleton!");
|
|
|
|
|
2022-02-05 18:26:32 +01:00
|
|
|
DatabaseManager *dbm = new DatabaseManager();
|
|
|
|
manage_object(dbm);
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-05 18:31:00 +01:00
|
|
|
|
|
|
|
#if WEB_ENABLED
|
|
|
|
if (allocate_session_manager_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Allocating SessionManager singleton!");
|
|
|
|
|
2022-02-05 18:31:00 +01:00
|
|
|
::SessionManager *session_manager = new ::SessionManager();
|
2022-02-05 18:39:27 +01:00
|
|
|
manage_object(session_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allocate_file_cache_singleton) {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Allocating FileCache singleton!");
|
|
|
|
|
2022-02-05 18:39:27 +01:00
|
|
|
FileCache *file_cache = new FileCache(true);
|
|
|
|
manage_object(file_cache);
|
2022-02-05 18:31:00 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-02-05 19:48:41 +01:00
|
|
|
|
|
|
|
RLOG_MSG("(RCPPFramework) Initialized!");
|
2022-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RCPPFramework::_do_uninitialize() {
|
2022-02-05 19:48:41 +01:00
|
|
|
RLOG_MSG("(RCPPFramework) Deleting managed objects!");
|
|
|
|
for (int i = _managed_objects.size() - 1; i >= 0; --i) {
|
|
|
|
delete _managed_objects[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
_managed_objects.clear();
|
|
|
|
|
|
|
|
RLOG_MSG("(RCPPFramework) Freeing platforms!");
|
2022-02-05 18:17:36 +01:00
|
|
|
PlatformInitializer::free_all();
|
2022-02-05 19:48:41 +01:00
|
|
|
|
|
|
|
RLOG_MSG("(RCPPFramework) Uninitialized!");
|
2022-02-05 18:17:36 +01:00
|
|
|
}
|