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() {
|
|
|
|
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) {
|
|
|
|
RLOG_ERR("RCPPFramework: has already beed initialized!");
|
|
|
|
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() {
|
|
|
|
delete _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCPPFramework::manage_object(Object *obj) {
|
2022-02-05 19:20:25 +01:00
|
|
|
ERR_FAIL_COND(!_initialized);
|
|
|
|
ERR_FAIL_COND(obj);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
initialize_database_backends();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
backend_hash_hashlib_install_providers();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
settings = new DBSettings(true);
|
|
|
|
} else {
|
|
|
|
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) {
|
|
|
|
DatabaseManager *dbm = new DatabaseManager();
|
|
|
|
manage_object(dbm);
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-05 18:31:00 +01:00
|
|
|
|
|
|
|
#if WEB_ENABLED
|
|
|
|
if (allocate_session_manager_singleton) {
|
|
|
|
::SessionManager *session_manager = new ::SessionManager();
|
2022-02-05 18:39:27 +01:00
|
|
|
manage_object(session_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allocate_file_cache_singleton) {
|
|
|
|
FileCache *file_cache = new FileCache(true);
|
|
|
|
manage_object(file_cache);
|
|
|
|
|
|
|
|
if (www_root != "") {
|
|
|
|
file_cache->wwwroot = www_root;
|
|
|
|
file_cache->wwwroot_refresh_cache();
|
|
|
|
}
|
2022-02-05 18:31:00 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-02-05 18:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RCPPFramework::_do_uninitialize() {
|
|
|
|
PlatformInitializer::free_all();
|
|
|
|
}
|