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 <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2021-11-10 12:23:31 +01:00
parent 971b1b2269
commit 94c70d1933
5 changed files with 24 additions and 23 deletions

View File

@@ -79,8 +79,8 @@ public:
{ {
connect(&m_appRunner, &ApplicationLauncher::appendMessage, this, connect(&m_appRunner, &ApplicationLauncher::appendMessage, this,
&DeviceApplicationObserver::handleAppendMessage); &DeviceApplicationObserver::handleAppendMessage);
connect(&m_appRunner, &ApplicationLauncher::reportError, this, connect(&m_appRunner, &ApplicationLauncher::error, this,
&DeviceApplicationObserver::handleError); [this] { m_error = m_appRunner.errorString(); });
connect(&m_appRunner, &ApplicationLauncher::finished, this, connect(&m_appRunner, &ApplicationLauncher::finished, this,
&DeviceApplicationObserver::handleFinished); &DeviceApplicationObserver::handleFinished);
@@ -102,7 +102,6 @@ private:
else if (format == Utils::StdErrFormat) else if (format == Utils::StdErrFormat)
m_stderr += data; m_stderr += data;
} }
void handleError(const QString &message) { m_error = message; }
void handleFinished(bool success) void handleFinished(bool success)
{ {

View File

@@ -88,8 +88,8 @@ void QdbStopApplicationService::handleAppendMessage(const QString &message, Util
void QdbStopApplicationService::doDeploy() void QdbStopApplicationService::doDeploy()
{ {
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::reportError, connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::error,
this, &QdbStopApplicationService::stdErrData); this, [this] { emit stdErrData(d->applicationLauncher.errorString()); });
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished, connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished,
this, &QdbStopApplicationService::handleProcessFinished); this, &QdbStopApplicationService::handleProcessFinished);
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage, connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage,

View File

@@ -88,7 +88,8 @@ public:
bool isRunning() const; bool isRunning() const;
// Remote // Remote
void doReportError(const QString &message); void doReportError(const QString &message,
QProcess::ProcessError error = QProcess::FailedToStart);
void handleRemoteStderr(); void handleRemoteStderr();
void handleRemoteStdout(); void handleRemoteStdout();
void handleApplicationFinished(); void handleApplicationFinished();
@@ -116,6 +117,8 @@ public:
// Remote // Remote
DeviceProcess *m_deviceProcess = nullptr; DeviceProcess *m_deviceProcess = nullptr;
QString m_remoteErrorString;
QProcess::ProcessError m_remoteError = QProcess::UnknownError;
State m_state = Inactive; State m_state = Inactive;
bool m_stopRequested = false; bool m_stopRequested = false;
bool m_success = false; bool m_success = false;
@@ -258,18 +261,16 @@ qint64 ApplicationLauncherPrivate::applicationPID() const
QString ApplicationLauncher::errorString() const QString ApplicationLauncher::errorString() const
{ {
if (d->m_useTerminal) if (d->m_isLocal)
return d->m_consoleProcess.errorString(); return d->m_useTerminal ? d->m_consoleProcess.errorString() : d->m_guiProcess.errorString();
else return d->m_remoteErrorString;
return d->m_guiProcess.errorString();
} }
QProcess::ProcessError ApplicationLauncher::processError() const QProcess::ProcessError ApplicationLauncher::processError() const
{ {
if (d->m_useTerminal) if (d->m_isLocal)
return d->m_consoleProcess.error(); return d->m_useTerminal ? d->m_consoleProcess.error() : d->m_guiProcess.error();
else return d->m_remoteError;
return d->m_guiProcess.error();
} }
void ApplicationLauncherPrivate::localGuiProcessError() void ApplicationLauncherPrivate::localGuiProcessError()
@@ -469,11 +470,12 @@ void ApplicationLauncherPrivate::handleApplicationFinished()
QTC_ASSERT(m_state == Run, return); QTC_ASSERT(m_state == Run, return);
if (m_deviceProcess->exitStatus() == QProcess::CrashExit) { if (m_deviceProcess->exitStatus() == QProcess::CrashExit) {
doReportError(m_deviceProcess->errorString()); doReportError(m_deviceProcess->errorString(), QProcess::Crashed);
} else { } else {
const int exitCode = m_deviceProcess->exitCode(); const int exitCode = m_deviceProcess->exitCode();
if (exitCode != 0) { 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 { } else {
emit q->appendMessage(ApplicationLauncher::tr("Application finished with exit code 0."), emit q->appendMessage(ApplicationLauncher::tr("Application finished with exit code 0."),
Utils::NormalMessageFormat); Utils::NormalMessageFormat);
@@ -496,10 +498,12 @@ void ApplicationLauncherPrivate::handleRemoteStderr()
emit q->appendMessage(QString::fromUtf8(output), Utils::StdErrFormat, false); 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; m_success = false;
emit q->reportError(message); emit q->error(error);
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -74,7 +74,6 @@ signals:
void processExited(int exitCode, QProcess::ExitStatus); void processExited(int exitCode, QProcess::ExitStatus);
void error(QProcess::ProcessError error); void error(QProcess::ProcessError error);
void reportError(const QString &errorOutput);
void finished(bool success); void finished(bool success);
private: private:

View File

@@ -1252,9 +1252,8 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP
} else { } else {
connect(&m_launcher, &ApplicationLauncher::reportError, connect(&m_launcher, &ApplicationLauncher::error, this, [this] {
this, [this](const QString &msg) { reportFailure(m_launcher.errorString());
reportFailure(msg);
}); });
connect(&m_launcher, &ApplicationLauncher::finished, connect(&m_launcher, &ApplicationLauncher::finished,