From 9770b1d0254435d76e9836498ef466283b7a0031 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 5 May 2022 10:37:12 +0200 Subject: [PATCH] Qdb: Replace ApplicationLauncher in QdbStopApplicationStep Change-Id: I0120a96e4289a4b12e31d805d09fca9413624c12 Reviewed-by: Jarek Kobus --- .../boot2qt/qdbstopapplicationstep.cpp | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/plugins/boot2qt/qdbstopapplicationstep.cpp b/src/plugins/boot2qt/qdbstopapplicationstep.cpp index d5650243df8..61a7da53e8f 100644 --- a/src/plugins/boot2qt/qdbstopapplicationstep.cpp +++ b/src/plugins/boot2qt/qdbstopapplicationstep.cpp @@ -27,7 +27,7 @@ #include "qdbconstants.h" -#include +#include #include #include #include @@ -35,6 +35,8 @@ #include +#include + using namespace ProjectExplorer; using namespace Utils; @@ -52,8 +54,7 @@ public: ~QdbStopApplicationService() { cleanup(); } private: - void handleProcessFinished(); - void handleAppendMessage(const QString &message, OutputFormat format); + void handleProcessDone(); bool isDeploymentNecessary() const final { return true; } @@ -62,19 +63,25 @@ private: void cleanup(); - ApplicationLauncher m_applicationLauncher; + QtcProcess m_process; QString m_errorOutput; }; -void QdbStopApplicationService::handleProcessFinished() +void QdbStopApplicationService::handleProcessDone() { const QString failureMessage = tr("Could not check and possibly stop running application."); - if (m_applicationLauncher.exitStatus() == QProcess::CrashExit) { + + if (m_process.exitStatus() == QProcess::CrashExit) { emit errorMessage(failureMessage); stopDeployment(); return; } + if (m_process.result() != ProcessResult::FinishedWithSuccess) { + emit stdErrData(m_process.errorString()); + return; + } + if (m_errorOutput.contains("Could not connect: Connection refused")) { emit progressMessage(tr("Checked that there is no running application.")); } else if (!m_errorOutput.isEmpty()) { @@ -87,30 +94,24 @@ void QdbStopApplicationService::handleProcessFinished() stopDeployment(); } -void QdbStopApplicationService::handleAppendMessage(const QString &message, OutputFormat format) -{ - if (format == StdErrFormat) - m_errorOutput.append(message); - else - emit stdOutData(message); -} - void QdbStopApplicationService::doDeploy() { - connect(&m_applicationLauncher, &ApplicationLauncher::errorOccurred, - this, [this] { emit stdErrData(m_applicationLauncher.errorString()); }); - connect(&m_applicationLauncher, &ApplicationLauncher::finished, - this, &QdbStopApplicationService::handleProcessFinished); - connect(&m_applicationLauncher, &ApplicationLauncher::appendMessage, - this, &QdbStopApplicationService::handleAppendMessage); + auto device = DeviceKitAspect::device(target()->kit()); + QTC_ASSERT(device, return); - Runnable runnable; - runnable.command = {Constants::AppcontrollerFilepath, {"--stop"}}; - runnable.workingDirectory = "/usr/bin"; - runnable.device = DeviceKitAspect::device(target()->kit()); + connect(&m_process, &QtcProcess::done, + this, &QdbStopApplicationService::handleProcessDone); - m_applicationLauncher.setRunnable(runnable); - m_applicationLauncher.start(); + connect(&m_process, &QtcProcess::readyReadStandardError, this, [this] { + m_errorOutput.append(QString::fromUtf8(m_process.readAllStandardError())); + }); + connect(&m_process, &QtcProcess::readyReadStandardOutput, this, [this] { + emit stdOutData(QString::fromUtf8(m_process.readAllStandardOutput())); + }); + + m_process.setCommand({device->mapToGlobalPath(Constants::AppcontrollerFilepath), {"--stop"}}); + m_process.setWorkingDirectory("/usr/bin"); + m_process.start(); } void QdbStopApplicationService::stopDeployment() @@ -121,7 +122,7 @@ void QdbStopApplicationService::stopDeployment() void QdbStopApplicationService::cleanup() { - m_applicationLauncher.disconnect(this); + m_process.close(); }