aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-27 22:29:33 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-27 22:29:33 +0200
commit75bb620cb6257d946e578ed2eda71d57c6796af1 (patch)
treeaee76f6826bd94c6c6560b821e2a080b2f895233 /src
parent0f69ca4bff8605ac69b3a8874d0319b7f711e63a (diff)
parent80210376f3fb80116f4592dd206247bf82fd7edc (diff)
downloadmonzero-gui-75bb620cb6257d946e578ed2eda71d57c6796af1.tar.gz
monzero-gui-75bb620cb6257d946e578ed2eda71d57c6796af1.tar.xz
monzero-gui-75bb620cb6257d946e578ed2eda71d57c6796af1.zip
Merge pull request #492
8021037 pause refresh while starting daemon + startup timeout (Jaquee) df60c81 add start/pauseRefresh() (Jaquee) 2ed59f4 Daemon manager improvements (Jaquee)
Diffstat (limited to 'src')
-rw-r--r--src/daemon/DaemonManager.cpp97
-rw-r--r--src/daemon/DaemonManager.h6
-rw-r--r--src/libwalletqt/Wallet.cpp10
-rw-r--r--src/libwalletqt/Wallet.h4
4 files changed, 108 insertions, 9 deletions
diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp
index 606448d9..47ad10cf 100644
--- a/src/daemon/DaemonManager.cpp
+++ b/src/daemon/DaemonManager.cpp
@@ -7,6 +7,11 @@
#include <QtConcurrent/QtConcurrent>
#include <QApplication>
#include <QProcess>
+#include <QTime>
+
+namespace {
+ static const int DAEMON_START_TIMEOUT_SECONDS = 30;
+}
DaemonManager * DaemonManager::m_instance = nullptr;
QStringList DaemonManager::m_clArgs;
@@ -69,23 +74,93 @@ bool DaemonManager::start(const QString &flags, bool testnet)
if (!started) {
qDebug() << "Daemon start error: " + m_daemon->errorString();
- } else {
- emit daemonStarted();
+ emit daemonStartFailure();
+ return false;
}
- return started;
+ // Start start watcher
+ QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::startWatcher, testnet);
+ QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
+ connect(watcher, &QFutureWatcher<bool>::finished,
+ this, [this, watcher]() {
+ QFuture<bool> future = watcher->future();
+ watcher->deleteLater();
+ if(future.result())
+ emit daemonStarted();
+ else
+ emit daemonStartFailure();
+ });
+ watcher->setFuture(future);
+
+
+ return true;
}
bool DaemonManager::stop(bool testnet)
{
QString message;
- bool stopped = sendCommand("exit",testnet,message);
+ sendCommand("exit",testnet,message);
qDebug() << message;
- if(stopped)
- emit daemonStopped();
- return stopped;
+
+ // Start stop watcher - Will kill if not shutting down
+ QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::stopWatcher, testnet);
+ QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
+ connect(watcher, &QFutureWatcher<bool>::finished,
+ this, [this, watcher]() {
+ QFuture<bool> future = watcher->future();
+ watcher->deleteLater();
+ if(future.result()) {
+ emit daemonStopped();
+ }
+ });
+ watcher->setFuture(future);
+
+ return true;
+}
+
+bool DaemonManager::startWatcher(bool testnet) const
+{
+ // Check if daemon is started every 2 seconds
+ QTime timer;
+ timer.restart();
+ while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) {
+ QThread::sleep(2);
+ if(!running(testnet)) {
+ qDebug() << "daemon not running. checking again in 2 seconds.";
+ } else {
+ qDebug() << "daemon is started. Waiting 5 seconds to let daemon catch up";
+ QThread::sleep(5);
+ return true;
+ }
+ }
+ return false;
}
+bool DaemonManager::stopWatcher(bool testnet) const
+{
+ // Check if daemon is running every 2 seconds. Kill if still running after 10 seconds
+ int counter = 0;
+ while(true && !m_app_exit) {
+ QThread::sleep(2);
+ counter++;
+ if(running(testnet)) {
+ qDebug() << "Daemon still running. " << counter;
+ if(counter >= 5) {
+ qDebug() << "Killing it! ";
+#ifdef Q_OS_WIN
+ QProcess::execute("taskkill /F /IM monerod.exe");
+#else
+ QProcess::execute("pkill monerod");
+#endif
+ }
+
+ } else
+ return true;
+ }
+ return false;
+}
+
+
void DaemonManager::stateChanged(QProcess::ProcessState state)
{
qDebug() << "STATE CHANGED: " << state;
@@ -124,10 +199,8 @@ bool DaemonManager::running(bool testnet) const
// `./monerod status` returns BUSY when syncing.
// Treat busy as connected, until fixed upstream.
if (status.contains("Height:") || status.contains("BUSY") ) {
- emit daemonStarted();
return true;
}
- emit daemonStopped();
return false;
}
bool DaemonManager::sendCommand(const QString &cmd,bool testnet) const
@@ -155,6 +228,12 @@ bool DaemonManager::sendCommand(const QString &cmd,bool testnet, QString &messag
return started;
}
+void DaemonManager::exit()
+{
+ qDebug("DaemonManager: exit()");
+ m_app_exit = true;
+}
+
DaemonManager::DaemonManager(QObject *parent)
: QObject(parent)
{
diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h
index bd13ef60..428630e1 100644
--- a/src/daemon/DaemonManager.h
+++ b/src/daemon/DaemonManager.h
@@ -20,12 +20,17 @@ public:
Q_INVOKABLE bool running(bool testnet) const;
// Send daemon command from qml and prints output in console window.
Q_INVOKABLE bool sendCommand(const QString &cmd, bool testnet) const;
+ Q_INVOKABLE void exit();
private:
+
bool sendCommand(const QString &cmd, bool testnet, QString &message) const;
+ bool startWatcher(bool testnet) const;
+ bool stopWatcher(bool testnet) const;
signals:
void daemonStarted() const;
void daemonStopped() const;
+ void daemonStartFailure() const;
void daemonConsoleUpdated(QString message) const;
public slots:
@@ -41,6 +46,7 @@ private:
bool initialized = false;
QString m_monerod;
bool m_has_daemon = true;
+ bool m_app_exit = false;
};
diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp
index 2b36920f..547596fa 100644
--- a/src/libwalletqt/Wallet.cpp
+++ b/src/libwalletqt/Wallet.cpp
@@ -302,6 +302,16 @@ int Wallet::autoRefreshInterval() const
return m_walletImpl->autoRefreshInterval();
}
+void Wallet::startRefresh() const
+{
+ m_walletImpl->startRefresh();
+}
+
+void Wallet::pauseRefresh() const
+{
+ m_walletImpl->pauseRefresh();
+}
+
PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,
PendingTransaction::Priority priority)
diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h
index a11cabe9..c75f53b1 100644
--- a/src/libwalletqt/Wallet.h
+++ b/src/libwalletqt/Wallet.h
@@ -146,6 +146,10 @@ public:
//! return auto-refresh interval in seconds
Q_INVOKABLE int autoRefreshInterval() const;
+ // pause/resume refresh
+ Q_INVOKABLE void startRefresh() const;
+ Q_INVOKABLE void pauseRefresh() const;
+
//! creates transaction
Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,