-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
67 lines (58 loc) · 2.76 KB
/
main.cpp
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
#include <QCoreApplication>
#include "handlers/udpsockethandler.h"
#include "handlers/tcpserverhandler.h"
#include "handlers/sqltcpserverhandler.h"
#include "handlers/roomshandler.h"
#include <iostream>
/*! \mainpage qZoom-Server Documentation
*
* \section intro_sec Introduction
*
* This document describes all the C++ classes used in our qZoom Server
*
*/
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("qZoom-Server");
QCoreApplication::setApplicationVersion("1.0");
QCommandLineParser parser;
parser.setApplicationDescription("Hello! This is the current description");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption udpPortNumber(QStringList() << "u" << "udp", QCoreApplication::translate("main", "Sets the port number for the UDP socket"),
QCoreApplication::translate("main", "port number"));
QCommandLineOption tcpPortNumber(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Sets the port number for the TCP socket"),
QCoreApplication::translate("main", "port number"));
QCommandLineOption sqlPortNumber(QStringList() << "s" << "sql", QCoreApplication::translate("main", "Sets the port number for the SQL-TCP socket"),
QCoreApplication::translate("main", "port number"));
parser.addOption(udpPortNumber);
parser.addOption(tcpPortNumber);
parser.addOption(sqlPortNumber);
parser.process(a);
qDebug() << "qZoom-Server running Qt Version: " << QT_VERSION_STR;
int portNumberTCP = parser.isSet(tcpPortNumber) ? parser.value(tcpPortNumber).toInt() : 1338;
if(portNumberTCP < 1024 || portNumberTCP > 49151)
{
printf("TCP port number was not valid, needs to be larger than 1024 and smaller than 49151");
exit(-1);
}
int portNumberUDP = parser.isSet(udpPortNumber) ? parser.value(udpPortNumber).toInt() : 1337;
if(portNumberUDP < 1024 || portNumberUDP > 49151)
{
printf("UDP port number was not valid, needs to be larger than 1024 and smaller than 49151");
exit(-1);
}
int portNumberSQL = parser.isSet(sqlPortNumber) ? parser.value(sqlPortNumber).toInt() : 1339;
if(portNumberUDP < 1024 || portNumberUDP > 49151)
{
printf("SQL-TCP port number was not valid, needs to be larger than 1024 and smaller than 49151");
exit(-1);
}
Database* db = new Database();
RoomsHandler* roomsHandler = new RoomsHandler(db);
new UdpSocketHandler(roomsHandler, portNumberUDP);
new TcpServerHandler(roomsHandler, portNumberTCP);
new SqlTcpServerHandler(portNumberSQL, db, roomsHandler);
return a.exec();
}