Uniform ApplicationLauncher API: get rid of finished()

Use existing processExited() signal instead.

Change-Id: I1eecaa05fa8b3a97d8585fca4ca89e8e1acecec3
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2021-11-10 14:31:31 +01:00
parent 15edfc85cb
commit a3ae60d729
10 changed files with 25 additions and 71 deletions

View File

@@ -81,7 +81,7 @@ public:
&DeviceApplicationObserver::handleAppendMessage);
connect(&m_appRunner, &ApplicationLauncher::error, this,
[this] { m_error = m_appRunner.errorString(); });
connect(&m_appRunner, &ApplicationLauncher::finished, this,
connect(&m_appRunner, &ApplicationLauncher::processExited, this,
&DeviceApplicationObserver::handleFinished);
QTC_ASSERT(device, return);
@@ -103,14 +103,14 @@ private:
m_stderr += data;
}
void handleFinished(bool success)
void handleFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (success && (m_stdout.contains("fail") || m_stdout.contains("error")
|| m_stdout.contains("not found"))) {
Q_UNUSED(exitCode)
// FIXME: Needed in a post-adb world?
success = false; // adb does not forward exit codes and all stderr goes to stdout.
}
if (!success) {
// adb does not forward exit codes and all stderr goes to stdout.
const bool failure = exitStatus == QProcess::CrashExit || m_stdout.contains("fail")
|| m_stdout.contains("error") || m_stdout.contains("not found");
if (failure) {
QString errorString;
if (!m_error.isEmpty()) {
errorString = QdbDevice::tr("Command failed on device \"%1\": %2")

View File

@@ -57,7 +57,7 @@ public:
connect(&m_launcher, &ApplicationLauncher::processStarted,
this, &RunWorker::reportStarted);
connect(&m_launcher, &ApplicationLauncher::finished,
connect(&m_launcher, &ApplicationLauncher::processExited,
this, &RunWorker::reportStopped);
connect(&m_launcher, &ApplicationLauncher::appendMessage,
this, &RunWorker::appendMessage);

View File

@@ -57,10 +57,11 @@ QdbStopApplicationService::~QdbStopApplicationService()
delete d;
}
void QdbStopApplicationService::handleProcessFinished(bool success)
void QdbStopApplicationService::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitCode)
const auto failureMessage = tr("Could not check and possibly stop running application.");
if (!success) {
if (exitStatus == QProcess::CrashExit) {
emit errorMessage(failureMessage);
stopDeployment();
return;
@@ -90,7 +91,7 @@ void QdbStopApplicationService::doDeploy()
{
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::error,
this, [this] { emit stdErrData(d->applicationLauncher.errorString()); });
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished,
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::processExited,
this, &QdbStopApplicationService::handleProcessFinished);
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage,
this, &QdbStopApplicationService::handleAppendMessage);

View File

@@ -28,6 +28,8 @@
#include <remotelinux/abstractremotelinuxdeployservice.h>
#include <utils/outputformat.h>
#include <QProcess>
namespace Qdb {
namespace Internal {
@@ -41,7 +43,7 @@ public:
~QdbStopApplicationService();
private:
void handleProcessFinished(bool success);
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void handleAppendMessage(const QString &message, Utils::OutputFormat format);
bool isDeploymentNecessary() const final { return true; }

View File

@@ -119,9 +119,9 @@ public:
DeviceProcess *m_deviceProcess = nullptr;
QString m_remoteErrorString;
QProcess::ProcessError m_remoteError = QProcess::UnknownError;
QProcess::ExitStatus m_remoteExitStatus = QProcess::CrashExit;
State m_state = Inactive;
bool m_stopRequested = false;
bool m_success = false;
};
} // Internal
@@ -213,7 +213,7 @@ void ApplicationLauncherPrivate::stop()
if (m_stopRequested)
return;
m_stopRequested = true;
m_success = false;
m_remoteExitStatus = QProcess::CrashExit;
emit q->appendMessage(ApplicationLauncher::tr("User requested stop. Shutting down..."),
Utils::NormalMessageFormat);
switch (m_state) {
@@ -423,7 +423,7 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::
}
m_stopRequested = false;
m_success = true;
m_remoteExitStatus = QProcess::NormalExit;
m_deviceProcess = device->createProcess(this);
m_deviceProcess->setRunInTerminal(m_useTerminal);
@@ -455,14 +455,16 @@ void ApplicationLauncherPrivate::setFinished()
if (m_state == Inactive)
return;
int exitCode = 0;
if (m_deviceProcess) {
exitCode = m_deviceProcess->exitCode();
m_deviceProcess->disconnect(this);
m_deviceProcess->deleteLater();
m_deviceProcess = nullptr;
}
m_state = Inactive;
emit q->finished(m_success);
emit q->processExited(exitCode, m_remoteExitStatus);
}
void ApplicationLauncherPrivate::handleApplicationFinished()
@@ -502,7 +504,7 @@ void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess:
{
m_remoteErrorString = message;
m_remoteError = error;
m_success = false;
m_remoteExitStatus = QProcess::CrashExit;
emit q->error(error);
}

View File

@@ -71,11 +71,9 @@ public:
signals:
void appendMessage(const QString &message, Utils::OutputFormat format, bool appendNewLine = true);
void processStarted();
void processExited(int exitCode, QProcess::ExitStatus);
void processExited(int exitCode, QProcess::ExitStatus exitStatus);
void error(QProcess::ProcessError error);
void finished(bool success);
private:
std::unique_ptr<Internal::ApplicationLauncherPrivate> d;
};

