diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2013-10-17 14:13:51 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2013-10-18 14:25:53 +0200 |
commit | 33dbdcd43042e8c7a51ae7b2e2eb4004ca516b8c (patch) | |
tree | 83de2d0e944014d23b6ba361f26f7eb18f9a658f /src/plugins | |
parent | e58906a9ed718b0e65a0f805c165e7bacf54d936 (diff) | |
download | qt-creator-33dbdcd43042e8c7a51ae7b2e2eb4004ca516b8c.tar.gz |
Device support: Polish DeviceApplicationRunner.
Remove timeout check (part of DeviceProcess now), react to the
DeviceProcess' error() signal, remove unneeded members, improve
messages.
What's left is a light-weight wrapper around DeviceProcess suitable for
run controls. Removal would result in identical boiler-plate code in
several places.
Change-Id: Ib306369df8dbf72dddb8ca305d256870a121dd63
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp | 78 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.h | 4 |
2 files changed, 35 insertions, 47 deletions
diff --git a/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp b/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp index fa46dc1680..4a413ac08a 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp +++ b/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp @@ -50,10 +50,6 @@ class DeviceApplicationRunner::DeviceApplicationRunnerPrivate { public: DeviceProcess *deviceProcess; - IDevice::ConstPtr device; - QTimer stopTimer; - QString command; - QStringList arguments; Utils::Environment environment; QString workingDir; State state; @@ -67,9 +63,6 @@ DeviceApplicationRunner::DeviceApplicationRunner(QObject *parent) : { d->deviceProcess = 0; d->state = Inactive; - - d->stopTimer.setSingleShot(true); - connect(&d->stopTimer, SIGNAL(timeout()), SLOT(handleStopTimeout())); } DeviceApplicationRunner::~DeviceApplicationRunner() @@ -91,22 +84,34 @@ void DeviceApplicationRunner::setWorkingDirectory(const QString &workingDirector void DeviceApplicationRunner::start(const IDevice::ConstPtr &device, const QString &command, const QStringList &arguments) { - QTC_ASSERT(device->canCreateProcess(), return); QTC_ASSERT(d->state == Inactive, return); - d->device = device; - d->command = command; - d->arguments = arguments; - d->stopRequested = false; - d->success = true; - - if (!d->device) { + if (!device) { emit reportError(tr("Cannot run: No device.")); setFinished(); return; } - runApplication(); + if (!device->canCreateProcess()) { + emit reportError(tr("Cannot run: Device is not able to create processes.")); + setFinished(); + return; + } + + d->stopRequested = false; + d->success = true; + + d->state = Run; + d->deviceProcess = device->createProcess(this); + connect(d->deviceProcess, SIGNAL(started()), SIGNAL(remoteProcessStarted())); + connect(d->deviceProcess, SIGNAL(readyReadStandardOutput()), SLOT(handleRemoteStdout())); + connect(d->deviceProcess, SIGNAL(readyReadStandardError()), SLOT(handleRemoteStderr())); + connect(d->deviceProcess, SIGNAL(error(QProcess::ProcessError)), + SLOT(handleApplicationError(QProcess::ProcessError))); + connect(d->deviceProcess, SIGNAL(finished()), SLOT(handleApplicationFinished())); + d->deviceProcess->setEnvironment(d->environment); + d->deviceProcess->setWorkingDirectory(d->workingDir); + d->deviceProcess->start(command, arguments); } void DeviceApplicationRunner::stop() @@ -118,7 +123,6 @@ void DeviceApplicationRunner::stop() emit reportProgress(tr("User requested stop. Shutting down...")); switch (d->state) { case Run: - d->stopTimer.start(10000); d->deviceProcess->terminate(); break; case Inactive: @@ -126,6 +130,15 @@ void DeviceApplicationRunner::stop() } } +void DeviceApplicationRunner::handleApplicationError(QProcess::ProcessError error) +{ + if (error == QProcess::FailedToStart) { + emit reportError(tr("Application failed to start: %1") + .arg(d->deviceProcess->errorString())); + setFinished(); + } +} + void DeviceApplicationRunner::setFinished() { if (d->state == Inactive) @@ -141,30 +154,20 @@ void DeviceApplicationRunner::setFinished() emit finished(d->success); } -void DeviceApplicationRunner::handleStopTimeout() -{ - QTC_ASSERT(d->stopRequested && d->state == Run, return); - - emit reportError(tr("Application did not finish in time, aborting.")); - d->success = false; - setFinished(); -} - void DeviceApplicationRunner::handleApplicationFinished() { QTC_ASSERT(d->state == Run, return); - d->stopTimer.stop(); if (d->deviceProcess->exitStatus() == QProcess::CrashExit) { - emit reportError(tr("Remote application crashed: %1").arg(d->deviceProcess->errorString())); + emit reportError(d->deviceProcess->errorString()); d->success = false; } else { const int exitCode = d->deviceProcess->exitCode(); if (exitCode != 0) { - emit reportError(tr("Remote application finished with exit code %1.").arg(exitCode)); + emit reportError(tr("Application finished with exit code %1.").arg(exitCode)); d->success = false; } else { - emit reportProgress(tr("Remote application finished with exit code 0.")); + emit reportProgress(tr("Application finished with exit code 0.")); } } setFinished(); @@ -182,19 +185,4 @@ void DeviceApplicationRunner::handleRemoteStderr() emit remoteStderr(d->deviceProcess->readAllStandardError()); } -void DeviceApplicationRunner::runApplication() -{ - QTC_ASSERT(d->state == Inactive, return); - - d->state = Run; - d->deviceProcess = d->device->createProcess(this); - connect(d->deviceProcess, SIGNAL(started()), SIGNAL(remoteProcessStarted())); - connect(d->deviceProcess, SIGNAL(readyReadStandardOutput()), SLOT(handleRemoteStdout())); - connect(d->deviceProcess, SIGNAL(readyReadStandardError()), SLOT(handleRemoteStderr())); - connect(d->deviceProcess, SIGNAL(finished()), SLOT(handleApplicationFinished())); - d->deviceProcess->setEnvironment(d->environment); - d->deviceProcess->setWorkingDirectory(d->workingDir); - d->deviceProcess->start(d->command, d->arguments); -} - } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.h b/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.h index fbb9fc3213..7481ac0271 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.h +++ b/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.h @@ -34,6 +34,7 @@ #include "../projectexplorer_export.h" #include <QObject> +#include <QProcess> QT_BEGIN_NAMESPACE class QStringList; @@ -66,13 +67,12 @@ signals: void finished(bool success); private slots: - void handleStopTimeout(); + void handleApplicationError(QProcess::ProcessError error); void handleApplicationFinished(); void handleRemoteStdout(); void handleRemoteStderr(); private: - void runApplication(); void setFinished(); class DeviceApplicationRunnerPrivate; |