2011-06-16 17:03:43 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "remotelinuxapplicationrunner.h"
|
|
|
|
|
|
2011-06-22 10:00:50 +02:00
|
|
|
#include "linuxdeviceconfiguration.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
#include "remotelinuxrunconfiguration.h"
|
2011-07-22 16:04:55 +02:00
|
|
|
#include "remotelinuxusedportsgatherer.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2012-02-28 10:34:50 +01:00
|
|
|
#include <utils/portlist.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshconnection.h>
|
|
|
|
|
#include <ssh/sshconnectionmanager.h>
|
|
|
|
|
#include <ssh/sshremoteprocess.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
|
|
using namespace Qt4ProjectManager;
|
2012-05-18 10:49:35 +02:00
|
|
|
using namespace QSsh;
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
2011-07-19 14:30:06 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
|
Inactive, SettingUpDevice, Connecting, PreRunCleaning, AdditionalPreRunCleaning,
|
|
|
|
|
GatheringPorts, AdditionalInitializing, ReadyForExecution, ProcessStarting, ProcessStarted,
|
|
|
|
|
PostRunCleaning
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
class AbstractRemoteLinuxApplicationRunnerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AbstractRemoteLinuxApplicationRunnerPrivate(const RemoteLinuxRunConfiguration *runConfig)
|
2011-12-21 20:14:42 +01:00
|
|
|
: devConfig(runConfig->deviceConfig()),
|
2011-07-19 14:30:06 +02:00
|
|
|
remoteExecutable(runConfig->remoteExecutableFilePath()),
|
|
|
|
|
appArguments(runConfig->arguments()),
|
|
|
|
|
commandPrefix(runConfig->commandPrefix()),
|
|
|
|
|
initialFreePorts(runConfig->freePorts()),
|
2012-05-29 13:22:33 +02:00
|
|
|
connection(0),
|
2011-07-19 14:30:06 +02:00
|
|
|
stopRequested(false),
|
|
|
|
|
state(Inactive)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 16:04:55 +02:00
|
|
|
RemoteLinuxUsedPortsGatherer portsGatherer;
|
2011-08-17 16:02:00 +02:00
|
|
|
LinuxDeviceConfiguration::ConstPtr devConfig;
|
2011-07-19 14:30:06 +02:00
|
|
|
const QString remoteExecutable;
|
|
|
|
|
const QString appArguments;
|
|
|
|
|
const QString commandPrefix;
|
|
|
|
|
const PortList initialFreePorts;
|
|
|
|
|
|
2012-05-29 13:22:33 +02:00
|
|
|
QSsh::SshConnection *connection;
|
2012-05-18 10:49:35 +02:00
|
|
|
QSsh::SshRemoteProcess::Ptr runner;
|
|
|
|
|
QSsh::SshRemoteProcess::Ptr cleaner;
|
2011-07-19 14:30:06 +02:00
|
|
|
|
|
|
|
|
PortList freePorts;
|
|
|
|
|
int exitStatus;
|
|
|
|
|
bool stopRequested;
|
|
|
|
|
State state;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
AbstractRemoteLinuxApplicationRunner::AbstractRemoteLinuxApplicationRunner(RemoteLinuxRunConfiguration *runConfig,
|
|
|
|
|
QObject *parent)
|
2011-09-15 09:10:10 +02:00
|
|
|
: QObject(parent), d(new AbstractRemoteLinuxApplicationRunnerPrivate(runConfig))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
connect(&d->portsGatherer, SIGNAL(error(QString)), SLOT(handlePortsGathererError(QString)));
|
|
|
|
|
connect(&d->portsGatherer, SIGNAL(portListReady()), SLOT(handleUsedPortsAvailable()));
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractRemoteLinuxApplicationRunner::~AbstractRemoteLinuxApplicationRunner()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
delete d;
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
2011-07-11 12:51:36 +02:00
|
|
|
|
2012-05-29 13:22:33 +02:00
|
|
|
SshConnection *AbstractRemoteLinuxApplicationRunner::connection() const
|
2011-07-19 14:30:06 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return d->connection;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
LinuxDeviceConfiguration::ConstPtr AbstractRemoteLinuxApplicationRunner::devConfig() const
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return d->devConfig;
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-22 16:04:55 +02:00
|
|
|
const RemoteLinuxUsedPortsGatherer *AbstractRemoteLinuxApplicationRunner::usedPortsGatherer() const
|
2011-06-22 10:00:50 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return &d->portsGatherer;
|
2011-06-22 10:00:50 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
PortList *AbstractRemoteLinuxApplicationRunner::freePorts()
|
2011-06-22 10:00:50 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return &d->freePorts;
|
2011-06-22 10:00:50 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
QString AbstractRemoteLinuxApplicationRunner::remoteExecutable() const
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return d->remoteExecutable;
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractRemoteLinuxApplicationRunner::arguments() const
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return d->appArguments;
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractRemoteLinuxApplicationRunner::commandPrefix() const
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return d->commandPrefix;
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxApplicationRunner::start()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(!d->stopRequested && d->state == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
QString errorMsg;
|
|
|
|
|
if (!canRun(errorMsg)) {
|
|
|
|
|
emitError(tr("Cannot run: %1").arg(errorMsg), true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = SettingUpDevice;
|
2011-06-29 11:38:21 +02:00
|
|
|
doDeviceSetup();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::stop()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
switch (d->state) {
|
2011-06-16 17:03:43 +02:00
|
|
|
case Connecting:
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
break;
|
|
|
|
|
case GatheringPorts:
|
2011-12-21 20:14:42 +01:00
|
|
|
d->portsGatherer.stop();
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
break;
|
2011-06-29 11:38:21 +02:00
|
|
|
case SettingUpDevice:
|
2011-06-16 17:03:43 +02:00
|
|
|
case PreRunCleaning:
|
|
|
|
|
case AdditionalPreRunCleaning:
|
|
|
|
|
case AdditionalInitializing:
|
|
|
|
|
case ProcessStarting:
|
|
|
|
|
case PostRunCleaning:
|
2011-09-15 09:10:10 +02:00
|
|
|
d->stopRequested = true; // TODO: We might need stopPreRunCleaning() etc. for the subclasses
|
2011-06-16 17:03:43 +02:00
|
|
|
break;
|
|
|
|
|
case ReadyForExecution:
|
2011-09-15 09:10:10 +02:00
|
|
|
d->stopRequested = true;
|
|
|
|
|
d->state = PostRunCleaning;
|
2011-07-19 14:30:06 +02:00
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
break;
|
|
|
|
|
case ProcessStarted:
|
2011-09-15 09:10:10 +02:00
|
|
|
d->stopRequested = true;
|
2011-06-16 17:03:43 +02:00
|
|
|
cleanup();
|
|
|
|
|
break;
|
|
|
|
|
case Inactive:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleConnected()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == Connecting, return);
|
2011-07-19 14:30:06 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested) {
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
} else {
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = PreRunCleaning;
|
2011-06-16 17:03:43 +02:00
|
|
|
cleanup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleConnectionFailure()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state != Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state != Connecting || d->state != PreRunCleaning)
|
2011-06-16 17:03:43 +02:00
|
|
|
doAdditionalConnectionErrorHandling();
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
const QString errorMsg = d->state == Connecting
|
2011-07-19 14:30:06 +02:00
|
|
|
? tr("Could not connect to host: %1") : tr("Connection error: %1");
|
2011-09-15 09:10:10 +02:00
|
|
|
emitError(errorMsg.arg(d->connection->errorString()));
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::cleanup()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == PreRunCleaning
|
|
|
|
|
|| (d->state == ProcessStarted && d->stopRequested), return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
emit reportProgress(tr("Killing remote process(es)..."));
|
2011-09-15 09:10:10 +02:00
|
|
|
d->cleaner = d->connection->createRemoteProcess(killApplicationCommandLine().toUtf8());
|
|
|
|
|
connect(d->cleaner.data(), SIGNAL(closed(int)), SLOT(handleCleanupFinished(int)));
|
|
|
|
|
d->cleaner->start();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleCleanupFinished(int exitStatus)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|
|
|
|
|
|| exitStatus == SshRemoteProcess::KilledBySignal
|
|
|
|
|
|| exitStatus == SshRemoteProcess::ExitedNormally);
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == PreRunCleaning
|
|
|
|
|
|| (d->state == ProcessStarted && d->stopRequested) || d->state == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state == Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested && d->state == PreRunCleaning) {
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested) {
|
|
|
|
|
d->state = PostRunCleaning;
|
2011-07-19 14:30:06 +02:00
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exitStatus != SshRemoteProcess::ExitedNormally) {
|
2011-09-15 09:10:10 +02:00
|
|
|
emitError(tr("Initial cleanup failed: %1").arg(d->cleaner->errorString()));
|
2011-07-11 12:51:36 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = AdditionalPreRunCleaning;
|
2011-06-16 17:03:43 +02:00
|
|
|
doAdditionalInitialCleanup();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::startExecution(const QByteArray &remoteCall)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == ReadyForExecution, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->runner = d->connection->createRemoteProcess(remoteCall);
|
|
|
|
|
connect(d->runner.data(), SIGNAL(started()), SLOT(handleRemoteProcessStarted()));
|
|
|
|
|
connect(d->runner.data(), SIGNAL(closed(int)), SLOT(handleRemoteProcessFinished(int)));
|
2011-11-14 17:23:51 +01:00
|
|
|
connect(d->runner.data(), SIGNAL(readyReadStandardOutput()), SLOT(handleRemoteStdout()));
|
|
|
|
|
connect(d->runner.data(), SIGNAL(readyReadStandardError()), SLOT(handleRemoteStderr()));
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = ProcessStarting;
|
|
|
|
|
d->runner->start();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleRemoteProcessStarted()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == ProcessStarting, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = ProcessStarted;
|
|
|
|
|
if (d->stopRequested) {
|
2011-06-16 17:03:43 +02:00
|
|
|
cleanup();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit reportProgress(tr("Remote process started."));
|
|
|
|
|
emit remoteProcessStarted();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleRemoteProcessFinished(int exitStatus)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|
|
|
|
|
|| exitStatus == SshRemoteProcess::KilledBySignal
|
|
|
|
|
|| exitStatus == SshRemoteProcess::ExitedNormally);
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == ProcessStarted || d->state == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->exitStatus = exitStatus;
|
|
|
|
|
if (!d->stopRequested && d->state != Inactive) {
|
|
|
|
|
d->state = PostRunCleaning;
|
2011-07-19 14:30:06 +02:00
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::setInactive()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
d->portsGatherer.stop();
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->connection) {
|
2012-05-29 13:22:33 +02:00
|
|
|
disconnect(d->connection, 0, this, 0);
|
2011-09-15 09:10:10 +02:00
|
|
|
SshConnectionManager::instance().releaseConnection(d->connection);
|
2012-05-29 13:22:33 +02:00
|
|
|
d->connection = 0;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->cleaner)
|
|
|
|
|
disconnect(d->cleaner.data(), 0, this, 0);
|
|
|
|
|
d->stopRequested = false;
|
|
|
|
|
d->state = Inactive;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::emitError(const QString &errorMsg, bool force)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state != Inactive) {
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit error(errorMsg);
|
|
|
|
|
} else if (force) {
|
|
|
|
|
emit error(errorMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handlePortsGathererError(const QString &errorMsg)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state != Inactive) {
|
2011-09-07 15:43:11 +02:00
|
|
|
if (connection()->errorState() != SshNoError) {
|
|
|
|
|
emitError(errorMsg);
|
|
|
|
|
} else {
|
|
|
|
|
emit reportProgress(tr("Gathering ports failed: %1\nContinuing anyway.").arg(errorMsg));
|
|
|
|
|
handleUsedPortsAvailable();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleUsedPortsAvailable()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == GatheringPorts, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested) {
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = AdditionalInitializing;
|
2011-06-16 17:03:43 +02:00
|
|
|
doAdditionalInitializations();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 17:23:51 +01:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleRemoteStdout()
|
|
|
|
|
{
|
|
|
|
|
emit remoteOutput(d->runner->readAllStandardOutput());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleRemoteStderr()
|
|
|
|
|
{
|
|
|
|
|
emit remoteErrorOutput(d->runner->readAllStandardError());
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
bool AbstractRemoteLinuxApplicationRunner::canRun(QString &whyNot) const
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->remoteExecutable.isEmpty()) {
|
2011-06-16 17:03:43 +02:00
|
|
|
whyNot = tr("No remote executable set.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (!d->devConfig) {
|
2011-06-16 17:03:43 +02:00
|
|
|
whyNot = tr("No device configuration set.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 16:02:00 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::setDeviceConfiguration(const LinuxDeviceConfiguration::ConstPtr &deviceConfig)
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
d->devConfig = deviceConfig;
|
2011-08-17 16:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleDeviceSetupDone(bool success)
|
2011-06-29 11:38:21 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == SettingUpDevice, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (!success || d->stopRequested) {
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-29 11:38:21 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->connection = SshConnectionManager::instance().acquireConnection(d->devConfig->sshParameters());
|
|
|
|
|
d->state = Connecting;
|
|
|
|
|
d->exitStatus = -1;
|
|
|
|
|
d->freePorts = d->initialFreePorts;
|
2012-05-29 13:22:33 +02:00
|
|
|
connect(d->connection, SIGNAL(connected()), SLOT(handleConnected()));
|
|
|
|
|
connect(d->connection, SIGNAL(error(QSsh::SshError)),
|
2011-06-29 11:38:21 +02:00
|
|
|
SLOT(handleConnectionFailure()));
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->connection->state() == SshConnection::Connected) {
|
2011-06-29 11:38:21 +02:00
|
|
|
handleConnected();
|
|
|
|
|
} else {
|
|
|
|
|
emit reportProgress(tr("Connecting to device..."));
|
2012-05-18 10:49:35 +02:00
|
|
|
if (d->connection->state() == QSsh::SshConnection::Unconnected)
|
2011-09-15 09:10:10 +02:00
|
|
|
d->connection->connectToHost();
|
2011-06-29 11:38:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleInitialCleanupDone(bool success)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == AdditionalPreRunCleaning, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (!success || d->stopRequested) {
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = GatheringPorts;
|
2012-04-03 10:23:59 +02:00
|
|
|
d->portsGatherer.start(d->devConfig);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleInitializationsDone(bool success)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == AdditionalInitializing, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
if (!success) {
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->stopRequested) {
|
|
|
|
|
d->state = PostRunCleaning;
|
2011-07-19 14:30:06 +02:00
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = ReadyForExecution;
|
2011-06-16 17:03:43 +02:00
|
|
|
emit readyForExecution();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handlePostRunCleanupDone()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == PostRunCleaning, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
const bool wasStopRequested = d->stopRequested;
|
2011-07-19 14:30:06 +02:00
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
if (wasStopRequested)
|
|
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
2011-09-15 09:10:10 +02:00
|
|
|
else if (d->exitStatus == SshRemoteProcess::ExitedNormally)
|
|
|
|
|
emit remoteProcessFinished(d->runner->exitCode());
|
2011-06-16 17:03:43 +02:00
|
|
|
else
|
2011-09-15 09:10:10 +02:00
|
|
|
emit error(tr("Error running remote process: %1").arg(d->runner->errorString()));
|
2011-07-19 14:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-08 17:23:00 +01:00
|
|
|
QString AbstractRemoteLinuxApplicationRunner::killApplicationCommandLine() const
|
|
|
|
|
{
|
2012-01-30 16:39:10 +02:00
|
|
|
return QString::fromLatin1("cd /proc; for pid in `ls -d [0123456789]*`; "
|
2011-11-08 17:23:00 +01:00
|
|
|
"do "
|
|
|
|
|
"if [ \"`readlink /proc/$pid/exe`\" = \"%1\" ]; then "
|
|
|
|
|
" kill $pid; sleep 1; kill -9 $pid; "
|
|
|
|
|
"fi; "
|
|
|
|
|
"done").arg(remoteExecutable());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
const qint64 AbstractRemoteLinuxApplicationRunner::InvalidExitCode = std::numeric_limits<qint64>::min();
|
|
|
|
|
|
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
GenericRemoteLinuxApplicationRunner::GenericRemoteLinuxApplicationRunner(RemoteLinuxRunConfiguration *runConfig,
|
|
|
|
|
QObject *parent)
|
|
|
|
|
: AbstractRemoteLinuxApplicationRunner(runConfig, parent)
|
2011-07-19 14:30:06 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericRemoteLinuxApplicationRunner::~GenericRemoteLinuxApplicationRunner()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GenericRemoteLinuxApplicationRunner::doDeviceSetup()
|
|
|
|
|
{
|
|
|
|
|
handleDeviceSetupDone(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericRemoteLinuxApplicationRunner::doAdditionalInitialCleanup()
|
|
|
|
|
{
|
|
|
|
|
handleInitialCleanupDone(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericRemoteLinuxApplicationRunner::doAdditionalInitializations()
|
|
|
|
|
{
|
|
|
|
|
handleInitializationsDone(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericRemoteLinuxApplicationRunner::doPostRunCleanup()
|
|
|
|
|
{
|
|
|
|
|
handlePostRunCleanupDone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericRemoteLinuxApplicationRunner::doAdditionalConnectionErrorHandling()
|
|
|
|
|
{
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|
|
|
|
|
|