View File

@@ -1256,12 +1256,6 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP
reportFailure(m_launcher.errorString());
});
connect(&m_launcher, &ApplicationLauncher::finished,
this, [this] {
m_launcher.disconnect(this);
reportStopped();
});
connect(&m_launcher, &ApplicationLauncher::processStarted, this, &RunWorker::reportStarted);
connect(&m_launcher, &ApplicationLauncher::processExited,

View File

@@ -121,8 +121,6 @@ void CallgrindController::run(Option option)
this, &CallgrindController::controllerProcessFinished);
connect(m_controllerProcess, &ApplicationLauncher::error,
this, &CallgrindController::handleControllerProcessError);
connect(m_controllerProcess, &ApplicationLauncher::finished,
this, &CallgrindController::controllerProcessClosed);
Runnable controller = m_valgrindRunnable;
controller.command.setExecutable(FilePath::fromString(CALLGRIND_CONTROL_BINARY));
@@ -185,24 +183,6 @@ void CallgrindController::controllerProcessFinished(int rc, QProcess::ExitStatus
m_lastOption = Unknown;
}
void CallgrindController::controllerProcessClosed(bool success)
{
Q_UNUSED(success)
// QTC_ASSERT(m_remote.m_process, return);
// m_remote.m_errorString = m_remote.m_process->errorString();
// if (status == QSsh::SshRemoteProcess::FailedToStart) {
// m_remote.m_error = QProcess::FailedToStart;
// emit ValgrindProcessX::error(QProcess::FailedToStart);
// } else if (status == QSsh::SshRemoteProcess::NormalExit) {
// emit finished(m_remote.m_process->exitCode(), QProcess::NormalExit);
// } else if (status == QSsh::SshRemoteProcess::CrashExit) {
// m_remote.m_error = QProcess::Crashed;
// emit finished(m_remote.m_process->exitCode(), QProcess::CrashExit);
// }
controllerProcessFinished(0, QProcess::NormalExit);
}
void CallgrindController::getLocalDataFile()
{
cleanupTempFile();

View File

@@ -78,7 +78,6 @@ private:
void controllerProcessFinished(int, QProcess::ExitStatus);
void controllerProcessError(QProcess::ProcessError);
void controllerProcessClosed(bool success);
ProjectExplorer::ApplicationLauncher *m_controllerProcess = nullptr;
ProjectExplorer::Runnable m_valgrindRunnable;

View File

@@ -48,7 +48,6 @@ public:
bool run();
void closed(bool success);
void processStarted();
void localProcessStarted();
void remoteProcessStarted();
@@ -116,15 +115,13 @@ bool ValgrindRunner::Private::run()
// -q as suggested by valgrind manual
connect(&m_valgrindProcess, &ApplicationLauncher::processExited,
this, &ValgrindRunner::Private::closed);
q, &ValgrindRunner::processFinished);
connect(&m_valgrindProcess, &ApplicationLauncher::processStarted,
this, &ValgrindRunner::Private::processStarted);
connect(&m_valgrindProcess, &ApplicationLauncher::error,
q, &ValgrindRunner::processError);
connect(&m_valgrindProcess, &ApplicationLauncher::appendMessage,
q, &ValgrindRunner::processOutputReceived);
connect(&m_valgrindProcess, &ApplicationLauncher::finished,
q, &ValgrindRunner::finished);
if (HostOsInfo::isMacHost())
// May be slower to start but without it we get no filenames for symbols.
@@ -218,25 +215,6 @@ void ValgrindRunner::Private::findPidOutputReceived(const QString &out, Utils::O
}
}
void ValgrindRunner::Private::closed(bool success)
{
Q_UNUSED(success)
// QTC_ASSERT(m_remote.m_process, return);
// m_remote.m_errorString = m_remote.m_process->errorString();
// if (status == QSsh::SshRemoteProcess::FailedToStart) {
// m_remote.m_error = QProcess::FailedToStart;
// q->processError(QProcess::FailedToStart);
// } else if (status == QSsh::SshRemoteProcess::NormalExit) {
// q->processFinished(m_remote.m_process->exitCode(), QProcess::NormalExit);
// } else if (status == QSsh::SshRemoteProcess::CrashExit) {
// m_remote.m_error = QProcess::Crashed;
// q->processFinished(m_remote.m_process->exitCode(), QProcess::CrashExit);
// }
q->processFinished(0, QProcess::NormalExit);
}
ValgrindRunner::ValgrindRunner(QObject *parent)
: QObject(parent), d(new Private(this))
{