-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrcpp_framework.cpp
More file actions
231 lines (169 loc) · 5.08 KB
/
rcpp_framework.cpp
File metadata and controls
231 lines (169 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include "rcpp_framework.h"
#include "core/error_macros.h"
#include "core/settings/settings.h"
#if DATABASES_ENABLED
#include "database/database_manager.h"
#include "database_backends/db_init.h"
#include "database_modules/db_settings/db_settings.h"
#endif
#if WEB_ENABLED
#include "web/file_cache.h"
#include "web/http/session_manager.h"
#endif
#include "platform/platform_initializer.h"
// Backends
#include "crypto_backends/hash_hashlib/setup.h"
void RCPPFramework::create() {
new RCPPFramework();
}
void RCPPFramework::destroy() {
_instance->uninitialize();
delete _instance;
}
void RCPPFramework::create_and_init() {
new RCPPFramework();
RCPPFramework::get_singleton()->initialize();
}
void RCPPFramework::create_and_init(int argc, char **argv, char **envp) {
new RCPPFramework();
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();
}
void RCPPFramework::initialize(int argc, char **argv, char **envp) {
initialize();
setup_args(argc, argv, envp);
}
void RCPPFramework::setup_args(int argc, char **argv, char **envp) {
ERR_FAIL_COND(!_initialized);
PlatformInitializer::arg_setup(argc, argv, envp);
}
void RCPPFramework::uninitialize() {
_do_uninitialize();
}
void RCPPFramework::load() {
#if DATABASES_ENABLED
if (allocate_settings_singleton && allocate_db_settings_singleton) {
RLOG_MSG("(RCPPFramework) Loading DBSettings singleton!");
DBSettings::get_singleton()->load();
}
#endif
#if WEB_ENABLED
if (allocate_session_manager_singleton) {
RLOG_MSG("(RCPPFramework) Loading SessionManager singleton!");
::SessionManager::get_singleton()->load_sessions();
}
if (allocate_file_cache_singleton && www_root != "") {
RLOG_MSG("(RCPPFramework) Loading FileCache singleton!");
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) {
RLOG_MSG("(RCPPFramework) Migrating DBSettings singleton!");
DBSettings::get_singleton()->migrate();
}
#endif
#if WEB_ENABLED
if (allocate_session_manager_singleton) {
RLOG_MSG("(RCPPFramework) Migrating SessionManager singleton!");
::SessionManager::get_singleton()->migrate();
}
#endif
}
void RCPPFramework::manage_object(Object *obj) {
ERR_FAIL_COND(!_initialized);
ERR_FAIL_COND(!obj);
_managed_objects.push_back(obj);
}
RCPPFramework::RCPPFramework() {
_instance = this;
_initialized = false;
allocate_settings_singleton = true;
#if DATABASES_ENABLED
allocate_database_manager_singleton = true;
allocate_db_settings_singleton = true;
#endif
#if WEB_ENABLED
allocate_session_manager_singleton = true;
allocate_file_cache_singleton = true;
#endif
}
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;
RLOG_MSG("(RCPPFramework) uninitialized!");
}
RCPPFramework *RCPPFramework::get_singleton() {
return _instance;
}
RCPPFramework *RCPPFramework::_instance = nullptr;
void RCPPFramework::_do_initialize() {
#if DATABASES_ENABLED
RLOG_MSG("(RCPPFramework) Initializing database backends!");
initialize_database_backends();
#endif
RLOG_MSG("(RCPPFramework) Initializing hash providers!");
backend_hash_hashlib_install_providers();
RLOG_MSG("(RCPPFramework) Initializing platforms!");
PlatformInitializer::allocate_all();
if (allocate_settings_singleton) {
Settings *settings = nullptr;
#if DATABASES_ENABLED
if (allocate_db_settings_singleton) {
RLOG_MSG("(RCPPFramework) Allocating Settings (DBSettings) singleton!");
settings = new DBSettings(true);
} else {
RLOG_MSG("(RCPPFramework) Allocating Settings (Settings) singleton!");
settings = new Settings(true);
}
#else
settings = new Settings(true);
#endif
manage_object(settings);
}
#if DATABASES_ENABLED
if (allocate_database_manager_singleton) {
RLOG_MSG("(RCPPFramework) Allocating DatabaseManager singleton!");
DatabaseManager *dbm = new DatabaseManager();
manage_object(dbm);
}
#endif
#if WEB_ENABLED
if (allocate_session_manager_singleton) {
RLOG_MSG("(RCPPFramework) Allocating SessionManager singleton!");
::SessionManager *session_manager = new ::SessionManager();
manage_object(session_manager);
}
if (allocate_file_cache_singleton) {
RLOG_MSG("(RCPPFramework) Allocating FileCache singleton!");
FileCache *file_cache = new FileCache(true);
manage_object(file_cache);
}
#endif
RLOG_MSG("(RCPPFramework) Initialized!");
}
void RCPPFramework::_do_uninitialize() {
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!");
PlatformInitializer::free_all();
RLOG_MSG("(RCPPFramework) Uninitialized!");
}