aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorJaquee <jaquee.monero@gmail.com>2017-02-23 19:47:58 +0100
committerJaquee <jaquee.monero@gmail.com>2017-02-23 19:52:06 +0100
commitfaacd3d6a11efcb6dcf9a54ce55ed20e573b40f5 (patch)
treeed5d7ba5a02dcdc5d705b71075e2d0f8bc03c9f6 /src/daemon
parentc6688dc876d4ab8e0cea6f34f4607bf3be9a3648 (diff)
downloadmonzero-gui-faacd3d6a11efcb6dcf9a54ce55ed20e573b40f5.tar.gz
monzero-gui-faacd3d6a11efcb6dcf9a54ce55ed20e573b40f5.tar.xz
monzero-gui-faacd3d6a11efcb6dcf9a54ce55ed20e573b40f5.zip
start daemon automatically and detached
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/DaemonManager.cpp77
-rw-r--r--src/daemon/DaemonManager.h19
2 files changed, 45 insertions, 51 deletions
diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp
index 5298743a..dd08feb9 100644
--- a/src/daemon/DaemonManager.cpp
+++ b/src/daemon/DaemonManager.cpp
@@ -23,10 +23,14 @@ DaemonManager *DaemonManager::instance(const QStringList *args)
return m_instance;
}
-bool DaemonManager::start(const QString &flags)
+bool DaemonManager::start(const QString &flags, bool testnet)
{
// prepare command line arguments and pass to monerod
QStringList arguments;
+ arguments << "--detach";
+ if(testnet)
+ arguments << "--testnet";
+
foreach (const QString &str, m_clArgs) {
qDebug() << QString(" [%1] ").arg(str);
if (!str.isEmpty())
@@ -52,8 +56,7 @@ bool DaemonManager::start(const QString &flags)
connect (m_daemon, SIGNAL(readyReadStandardError()), this, SLOT(printError()));
// Start monerod
- m_daemon->start(m_monerod, arguments);
- bool started = m_daemon->waitForStarted();
+ bool started = m_daemon->startDetached(m_monerod, arguments);
// add state changed listener
connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState)));
@@ -67,16 +70,14 @@ bool DaemonManager::start(const QString &flags)
return started;
}
-bool DaemonManager::stop()
+bool DaemonManager::stop(bool testnet)
{
- if (initialized) {
- qDebug() << "stopping daemon";
- // we can't use QProcess::terminate() on windows console process
- // write exit command to stdin
- m_daemon->write("exit\n");
- }
-
- return true;
+ QString message;
+ bool stopped = sendCommand("exit",testnet,message);
+ qDebug() << message;
+ if(stopped)
+ emit daemonStopped();
+ return stopped;
}
void DaemonManager::stateChanged(QProcess::ProcessState state)
@@ -109,40 +110,42 @@ void DaemonManager::printError()
}
}
-bool DaemonManager::running() const
-{
- if (initialized) {
- qDebug() << m_daemon->state();
- qDebug() << QProcess::NotRunning;
- // m_daemon->write("status\n");
- return m_daemon->state() > QProcess::NotRunning;
+bool DaemonManager::running(bool testnet) const
+{
+ QString status;
+ sendCommand("status",testnet, status);
+ qDebug() << status;
+ // `./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)
+bool DaemonManager::sendCommand(const QString &cmd,bool testnet) const
{
- // If daemon is started by GUI - interactive mode
- if (initialized && running()) {
- m_daemon->write(cmd.toUtf8() +"\n");
- return true;
- }
+ QString message;
+ return sendCommand(cmd, testnet, message);
+}
- // else send external command
+bool DaemonManager::sendCommand(const QString &cmd,bool testnet, QString &message) const
+{
QProcess p;
QString external_cmd = m_monerod + " " + cmd;
+ qDebug() << "sending external cmd: " << external_cmd;
- // Add nestnet flag if needed
+ // Add testnet flag if needed
if (testnet)
external_cmd += " --testnet";
external_cmd += "\n";
p.start(external_cmd);
- bool started = p.waitForFinished(-1);
- QString p_stdout = p.readAllStandardOutput();
- qDebug() << p_stdout;
- emit daemonConsoleUpdated(p_stdout);
+ bool started = p.waitForFinished(-1);
+ message = p.readAllStandardOutput();
+ emit daemonConsoleUpdated(message);
return started;
}
@@ -162,13 +165,3 @@ DaemonManager::DaemonManager(QObject *parent)
m_has_daemon = false;
}
}
-
-void DaemonManager::closing()
-{
- qDebug() << __FUNCTION__;
- stop();
- // Wait for daemon to stop before exiting (max 10 secs)
- if (initialized) {
- m_daemon->waitForFinished(10000);
- }
-}
diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h
index 2a2b38df..bd13ef60 100644
--- a/src/daemon/DaemonManager.h
+++ b/src/daemon/DaemonManager.h
@@ -13,26 +13,27 @@ public:
static DaemonManager * instance(const QStringList *args);
- Q_INVOKABLE bool start(const QString &flags);
- Q_INVOKABLE bool stop();
+ Q_INVOKABLE bool start(const QString &flags, bool testnet);
+ Q_INVOKABLE bool stop(bool testnet);
// return true if daemon process is started
- Q_INVOKABLE bool running() const;
- Q_INVOKABLE bool sendCommand(const QString &cmd, bool testnet);
+ 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;
+private:
+ bool sendCommand(const QString &cmd, bool testnet, QString &message) const;
signals:
- void daemonStarted();
- void daemonStopped();
- void daemonConsoleUpdated(QString message);
+ void daemonStarted() const;
+ void daemonStopped() const;
+ void daemonConsoleUpdated(QString message) const;
public slots:
void printOutput();
void printError();
- void closing();
void stateChanged(QProcess::ProcessState state);
private:
-
explicit DaemonManager(QObject *parent = 0);
static DaemonManager * m_instance;
static QStringList m_clArgs;