diff options
| author | xiphon <xiphon@protonmail.com> | 2019-09-27 10:56:42 +0000 |
|---|---|---|
| committer | xiphon <xiphon@protonmail.com> | 2019-10-07 10:39:30 +0000 |
| commit | 32257c8fab83cab89811111284cdca8bf5e9dbac (patch) | |
| tree | 73fc6c6320c727728c70ff973b8f19f900d027de /src | |
| parent | d3b81cb6f8b9e79bc8bda675f556d5288916af56 (diff) | |
| download | monzero-gui-32257c8fab83cab89811111284cdca8bf5e9dbac.tar.gz monzero-gui-32257c8fab83cab89811111284cdca8bf5e9dbac.tar.xz monzero-gui-32257c8fab83cab89811111284cdca8bf5e9dbac.zip | |
DaemonManager: implement async sendCommand
Diffstat (limited to 'src')
| -rw-r--r-- | src/daemon/DaemonManager.cpp | 23 | ||||
| -rw-r--r-- | src/daemon/DaemonManager.h | 4 |
2 files changed, 14 insertions, 13 deletions
diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index 0d311535..baabffb4 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -150,7 +150,7 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const bool DaemonManager::stop(NetworkType::Type nettype) { QString message; - sendCommand("exit", nettype, message); + sendCommand({"exit"}, nettype, message); qDebug() << message; // Start stop watcher - Will kill if not shutting down @@ -240,7 +240,7 @@ void DaemonManager::printError() bool DaemonManager::running(NetworkType::Type nettype) const { QString status; - sendCommand("sync_info", nettype, status); + sendCommand({"sync_info"}, nettype, status); qDebug() << status; return status.contains("Height:"); } @@ -257,17 +257,10 @@ void DaemonManager::runningAsync(NetworkType::Type nettype, const QJSValue& call }, callback); } -bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype) const -{ - QString message; - return sendCommand(cmd, nettype, message); -} - -bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype, QString &message) const +bool DaemonManager::sendCommand(const QStringList &cmd, NetworkType::Type nettype, QString &message) const { QProcess p; - QStringList external_cmd; - external_cmd << cmd; + QStringList external_cmd(cmd); // Add network type flag if needed if (nettype == NetworkType::TESTNET) @@ -286,6 +279,14 @@ bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype, Q return started; } +void DaemonManager::sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const +{ + m_scheduler.run([this, cmd, nettype] { + QString message; + return QJSValueList({sendCommand(cmd, nettype, message)}); + }, callback); +} + void DaemonManager::exit() { qDebug("DaemonManager: exit()"); diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index 0df97c63..a03d3d9b 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -51,14 +51,14 @@ public: // return true if daemon process is started Q_INVOKABLE void runningAsync(NetworkType::Type nettype, const QJSValue& callback) const; // Send daemon command from qml and prints output in console window. - Q_INVOKABLE bool sendCommand(const QString &cmd, NetworkType::Type nettype) const; + Q_INVOKABLE void sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const; Q_INVOKABLE void exit(); Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const; private: bool running(NetworkType::Type nettype) const; - bool sendCommand(const QString &cmd, NetworkType::Type nettype, QString &message) const; + bool sendCommand(const QStringList &cmd, NetworkType::Type nettype, QString &message) const; bool startWatcher(NetworkType::Type nettype) const; bool stopWatcher(NetworkType::Type nettype) const; signals: |
