diff --git a/SConstruct b/SConstruct index e582651..6fdacc3 100644 --- a/SConstruct +++ b/SConstruct @@ -341,6 +341,8 @@ folders = env_base["folders"].split(";") files = [] +files.append("rcpp_framework.cpp") + for fol in folders: folt = fol.strip() diff --git a/init.h b/init.h deleted file mode 100644 index c7184ab..0000000 --- a/init.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef FRAMEWORK_INIT_H -#define FRAMEWORK_INIT_H - -#if DATABASES_ENABLED -#include "database_backends/db_init.h" -#endif - -#include "platform/platform_initializer.h" - -// Backends -#include "crypto_backends/hash_hashlib/setup.h" - -void initialize_framework() { -#if DATABASES_ENABLED - initialize_database_backends(); -#endif - - backend_hash_hashlib_install_providers(); - - PlatformInitializer::allocate_all(); -} - -void initialize_framework_args(int argc, char **argv, char **envp) { - initialize_framework(); - - PlatformInitializer::arg_setup(argc, argv, envp); -} - -void uninitialize_framework() { - PlatformInitializer::free_all(); -} - -#endif \ No newline at end of file diff --git a/rcpp_framework.cpp b/rcpp_framework.cpp new file mode 100644 index 0000000..b9aa6fe --- /dev/null +++ b/rcpp_framework.cpp @@ -0,0 +1,65 @@ +#include "rcpp_framework.h" + +#include "core/error_macros.h" + +#if DATABASES_ENABLED +#include "database_backends/db_init.h" +#endif + +#include "platform/platform_initializer.h" + +// Backends +#include "crypto_backends/hash_hashlib/setup.h" + +void RCPPFramework::initialize() { + if (get_singleton() != nullptr) { + RLOG_ERR("RCPPFramework: has already beed initialized!"); + } + + new RCPPFramework(); + +#if DATABASES_ENABLED + initialize_database_backends(); +#endif + + backend_hash_hashlib_install_providers(); + + PlatformInitializer::allocate_all(); +} + +void RCPPFramework::initialize(int argc, char **argv, char **envp) { + initialize(); + + PlatformInitializer::arg_setup(argc, argv, envp); +} + +void RCPPFramework::uninitialize() { + delete _instance; + + PlatformInitializer::free_all(); +} + +void RCPPFramework::manage_object(Object *obj) { + _managed_objects.push_back(obj); +} + +RCPPFramework::RCPPFramework() { + _instance = this; +} + +RCPPFramework::~RCPPFramework() { + //delete in reverse order added + 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; diff --git a/rcpp_framework.h b/rcpp_framework.h new file mode 100644 index 0000000..80c7a86 --- /dev/null +++ b/rcpp_framework.h @@ -0,0 +1,30 @@ +#ifndef RCPP_FRAMEWORK_H +#define RCPP_FRAMEWORK_H + +#include "core/string.h" +#include "core/containers/vector.h" + +#include "core/object.h" + +class RCPPFramework : Object { + RCPP_OBJECT(RCPPFramework, Object); + +public: + static void initialize(); + static void initialize(int argc, char **argv, char **envp); + static void uninitialize(); + + void manage_object(Object* obj); + + RCPPFramework(); + ~RCPPFramework(); + + static RCPPFramework *get_singleton(); + +protected: + Vector _managed_objects; + + static RCPPFramework *_instance; +}; + +#endif \ No newline at end of file