Removed init.h, and added a new RCPPFramework class instead.

This commit is contained in:
Relintai 2022-02-05 17:22:59 +01:00
parent 1fd817af9c
commit 3757114a21
4 changed files with 97 additions and 33 deletions

View File

@ -341,6 +341,8 @@ folders = env_base["folders"].split(";")
files = []
files.append("rcpp_framework.cpp")
for fol in folders:
folt = fol.strip()

33
init.h
View File

@ -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

65
rcpp_framework.cpp Normal file
View File

@ -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;

30
rcpp_framework.h Normal file
View File

@ -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<Object *> _managed_objects;
static RCPPFramework *_instance;
};
#endif