From aad59b53c34c235e85de56e18208a2aec46fcb22 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 5 Feb 2022 19:29:20 +0100 Subject: [PATCH] Added load anf migrate methods to RCPPFramework, so it can call it's managed singleton's related methods easily. Also Moved www root evaluation to load(). --- rcpp_framework.cpp | 40 ++++++++++++++++++++++++++++++++++------ rcpp_framework.h | 19 +++++++++++-------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/rcpp_framework.cpp b/rcpp_framework.cpp index 960ca19..8343d6a 100644 --- a/rcpp_framework.cpp +++ b/rcpp_framework.cpp @@ -67,9 +67,42 @@ void RCPPFramework::uninitialize() { delete _instance; } +void RCPPFramework::load() { +#if DATABASES_ENABLED + if (allocate_settings_singleton && allocate_db_settings_singleton) { + DBSettings::get_singleton()->load(); + } +#endif + +#if WEB_ENABLED + if (allocate_session_manager_singleton) { + ::SessionManager::get_singleton()->load_sessions(); + } + + if (allocate_file_cache_singleton && www_root != "") { + 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) { + DBSettings::get_singleton()->migrate(); + } +#endif + +#if WEB_ENABLED + if (allocate_session_manager_singleton) { + ::SessionManager::get_singleton()->migrate(); + } +#endif +} + void RCPPFramework::manage_object(Object *obj) { ERR_FAIL_COND(!_initialized); - ERR_FAIL_COND(obj); + ERR_FAIL_COND(!obj); _managed_objects.push_back(obj); } @@ -152,11 +185,6 @@ void RCPPFramework::_do_initialize() { 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(); - } } #endif } diff --git a/rcpp_framework.h b/rcpp_framework.h index bfa9af3..b1af735 100644 --- a/rcpp_framework.h +++ b/rcpp_framework.h @@ -19,11 +19,14 @@ public: static void create_and_init(int argc, char **argv, char **envp); void initialize(); - void initialize(int argc, char **argv, char **envp); + void initialize(int argc, char **argv, char **envp); void uninitialize(); void setup_args(int argc, char **argv, char **envp); + virtual void load(); + virtual void migrate(); + void manage_object(Object *obj); RCPPFramework(); @@ -31,22 +34,22 @@ public: static RCPPFramework *get_singleton(); - bool allocate_settings_singleton; + bool allocate_settings_singleton; #if DATABASES_ENABLED bool allocate_database_manager_singleton; - // TODO Need a define for this - bool allocate_db_settings_singleton; + // TODO Need a define for this + bool allocate_db_settings_singleton; #endif #if WEB_ENABLED bool allocate_session_manager_singleton; - bool allocate_file_cache_singleton; + bool allocate_file_cache_singleton; - // By default it's set to "". - // It will be ignored if you leave it. - String www_root; + // By default it's set to "". + // It will be ignored if you leave it. + String www_root; #endif protected: