From a3d2c1aa663c6a5493901d4fa0ce1730d0a390ba Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 23 Aug 2020 14:43:19 -0500 Subject: [PATCH] start implemented the actual server --- include/advertiser.h | 2 +- include/akashimain.h | 2 ++ include/config_manager.h | 2 +- include/server.h | 13 +++++++++++-- src/akashimain.cpp | 21 ++++++++++++++------- src/config_manager.cpp | 3 +-- src/server.cpp | 8 +++++++- 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/include/advertiser.h b/include/advertiser.h index 205ee9b..d6badf4 100644 --- a/include/advertiser.h +++ b/include/advertiser.h @@ -8,7 +8,7 @@ #include #include -class Advertiser : public QObject{ +class Advertiser : public QObject { Q_OBJECT public: diff --git a/include/akashimain.h b/include/akashimain.h index 043fe2e..64d1c60 100644 --- a/include/akashimain.h +++ b/include/akashimain.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -28,5 +29,6 @@ public: private: Ui::AkashiMain *ui; Advertiser *advertiser; + Server *server; }; #endif // AKASHIMAIN_H diff --git a/include/config_manager.h b/include/config_manager.h index a0b60c4..04e133c 100644 --- a/include/config_manager.h +++ b/include/config_manager.h @@ -15,7 +15,7 @@ public: void generateDefaultConfig(bool backup_old); void updateConfig(int current_version); - bool loadAdvertiserSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server); + bool loadServerSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server); private: QSettings* config; diff --git a/include/server.h b/include/server.h index 5cbd237..db8468e 100644 --- a/include/server.h +++ b/include/server.h @@ -1,11 +1,20 @@ #ifndef SERVER_H #define SERVER_H +#include +#include -class Server +class Server : public QObject { + Q_OBJECT + public: - Server(); + Server(int p_port, int p_ws_port); + void start(); + +private: + int port; + int ws_port; }; #endif // SERVER_H diff --git a/src/akashimain.cpp b/src/akashimain.cpp index f7f34a7..3990a6e 100644 --- a/src/akashimain.cpp +++ b/src/akashimain.cpp @@ -12,18 +12,25 @@ AkashiMain::AkashiMain(QWidget *parent) if(config_manager.initConfig()) { // Config is sound, so proceed with starting the server - // TODO: start the server here - // TODO: send signal server starting - // Validate some of the config before passing it on QString ms_ip, name, description; int port, ws_port, local_port; bool advertise_server; - config_manager.loadAdvertiserSettings(&ms_ip, &port, &ws_port, &local_port, &name, &description, &advertise_server); + bool config_valid = config_manager.loadServerSettings(&ms_ip, &port, &ws_port, &local_port, &name, &description, &advertise_server); - if(advertise_server){ - advertiser = new Advertiser(ms_ip, port, ws_port, local_port, name, description); - advertiser->contactMasterServer(); + if(!config_valid) { + // TODO: send signal config invalid + config_manager.generateDefaultConfig(true); + } else { + if(advertise_server) { + advertiser = new Advertiser(ms_ip, port, ws_port, local_port, name, description); + advertiser->contactMasterServer(); + } + + // TODO: start the server here + // TODO: send signal server starting. + server = new Server(port, ws_port); + server->start(); } } } diff --git a/src/config_manager.cpp b/src/config_manager.cpp index fe72120..1724344 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -103,9 +103,8 @@ void ConfigManager::updateConfig(int current_version) } // Validate and retriever settings related to advertising and the server -bool ConfigManager::loadAdvertiserSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server) +bool ConfigManager::loadServerSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server) { - // TODO: Move this logic into config_manager.cpp bool port_conversion_success; bool ws_port_conversion_success; bool local_port_conversion_success; diff --git a/src/server.cpp b/src/server.cpp index b9fa72e..b180194 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,6 +1,12 @@ #include "include/server.h" -Server::Server() +Server::Server(int p_port, int p_ws_port) +{ + port = p_port; + ws_port = p_ws_port; +} + +void Server::start() { }