-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (96 loc) · 2.99 KB
/
main.cpp
File metadata and controls
120 lines (96 loc) · 2.99 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
#include <QtCore/QCoreApplication>
#include <iostream>
#include "server.h"
#include "Controllers/RoomController/RoomController.h"
#include "Entities/Enums/Enums.h"
#include "DBRoom.h"
#include "DBService.h"
#include <plog/Log.h>
#include <plog/Initializers/RollingFileInitializer.h>
#include <plog/Appenders/ColorConsoleAppender.h>
#include "RoomRepository.h"
#include "UserRepository.h"
#include "MessageSaver_Service.h"
#if defined (Q_OS_WIN)
#include "Core/async_console_win.h"
#else
#endif
#include "LocalStorage_Service.h"
Server server; //create server instace
asyncConsoleWin* asyncConsole;
static void shutdown_routine()
{
qDebug() << "The server shatdown.";
}
static void startup_routine()
{
// add QT post exit rotine
qAddPostRoutine(shutdown_routine);
// set up some application settings
qApp->setOrganizationName("C++ Final Project"); // through macro
qApp->setApplicationName("InetChat");
// add a routine to be executed just before application exits through signal
QObject::connect(qApp, &QCoreApplication::aboutToQuit, []()
{
qDebug() << "AboutToQuit : InetChat finishing...";
}
);
// register some meta types
qRegisterMetaType<RoomController>();
static plog::RollingFileAppender<plog::TxtFormatter> fileAppender("log.txt", 1000000, 5);
static plog::ColorConsoleAppender<plog::TxtFormatter> consoleAppender;
plog::init(plog::debug, &consoleAppender).addAppender(&fileAppender);
PLOGD << "Console logging enabled";
PLOGD << "Server application starting. Logging is enabled.";
#if defined (Q_OS_WIN)
//(void)new asyncConsoleWin(qApp);
asyncConsole = new asyncConsoleWin(qApp);
QObject::connect(asyncConsole, &asyncConsoleWin::startServer, &server, &Server::startServer);
QObject::connect(asyncConsole, &asyncConsoleWin::stopServer, &server, &Server::stopServer);
QObject::connect(&server, &Server::logMessage, asyncConsole, &asyncConsoleWin::logMessage);
#else
qDebug() << "AsyncConsoleWin can't be loaded! Curent OS doesnt support.";
PLOGD << "AsyncConsoleWin can't be loaded! Curent OS doesnt support.";
#endif
QTimer::singleShot(0, [&]()
{
//MessageSaver_Service::start(0.05);
});
QTimer::singleShot(0, [&]()
{
server.startServer();
});
}
Q_COREAPP_STARTUP_FUNCTION(startup_routine)
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
//Logger severity
//enum Severity
//{
// none = 0,
// fatal = 1,
// error = 2,
// warning = 3,
// info = 4,
// debug = 5,
// verbose = 6
//};
//Short simple macros
//PLOGV << "verbose";
//PLOGD << "debug";
//PLOGI << "info";
//PLOGW << "warning";
//PLOGE << "error";
//PLOGF << "fatal";
//PLOGN << "none";
//Conditional macros
//PLOGV_IF(cond) << "verbose";
//PLOGD_IF(cond) << "debug";
//PLOGI_IF(cond) << "info";
//PLOGW_IF(cond) << "warning";
//PLOGE_IF(cond) << "error";
//PLOGF_IF(cond) << "fatal";
//PLOGN_IF(cond) << "none";