From af1d09d0b1b1b447436bce77997a4a24a04a3fa1 Mon Sep 17 00:00:00 2001 From: nonlin-lin-chaos-order-etc-etal Date: Thu, 6 Apr 2023 00:12:08 +0800 Subject: [PATCH] Dissect DaemonQT.* into the app launcher and daemon controller --- i2pd_qt.pro | 6 +- .../i2pd_daemon_controller.cpp} | 54 +-------------- .../i2pd_daemon_controller.h} | 6 +- src/launcher/i2pd_qt_launcher.cpp | 65 +++++++++++++++++++ src/launcher/i2pd_qt_launcher.h | 10 +++ src/mainwindow.cpp | 3 +- src/mainwindow.h | 3 +- 7 files changed, 89 insertions(+), 58 deletions(-) rename src/{DaemonQT.cpp => controller/i2pd_daemon_controller.cpp} (67%) rename src/{DaemonQT.h => controller/i2pd_daemon_controller.h} (94%) create mode 100644 src/launcher/i2pd_qt_launcher.cpp create mode 100644 src/launcher/i2pd_qt_launcher.h diff --git a/i2pd_qt.pro b/i2pd_qt.pro index 58667c7..3028167 100644 --- a/i2pd_qt.pro +++ b/i2pd_qt.pro @@ -38,7 +38,8 @@ CONFIG(release, debug|release) { } SOURCES += \ - src/DaemonQT.cpp \ + src/launcher/i2pd_qt_launcher.cpp \ + src/controller/i2pd_daemon_controller.cpp \ src/MutexWrapperLock.cpp \ src/mainwindow.cpp \ src/ClientTunnelPane.cpp \ @@ -67,7 +68,8 @@ SOURCES += \ HEADERS += \ src/ConcurrentHolder.h \ - src/DaemonQT.h \ + src/launcher/i2pd_qt_launcher.h \ + src/controller/i2pd_daemon_controller.h \ src/MutexWrapperLock.h \ src/mainwindow.h \ src/ClientTunnelPane.h \ diff --git a/src/DaemonQT.cpp b/src/controller/i2pd_daemon_controller.cpp similarity index 67% rename from src/DaemonQT.cpp rename to src/controller/i2pd_daemon_controller.cpp index e9bd592..47596a2 100644 --- a/src/DaemonQT.cpp +++ b/src/controller/i2pd_daemon_controller.cpp @@ -1,6 +1,6 @@ #include -#include "DaemonQT.h" +#include "controller/i2pd_daemon_controller.h" #include "Daemon.h" #include "mainwindow.h" @@ -11,12 +11,8 @@ #include #include -//#define DEBUG_WITH_DEFAULT_LOGGING (1) - -namespace i2p -{ -namespace qt -{ +namespace i2p { +namespace qt { Worker::Worker (DaemonQTImpl& daemon): m_Daemon (daemon) { @@ -146,50 +142,6 @@ namespace qt m_RunningChangedCallback(); } } - - int RunQT (int argc, char* argv[]) - { - QApplication app(argc, argv); - int result; - - { - std::shared_ptr logstreamptr= -#ifdef DEBUG_WITH_DEFAULT_LOGGING - nullptr -#else - std::make_shared() -#endif - ; - //TODO move daemon init deinit to a bg thread - DaemonQTImpl daemon; - if(logstreamptr) (*logstreamptr) << "Initialising the daemon..." << std::endl; - bool daemonInitSuccess = daemon.init(argc, argv, logstreamptr); - if(!daemonInitSuccess) - { - QMessageBox::critical(0, "Error", "Daemon init failed"); - return 1; - } - LogPrint(eLogDebug, "Initialised, creating the main window..."); - MainWindow w(logstreamptr); - LogPrint(eLogDebug, "Before main window.show()..."); - w.show (); - - { - i2p::qt::Controller daemonQtController(daemon); - w.setI2PController(&daemonQtController); - LogPrint(eLogDebug, "Starting the daemon..."); - emit daemonQtController.startDaemon(); - //daemon.start (); - LogPrint(eLogDebug, "Starting GUI event loop..."); - result = app.exec(); - //daemon.stop (); - } - } - - //QMessageBox::information(&w, "Debug", "demon stopped"); - LogPrint(eLogDebug, "Exiting the application"); - return result; - } } } diff --git a/src/DaemonQT.h b/src/controller/i2pd_daemon_controller.h similarity index 94% rename from src/DaemonQT.h rename to src/controller/i2pd_daemon_controller.h index aa329f5..4bc6449 100644 --- a/src/DaemonQT.h +++ b/src/controller/i2pd_daemon_controller.h @@ -1,5 +1,5 @@ -#ifndef DAEMONQT_H -#define DAEMONQT_H +#ifndef I2PD_DAEMON_CONTROLLER_H +#define I2PD_DAEMON_CONTROLLER_H #include #include @@ -85,4 +85,4 @@ namespace qt } } -#endif // DAEMONQT_H +#endif // I2PD_DAEMON_CONTROLLER_H diff --git a/src/launcher/i2pd_qt_launcher.cpp b/src/launcher/i2pd_qt_launcher.cpp new file mode 100644 index 0000000..a98107e --- /dev/null +++ b/src/launcher/i2pd_qt_launcher.cpp @@ -0,0 +1,65 @@ +#include + +#include "launcher/i2pd_qt_launcher.h" +#include "controller/i2pd_daemon_controller.h" +#include "Daemon.h" +#include "mainwindow.h" + +#include "Log.h" + +#include +#include +#include +#include + +//#define DEBUG_WITH_DEFAULT_LOGGING (1) + +namespace i2p { +namespace qt { + + //TODO rework for clean MVC + int RunQT (int argc, char* argv[]) { + + QApplication app(argc, argv); + + int result; + + { + std::shared_ptr logstreamptr = +#ifdef DEBUG_WITH_DEFAULT_LOGGING + nullptr +#else + std::make_shared() +#endif + ; + //TODO move daemon init deinit to a bg thread + DaemonQTImpl daemon; + if (logstreamptr) (*logstreamptr) << "Initialising the daemon..." << std::endl; + bool daemonInitSuccess = daemon.init(argc, argv, logstreamptr); + if (!daemonInitSuccess) { + QMessageBox::critical(0, "Error", "Daemon init failed"); + return 1; + } + LogPrint(eLogDebug, "Initialised, creating the main window..."); + MainWindow w(logstreamptr); + LogPrint(eLogDebug, "Before main window.show()..."); + w.show (); + + { + i2p::qt::Controller daemonQtController(daemon); + w.setI2PController(&daemonQtController); + LogPrint(eLogDebug, "Starting the daemon..."); + emit daemonQtController.startDaemon(); + //daemon.start (); + LogPrint(eLogDebug, "Starting GUI event loop..."); + result = app.exec(); + //daemon.stop (); + } + } + + //QMessageBox::information(&w, "Debug", "demon stopped"); + LogPrint(eLogDebug, "Exiting the application"); + return result; + } +} +} diff --git a/src/launcher/i2pd_qt_launcher.h b/src/launcher/i2pd_qt_launcher.h new file mode 100644 index 0000000..39418c7 --- /dev/null +++ b/src/launcher/i2pd_qt_launcher.h @@ -0,0 +1,10 @@ +#ifndef I2PD_QT_LAUNCHER_H +#define I2PD_QT_LAUNCHER_H + +namespace i2p { +namespace qt { + int RunQT (int argc, char* argv[]); +} +} + +#endif // I2PD_QT_LAUNCHER_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0d1755e..c6a0e90 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -33,7 +33,8 @@ # include #endif -#include "DaemonQT.h" +#include "controller/i2pd_daemon_controller.h" + #include "SignatureTypeComboboxFactory.h" #include "logviewermanager.h" diff --git a/src/mainwindow.h b/src/mainwindow.h index 3df6f5d..9554814 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -56,7 +56,8 @@ #include "TunnelsPageUpdateListener.h" -#include "DaemonQT.h" +#include "controller/i2pd_daemon_controller.h" + #include "SignatureTypeComboboxFactory.h" #include "pagewithbackbutton.h"