2011-06-16 17:03:43 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** Nokia at info@qt.nokia.com.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/ssh/sshconnection.h>
|
|
|
|
|
#include <utils/ssh/sshconnectionmanager.h>
|
|
|
|
|
#include <utils/ssh/sshremoteprocess.h>
|
|
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
|
|
using namespace Qt4ProjectManager;
|
|
|
|
|
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)
|
|
|
|
|
: devConfig(runConfig->deviceConfig()),
|
|
|
|
|
remoteExecutable(runConfig->remoteExecutableFilePath()),
|
|
|
|
|
appArguments(runConfig->arguments()),
|
|
|
|
|
commandPrefix(runConfig->commandPrefix()),
|
|
|
|
|
initialFreePorts(runConfig->freePorts()),
|
|
|
|
|
stopRequested(false),
|
|
|
|
|
state(Inactive)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 16:04:55 +02:00
|
|
|
RemoteLinuxUsedPortsGatherer portsGatherer;
|
2011-07-19 14:30:06 +02:00
|
|
|
const LinuxDeviceConfiguration::ConstPtr devConfig;
|
|
|
|
|
const QString remoteExecutable;
|
|
|
|
|
const QString appArguments;
|
|
|
|
|
const QString commandPrefix;
|
|
|
|
|
const PortList initialFreePorts;
|
|
|
|
|
|
|
|
|
|
Utils::SshConnection::Ptr connection;
|
|
|
|
|
Utils::SshRemoteProcess::Ptr runner;
|
|
|
|
|
Utils::SshRemoteProcess::Ptr cleaner;
|
|
|
|
|
|
|
|
|
|
PortList freePorts;
|
|
|
|
|
int exitStatus;
|
|
|
|
|
bool stopRequested;
|
|
|
|
|
State state;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
AbstractRemoteLinuxApplicationRunner::AbstractRemoteLinuxApplicationRunner(QObject *parent,
|
2011-06-16 17:03:43 +02:00
|
|
|
RemoteLinuxRunConfiguration *runConfig)
|
2011-07-19 14:30:06 +02:00
|
|
|
: QObject(parent), m_d(new AbstractRemoteLinuxApplicationRunnerPrivate(runConfig))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-07-19 14:30:06 +02:00
|
|
|
connect(&m_d->portsGatherer, SIGNAL(error(QString)), SLOT(handlePortsGathererError(QString)));
|
|
|
|
|
connect(&m_d->portsGatherer, SIGNAL(portListReady()), SLOT(handleUsedPortsAvailable()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractRemoteLinuxApplicationRunner::~AbstractRemoteLinuxApplicationRunner()
|
|
|
|
|
{
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
2011-07-11 12:51:36 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
SshConnection::Ptr AbstractRemoteLinuxApplicationRunner::connection() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->connection;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
LinuxDeviceConfiguration::ConstPtr AbstractRemoteLinuxApplicationRunner::devConfig() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->devConfig;
|
|
|
|
|
}
|
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-07-19 14:30:06 +02:00
|
|
|
return &m_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-07-19 14:30:06 +02:00
|
|
|
return &m_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-07-19 14:30:06 +02:00
|
|
|
return m_d->remoteExecutable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractRemoteLinuxApplicationRunner::arguments() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->appArguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AbstractRemoteLinuxApplicationRunner::commandPrefix() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->commandPrefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxApplicationRunner::start()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_d->stopRequested && m_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-07-19 14:30:06 +02:00
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
if (m_d->stopRequested)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
switch (m_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-07-19 14:30:06 +02:00
|
|
|
m_d->portsGatherer.stop();
|
|
|
|
|
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-07-19 14:30:06 +02:00
|
|
|
m_d->stopRequested = true; // TODO: We might need stopPreRunCleaning() etc. for the subclasses
|
2011-06-16 17:03:43 +02:00
|
|
|
break;
|
|
|
|
|
case ReadyForExecution:
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->stopRequested = true;
|
|
|
|
|
m_d->state = PostRunCleaning;
|
|
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
break;
|
|
|
|
|
case ProcessStarted:
|
2011-07-19 14:30:06 +02:00
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == Connecting, return);
|
|
|
|
|
|
|
|
|
|
if (m_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-07-19 14:30:06 +02:00
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state != Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->state != Connecting || m_d->state != PreRunCleaning)
|
2011-06-16 17:03:43 +02:00
|
|
|
doAdditionalConnectionErrorHandling();
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
const QString errorMsg = m_d->state == Connecting
|
|
|
|
|
? tr("Could not connect to host: %1") : tr("Connection error: %1");
|
|
|
|
|
emitError(errorMsg.arg(m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == PreRunCleaning
|
|
|
|
|
|| (m_d->state == ProcessStarted && m_d->stopRequested), return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
emit reportProgress(tr("Killing remote process(es)..."));
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->cleaner = m_d->connection->createRemoteProcess(killApplicationCommandLine().toUtf8());
|
|
|
|
|
connect(m_d->cleaner.data(), SIGNAL(closed(int)), SLOT(handleCleanupFinished(int)));
|
|
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == PreRunCleaning
|
|
|
|
|
|| (m_d->state == ProcessStarted && m_d->stopRequested) || m_d->state == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->state == Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->stopRequested && m_d->state == PreRunCleaning) {
|
|
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->stopRequested) {
|
|
|
|
|
m_d->state = PostRunCleaning;
|
|
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exitStatus != SshRemoteProcess::ExitedNormally) {
|
2011-07-19 14:30:06 +02:00
|
|
|
emitError(tr("Initial cleanup failed: %1").arg(m_d->cleaner->errorString()));
|
2011-07-11 12:51:36 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == ReadyForExecution, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->stopRequested)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->runner = m_d->connection->createRemoteProcess(remoteCall);
|
|
|
|
|
connect(m_d->runner.data(), SIGNAL(started()), SLOT(handleRemoteProcessStarted()));
|
|
|
|
|
connect(m_d->runner.data(), SIGNAL(closed(int)), SLOT(handleRemoteProcessFinished(int)));
|
|
|
|
|
connect(m_d->runner.data(), SIGNAL(outputAvailable(QByteArray)),
|
2011-06-16 17:03:43 +02:00
|
|
|
SIGNAL(remoteOutput(QByteArray)));
|
2011-07-19 14:30:06 +02:00
|
|
|
connect(m_d->runner.data(), SIGNAL(errorOutputAvailable(QByteArray)),
|
2011-06-16 17:03:43 +02:00
|
|
|
SIGNAL(remoteErrorOutput(QByteArray)));
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->state = ProcessStarting;
|
|
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == ProcessStarting, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->state = ProcessStarted;
|
|
|
|
|
if (m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == ProcessStarted || m_d->state == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->exitStatus = exitStatus;
|
|
|
|
|
if (!m_d->stopRequested && m_d->state != Inactive) {
|
|
|
|
|
m_d->state = PostRunCleaning;
|
|
|
|
|
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-07-19 14:30:06 +02:00
|
|
|
m_d->portsGatherer.stop();
|
|
|
|
|
if (m_d->connection) {
|
|
|
|
|
disconnect(m_d->connection.data(), 0, this, 0);
|
|
|
|
|
SshConnectionManager::instance().releaseConnection(m_d->connection);
|
|
|
|
|
m_d->connection = SshConnection::Ptr();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->cleaner)
|
|
|
|
|
disconnect(m_d->cleaner.data(), 0, this, 0);
|
|
|
|
|
m_d->stopRequested = false;
|
|
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
if (m_d->state != Inactive) {
|
|
|
|
|
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-07-19 14:30:06 +02:00
|
|
|
if (m_d->state != Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
emitError(errorMsg);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleUsedPortsAvailable()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == GatheringPorts, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->stopRequested) {
|
|
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->state = AdditionalInitializing;
|
2011-06-16 17:03:43 +02:00
|
|
|
doAdditionalInitializations();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
bool AbstractRemoteLinuxApplicationRunner::canRun(QString &whyNot) const
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->remoteExecutable.isEmpty()) {
|
2011-06-16 17:03:43 +02:00
|
|
|
whyNot = tr("No remote executable set.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (!m_d->devConfig) {
|
2011-06-16 17:03:43 +02:00
|
|
|
whyNot = tr("No device configuration set.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
void AbstractRemoteLinuxApplicationRunner::handleDeviceSetupDone(bool success)
|
2011-06-29 11:38:21 +02:00
|
|
|
{
|
2011-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == SettingUpDevice, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (!success || m_d->stopRequested) {
|
|
|
|
|
setInactive();
|
2011-06-29 11:38:21 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->connection = SshConnectionManager::instance().acquireConnection(m_d->devConfig->sshParameters());
|
|
|
|
|
m_d->state = Connecting;
|
|
|
|
|
m_d->exitStatus = -1;
|
|
|
|
|
m_d->freePorts = m_d->initialFreePorts;
|
|
|
|
|
connect(m_d->connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
|
|
|
|
|
connect(m_d->connection.data(), SIGNAL(error(Utils::SshError)),
|
2011-06-29 11:38:21 +02:00
|
|
|
SLOT(handleConnectionFailure()));
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->connection->state() == SshConnection::Connected) {
|
2011-06-29 11:38:21 +02:00
|
|
|
handleConnected();
|
|
|
|
|
} else {
|
|
|
|
|
emit reportProgress(tr("Connecting to device..."));
|
2011-07-19 14:30:06 +02:00
|
|
|
if (m_d->connection->state() == Utils::SshConnection::Unconnected)
|
|
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == AdditionalPreRunCleaning, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
if (!success || m_d->stopRequested) {
|
|
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_d->state = GatheringPorts;
|
|
|
|
|
m_d->portsGatherer.start(m_d->connection, m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_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-07-19 14:30:06 +02:00
|
|
|
if (m_d->stopRequested) {
|
|
|
|
|
m_d->state = PostRunCleaning;
|
|
|
|
|
doPostRunCleanup();
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
m_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-07-19 14:30:06 +02:00
|
|
|
QTC_ASSERT(m_d->state == PostRunCleaning, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
const bool wasStopRequested = m_d->stopRequested;
|
|
|
|
|
setInactive();
|
2011-06-16 17:03:43 +02:00
|
|
|
if (wasStopRequested)
|
|
|
|
|
emit remoteProcessFinished(InvalidExitCode);
|
2011-07-19 14:30:06 +02:00
|
|
|
else if (m_d->exitStatus == SshRemoteProcess::ExitedNormally)
|
|
|
|
|
emit remoteProcessFinished(m_d->runner->exitCode());
|
2011-06-16 17:03:43 +02:00
|
|
|
else
|
2011-07-19 14:30:06 +02:00
|
|
|
emit error(tr("Error running remote process: %1").arg(m_d->runner->errorString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const qint64 AbstractRemoteLinuxApplicationRunner::InvalidExitCode = std::numeric_limits<qint64>::min();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GenericRemoteLinuxApplicationRunner::GenericRemoteLinuxApplicationRunner(QObject *parent,
|
|
|
|
|
RemoteLinuxRunConfiguration *runConfig)
|
|
|
|
|
: AbstractRemoteLinuxApplicationRunner(parent, runConfig)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2011-07-19 14:30:06 +02:00
|
|
|
QString GenericRemoteLinuxApplicationRunner::killApplicationCommandLine() const
|
|
|
|
|
{
|
|
|
|
|
// Prevent pkill from matching our own pkill call.
|
|
|
|
|
QString pkillArg = remoteExecutable();
|
|
|
|
|
const int lastPos = pkillArg.count() - 1;
|
|
|
|
|
pkillArg.replace(lastPos, 1, QLatin1Char('[') + pkillArg.at(lastPos) + QLatin1Char(']'));
|
|
|
|
|
|
|
|
|
|
const char * const killTemplate = "pkill -%2 -f %1";
|
|
|
|
|
const QString niceKill = QString::fromLocal8Bit(killTemplate).arg(pkillArg).arg("SIGTERM");
|
|
|
|
|
const QString brutalKill = QString::fromLocal8Bit(killTemplate).arg(pkillArg).arg("SIGKILL");
|
|
|
|
|
return niceKill + QLatin1String("; sleep 1; ") + brutalKill;
|
|
|
|
|
}
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|
|
|
|
|
|