From d3102b1cc5ab6d4e66e57ea9c53e32210b5f1083 Mon Sep 17 00:00:00 2001 From: xiphon Date: Thu, 14 Jan 2021 19:14:22 +0000 Subject: [PATCH] DaemonManager: refactoring - drop singleton usage --- src/daemon/DaemonManager.cpp | 23 ----------------------- src/daemon/DaemonManager.h | 9 ++------- src/main/main.cpp | 4 ++-- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index 86c1a2cc..82d9eece 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -47,23 +47,6 @@ namespace { static const int DAEMON_START_TIMEOUT_SECONDS = 120; } -DaemonManager * DaemonManager::m_instance = nullptr; -QStringList DaemonManager::m_clArgs; - -DaemonManager *DaemonManager::instance(const QStringList *args/* = nullptr*/) -{ - if (!m_instance) { - m_instance = new DaemonManager; - // store command line arguments for later use - if (args != nullptr) - { - m_clArgs = *args; - } - } - - return m_instance; -} - bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const QString &dataDir, const QString &bootstrapNodeAddress, bool noSync /* = false*/) { if (!QFileInfo(m_monerod).isFile()) @@ -85,12 +68,6 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const else if (nettype == NetworkType::STAGENET) arguments << "--stagenet"; - foreach (const QString &str, m_clArgs) { - qDebug() << QString(" [%1] ").arg(str); - if (!str.isEmpty()) - arguments << str; - } - // Custom startup flags for daemon foreach (const QString &str, flags.split(" ")) { qDebug() << QString(" [%1] ").arg(str); diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index 812602cd..ac94c50d 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -44,8 +44,8 @@ class DaemonManager : public QObject Q_OBJECT public: - - static DaemonManager * instance(const QStringList *args = nullptr); + explicit DaemonManager(QObject *parent = 0); + ~DaemonManager(); Q_INVOKABLE bool start(const QString &flags, NetworkType::Type nettype, const QString &dataDir = "", const QString &bootstrapNodeAddress = "", bool noSync = false); Q_INVOKABLE void stopAsync(NetworkType::Type nettype, const QJSValue& callback); @@ -76,11 +76,6 @@ public slots: void stateChanged(QProcess::ProcessState state); private: - explicit DaemonManager(QObject *parent = 0); - ~DaemonManager(); - - static DaemonManager * m_instance; - static QStringList m_clArgs; std::unique_ptr m_daemon; QMutex m_daemonMutex; QString m_monerod; diff --git a/src/main/main.cpp b/src/main/main.cpp index 1024feb2..b4e1fe42 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -451,8 +451,8 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw // Exclude daemon manager from IOS #ifndef Q_OS_IOS - DaemonManager * daemonManager = DaemonManager::instance(); - engine.rootContext()->setContextProperty("daemonManager", daemonManager); + DaemonManager daemonManager; + engine.rootContext()->setContextProperty("daemonManager", &daemonManager); #endif engine.rootContext()->setContextProperty("isWindows", isWindows);