-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
109 lines (76 loc) · 2.23 KB
/
main.cpp
File metadata and controls
109 lines (76 loc) · 2.23 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
#include <string.h>
#include <iostream>
#include <string>
#include "core/http/web_application.h"
#include "core/file_cache.h"
#include "core/bry_http/http_server.h"
#include "app/ic_application.h"
#include "core/database/database_manager.h"
#include "database/db_init.h"
#include "core/settings.h"
#include "custom_modules/mqtt_server/mqtt_server.h"
#define MAIN_CLASS ICApplication
void create_databases() {
//Settings *settings = Settings::get_singleton();
//if (!settings) {
// printf("create_databases: Settings singleton is null!");
// return;
//}
/*
rapidjson::Value dbs = settings->settings["databases"];
if (!dbs.IsArray()) {
printf("create_databases: dbs !dbs.IsArray()!");
return;
}
*/
DatabaseManager *dbm = DatabaseManager::get_singleton();
//uint32_t index = dbm->create_database("mysql");
//Database *db = dbm->databases[0];
//db->connect("");
uint32_t index = dbm->create_database("sqlite");
Database *db = dbm->databases[index];
db->connect("database.sqlite");
}
int main(int argc, char **argv) {
bool migrate = false;
for (int i = 1; i < argc; ++i) {
const char *a = argv[i];
if (a[0] == 'm') {
migrate = true;
}
}
initialize_database_backends();
Settings *settings = new Settings(true);
settings->parse_file("settings.json");
FileCache *file_cache = new FileCache(true);
file_cache->wwwroot = "./content/www";
file_cache->wwwroot_refresh_cache();
DatabaseManager *dbm = new DatabaseManager();
create_databases();
WebApplication *app = new MAIN_CLASS();
app->load_settings();
app->setup_routes();
app->setup_middleware();
HTTPServer *server = new HTTPServer();
server->application = app;
server->port = 8080;
server->initialize();
MQTTServer *mqtt_server = new MQTTServer();
mqtt_server->initialize();
mqtt_server->add_local_session("a/b", [](const std::string &client_id, const std::vector<uint8_t> &data, void* obj){ reinterpret_cast<ICApplication*>(obj)->mqtt_sensor_callback(client_id, data); }, app);
if (!migrate) {
printf("Initialized!\n");
mqtt_server->run_async();
server->main_loop();
} else {
printf("Running migrations.\n");
app->migrate();
}
delete mqtt_server;
delete server;
delete app;
delete dbm;
delete file_cache;
delete settings;
return 0;
}