From 94c70d1933658df6e846cff80aee8a14184450db Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 10 Nov 2021 12:23:31 +0100 Subject: [PATCH] Uniform ApplicationLauncher API: get rid of reportError() Use existing error() signal instead. Implement errorString() and processError() in non-local case. Change-Id: Ibdd6cec19ffa5efa0dad330515988da80e86e35b Reviewed-by: hjk --- src/plugins/boot2qt/qdbdevice.cpp | 5 ++-- .../boot2qt/qdbstopapplicationservice.cpp | 4 +-- .../projectexplorer/applicationlauncher.cpp | 30 +++++++++++-------- .../projectexplorer/applicationlauncher.h | 1 - src/plugins/projectexplorer/runcontrol.cpp | 7 ++--- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/plugins/boot2qt/qdbdevice.cpp b/src/plugins/boot2qt/qdbdevice.cpp index def8394d838..ade393f363d 100644 --- a/src/plugins/boot2qt/qdbdevice.cpp +++ b/src/plugins/boot2qt/qdbdevice.cpp @@ -79,8 +79,8 @@ public: { connect(&m_appRunner, &ApplicationLauncher::appendMessage, this, &DeviceApplicationObserver::handleAppendMessage); - connect(&m_appRunner, &ApplicationLauncher::reportError, this, - &DeviceApplicationObserver::handleError); + connect(&m_appRunner, &ApplicationLauncher::error, this, + [this] { m_error = m_appRunner.errorString(); }); connect(&m_appRunner, &ApplicationLauncher::finished, this, &DeviceApplicationObserver::handleFinished); @@ -102,7 +102,6 @@ private: else if (format == Utils::StdErrFormat) m_stderr += data; } - void handleError(const QString &message) { m_error = message; } void handleFinished(bool success) { diff --git a/src/plugins/boot2qt/qdbstopapplicationservice.cpp b/src/plugins/boot2qt/qdbstopapplicationservice.cpp index acfc941ff39..98f96616c1e 100644 --- a/src/plugins/boot2qt/qdbstopapplicationservice.cpp +++ b/src/plugins/boot2qt/qdbstopapplicationservice.cpp @@ -88,8 +88,8 @@ void QdbStopApplicationService::handleAppendMessage(const QString &message, Util void QdbStopApplicationService::doDeploy() { - connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::reportError, - this, &QdbStopApplicationService::stdErrData); + connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::error, + this, [this] { emit stdErrData(d->applicationLauncher.errorString()); }); connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished, this, &QdbStopApplicationService::handleProcessFinished); connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage, diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index 4fa653a5052..1c77b7616cc 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -88,7 +88,8 @@ public: bool isRunning() const; // Remote - void doReportError(const QString &message); + void doReportError(const QString &message, + QProcess::ProcessError error = QProcess::FailedToStart); void handleRemoteStderr(); void handleRemoteStdout(); void handleApplicationFinished(); @@ -116,6 +117,8 @@ public: // Remote DeviceProcess *m_deviceProcess = nullptr; + QString m_remoteErrorString; + QProcess::ProcessError m_remoteError = QProcess::UnknownError; State m_state = Inactive; bool m_stopRequested = false; bool m_success = false; @@ -258,18 +261,16 @@ qint64 ApplicationLauncherPrivate::applicationPID() const QString ApplicationLauncher::errorString() const { - if (d->m_useTerminal) - return d->m_consoleProcess.errorString(); - else - return d->m_guiProcess.errorString(); + if (d->m_isLocal) + return d->m_useTerminal ? d->m_consoleProcess.errorString() : d->m_guiProcess.errorString(); + return d->m_remoteErrorString; } QProcess::ProcessError ApplicationLauncher::processError() const { - if (d->m_useTerminal) - return d->m_consoleProcess.error(); - else - return d->m_guiProcess.error(); + if (d->m_isLocal) + return d->m_useTerminal ? d->m_consoleProcess.error() : d->m_guiProcess.error(); + return d->m_remoteError; } void ApplicationLauncherPrivate::localGuiProcessError() @@ -469,11 +470,12 @@ void ApplicationLauncherPrivate::handleApplicationFinished() QTC_ASSERT(m_state == Run, return); if (m_deviceProcess->exitStatus() == QProcess::CrashExit) { - doReportError(m_deviceProcess->errorString()); + doReportError(m_deviceProcess->errorString(), QProcess::Crashed); } else { const int exitCode = m_deviceProcess->exitCode(); if (exitCode != 0) { - doReportError(ApplicationLauncher::tr("Application finished with exit code %1.").arg(exitCode)); + doReportError(ApplicationLauncher::tr("Application finished with exit code %1.") + .arg(exitCode), QProcess::UnknownError); } else { emit q->appendMessage(ApplicationLauncher::tr("Application finished with exit code 0."), Utils::NormalMessageFormat); @@ -496,10 +498,12 @@ void ApplicationLauncherPrivate::handleRemoteStderr() emit q->appendMessage(QString::fromUtf8(output), Utils::StdErrFormat, false); } -void ApplicationLauncherPrivate::doReportError(const QString &message) +void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess::ProcessError error) { + m_remoteErrorString = message; + m_remoteError = error; m_success = false; - emit q->reportError(message); + emit q->error(error); } } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/applicationlauncher.h b/src/plugins/projectexplorer/applicationlauncher.h index a41294c9c3d..07fa19f8ace 100644 --- a/src/plugins/projectexplorer/applicationlauncher.h +++ b/src/plugins/projectexplorer/applicationlauncher.h @@ -74,7 +74,6 @@ signals: void processExited(int exitCode, QProcess::ExitStatus); void error(QProcess::ProcessError error); - void reportError(const QString &errorOutput); void finished(bool success); private: diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index cd672e977ee..506cd5bce3f 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -1252,10 +1252,9 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP } else { - connect(&m_launcher, &ApplicationLauncher::reportError, - this, [this](const QString &msg) { - reportFailure(msg); - }); + connect(&m_launcher, &ApplicationLauncher::error, this, [this] { + reportFailure(m_launcher.errorString()); + }); connect(&m_launcher, &ApplicationLauncher::finished, this, [this] {