forked from qt-creator/qt-creator
Coding style: Pure virtual functions, private implementation pointers.
Change-Id: I293f8dbd4e467e866bab381841659a07e32b9d90 Reviewed-on: http://codereview.qt-project.org/4948 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -96,55 +96,55 @@ using namespace Internal;
|
||||
|
||||
AbstractRemoteLinuxApplicationRunner::AbstractRemoteLinuxApplicationRunner(RemoteLinuxRunConfiguration *runConfig,
|
||||
QObject *parent)
|
||||
: QObject(parent), m_d(new AbstractRemoteLinuxApplicationRunnerPrivate(runConfig))
|
||||
: QObject(parent), d(new AbstractRemoteLinuxApplicationRunnerPrivate(runConfig))
|
||||
{
|
||||
connect(&m_d->portsGatherer, SIGNAL(error(QString)), SLOT(handlePortsGathererError(QString)));
|
||||
connect(&m_d->portsGatherer, SIGNAL(portListReady()), SLOT(handleUsedPortsAvailable()));
|
||||
connect(&d->portsGatherer, SIGNAL(error(QString)), SLOT(handlePortsGathererError(QString)));
|
||||
connect(&d->portsGatherer, SIGNAL(portListReady()), SLOT(handleUsedPortsAvailable()));
|
||||
}
|
||||
|
||||
AbstractRemoteLinuxApplicationRunner::~AbstractRemoteLinuxApplicationRunner()
|
||||
{
|
||||
delete m_d;
|
||||
delete d;
|
||||
}
|
||||
|
||||
SshConnection::Ptr AbstractRemoteLinuxApplicationRunner::connection() const
|
||||
{
|
||||
return m_d->connection;
|
||||
return d->connection;
|
||||
}
|
||||
|
||||
LinuxDeviceConfiguration::ConstPtr AbstractRemoteLinuxApplicationRunner::devConfig() const
|
||||
{
|
||||
return m_d->devConfig;
|
||||
return d->devConfig;
|
||||
}
|
||||
|
||||
const RemoteLinuxUsedPortsGatherer *AbstractRemoteLinuxApplicationRunner::usedPortsGatherer() const
|
||||
{
|
||||
return &m_d->portsGatherer;
|
||||
return &d->portsGatherer;
|
||||
}
|
||||
|
||||
PortList *AbstractRemoteLinuxApplicationRunner::freePorts()
|
||||
{
|
||||
return &m_d->freePorts;
|
||||
return &d->freePorts;
|
||||
}
|
||||
|
||||
QString AbstractRemoteLinuxApplicationRunner::remoteExecutable() const
|
||||
{
|
||||
return m_d->remoteExecutable;
|
||||
return d->remoteExecutable;
|
||||
}
|
||||
|
||||
QString AbstractRemoteLinuxApplicationRunner::arguments() const
|
||||
{
|
||||
return m_d->appArguments;
|
||||
return d->appArguments;
|
||||
}
|
||||
|
||||
QString AbstractRemoteLinuxApplicationRunner::commandPrefix() const
|
||||
{
|
||||
return m_d->commandPrefix;
|
||||
return d->commandPrefix;
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::start()
|
||||
{
|
||||
QTC_ASSERT(!m_d->stopRequested && m_d->state == Inactive, return);
|
||||
QTC_ASSERT(!d->stopRequested && d->state == Inactive, return);
|
||||
|
||||
QString errorMsg;
|
||||
if (!canRun(errorMsg)) {
|
||||
@@ -152,22 +152,22 @@ void AbstractRemoteLinuxApplicationRunner::start()
|
||||
return;
|
||||
}
|
||||
|
||||
m_d->state = SettingUpDevice;
|
||||
d->state = SettingUpDevice;
|
||||
doDeviceSetup();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::stop()
|
||||
{
|
||||
if (m_d->stopRequested)
|
||||
if (d->stopRequested)
|
||||
return;
|
||||
|
||||
switch (m_d->state) {
|
||||
switch (d->state) {
|
||||
case Connecting:
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
break;
|
||||
case GatheringPorts:
|
||||
m_d->portsGatherer.stop();
|
||||
d->portsGatherer.stop();
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
break;
|
||||
@@ -177,15 +177,15 @@ void AbstractRemoteLinuxApplicationRunner::stop()
|
||||
case AdditionalInitializing:
|
||||
case ProcessStarting:
|
||||
case PostRunCleaning:
|
||||
m_d->stopRequested = true; // TODO: We might need stopPreRunCleaning() etc. for the subclasses
|
||||
d->stopRequested = true; // TODO: We might need stopPreRunCleaning() etc. for the subclasses
|
||||
break;
|
||||
case ReadyForExecution:
|
||||
m_d->stopRequested = true;
|
||||
m_d->state = PostRunCleaning;
|
||||
d->stopRequested = true;
|
||||
d->state = PostRunCleaning;
|
||||
doPostRunCleanup();
|
||||
break;
|
||||
case ProcessStarted:
|
||||
m_d->stopRequested = true;
|
||||
d->stopRequested = true;
|
||||
cleanup();
|
||||
break;
|
||||
case Inactive:
|
||||
@@ -195,38 +195,38 @@ void AbstractRemoteLinuxApplicationRunner::stop()
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleConnected()
|
||||
{
|
||||
QTC_ASSERT(m_d->state == Connecting, return);
|
||||
QTC_ASSERT(d->state == Connecting, return);
|
||||
|
||||
if (m_d->stopRequested) {
|
||||
if (d->stopRequested) {
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
setInactive();
|
||||
} else {
|
||||
m_d->state = PreRunCleaning;
|
||||
d->state = PreRunCleaning;
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleConnectionFailure()
|
||||
{
|
||||
QTC_ASSERT(m_d->state != Inactive, return);
|
||||
QTC_ASSERT(d->state != Inactive, return);
|
||||
|
||||
if (m_d->state != Connecting || m_d->state != PreRunCleaning)
|
||||
if (d->state != Connecting || d->state != PreRunCleaning)
|
||||
doAdditionalConnectionErrorHandling();
|
||||
|
||||
const QString errorMsg = m_d->state == Connecting
|
||||
const QString errorMsg = d->state == Connecting
|
||||
? tr("Could not connect to host: %1") : tr("Connection error: %1");
|
||||
emitError(errorMsg.arg(m_d->connection->errorString()));
|
||||
emitError(errorMsg.arg(d->connection->errorString()));
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::cleanup()
|
||||
{
|
||||
QTC_ASSERT(m_d->state == PreRunCleaning
|
||||
|| (m_d->state == ProcessStarted && m_d->stopRequested), return);
|
||||
QTC_ASSERT(d->state == PreRunCleaning
|
||||
|| (d->state == ProcessStarted && d->stopRequested), return);
|
||||
|
||||
emit reportProgress(tr("Killing remote process(es)..."));
|
||||
m_d->cleaner = m_d->connection->createRemoteProcess(killApplicationCommandLine().toUtf8());
|
||||
connect(m_d->cleaner.data(), SIGNAL(closed(int)), SLOT(handleCleanupFinished(int)));
|
||||
m_d->cleaner->start();
|
||||
d->cleaner = d->connection->createRemoteProcess(killApplicationCommandLine().toUtf8());
|
||||
connect(d->cleaner.data(), SIGNAL(closed(int)), SLOT(handleCleanupFinished(int)));
|
||||
d->cleaner->start();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleCleanupFinished(int exitStatus)
|
||||
@@ -235,56 +235,56 @@ void AbstractRemoteLinuxApplicationRunner::handleCleanupFinished(int exitStatus)
|
||||
|| exitStatus == SshRemoteProcess::KilledBySignal
|
||||
|| exitStatus == SshRemoteProcess::ExitedNormally);
|
||||
|
||||
QTC_ASSERT(m_d->state == PreRunCleaning
|
||||
|| (m_d->state == ProcessStarted && m_d->stopRequested) || m_d->state == Inactive, return);
|
||||
QTC_ASSERT(d->state == PreRunCleaning
|
||||
|| (d->state == ProcessStarted && d->stopRequested) || d->state == Inactive, return);
|
||||
|
||||
if (m_d->state == Inactive)
|
||||
if (d->state == Inactive)
|
||||
return;
|
||||
if (m_d->stopRequested && m_d->state == PreRunCleaning) {
|
||||
if (d->stopRequested && d->state == PreRunCleaning) {
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
return;
|
||||
}
|
||||
if (m_d->stopRequested) {
|
||||
m_d->state = PostRunCleaning;
|
||||
if (d->stopRequested) {
|
||||
d->state = PostRunCleaning;
|
||||
doPostRunCleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
if (exitStatus != SshRemoteProcess::ExitedNormally) {
|
||||
emitError(tr("Initial cleanup failed: %1").arg(m_d->cleaner->errorString()));
|
||||
emitError(tr("Initial cleanup failed: %1").arg(d->cleaner->errorString()));
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
return;
|
||||
}
|
||||
|
||||
m_d->state = AdditionalPreRunCleaning;
|
||||
d->state = AdditionalPreRunCleaning;
|
||||
doAdditionalInitialCleanup();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::startExecution(const QByteArray &remoteCall)
|
||||
{
|
||||
QTC_ASSERT(m_d->state == ReadyForExecution, return);
|
||||
QTC_ASSERT(d->state == ReadyForExecution, return);
|
||||
|
||||
if (m_d->stopRequested)
|
||||
if (d->stopRequested)
|
||||
return;
|
||||
|
||||
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)),
|
||||
d->runner = d->connection->createRemoteProcess(remoteCall);
|
||||
connect(d->runner.data(), SIGNAL(started()), SLOT(handleRemoteProcessStarted()));
|
||||
connect(d->runner.data(), SIGNAL(closed(int)), SLOT(handleRemoteProcessFinished(int)));
|
||||
connect(d->runner.data(), SIGNAL(outputAvailable(QByteArray)),
|
||||
SIGNAL(remoteOutput(QByteArray)));
|
||||
connect(m_d->runner.data(), SIGNAL(errorOutputAvailable(QByteArray)),
|
||||
connect(d->runner.data(), SIGNAL(errorOutputAvailable(QByteArray)),
|
||||
SIGNAL(remoteErrorOutput(QByteArray)));
|
||||
m_d->state = ProcessStarting;
|
||||
m_d->runner->start();
|
||||
d->state = ProcessStarting;
|
||||
d->runner->start();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleRemoteProcessStarted()
|
||||
{
|
||||
QTC_ASSERT(m_d->state == ProcessStarting, return);
|
||||
QTC_ASSERT(d->state == ProcessStarting, return);
|
||||
|
||||
m_d->state = ProcessStarted;
|
||||
if (m_d->stopRequested) {
|
||||
d->state = ProcessStarted;
|
||||
if (d->stopRequested) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
@@ -298,32 +298,32 @@ void AbstractRemoteLinuxApplicationRunner::handleRemoteProcessFinished(int exitS
|
||||
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|
||||
|| exitStatus == SshRemoteProcess::KilledBySignal
|
||||
|| exitStatus == SshRemoteProcess::ExitedNormally);
|
||||
QTC_ASSERT(m_d->state == ProcessStarted || m_d->state == Inactive, return);
|
||||
QTC_ASSERT(d->state == ProcessStarted || d->state == Inactive, return);
|
||||
|
||||
m_d->exitStatus = exitStatus;
|
||||
if (!m_d->stopRequested && m_d->state != Inactive) {
|
||||
m_d->state = PostRunCleaning;
|
||||
d->exitStatus = exitStatus;
|
||||
if (!d->stopRequested && d->state != Inactive) {
|
||||
d->state = PostRunCleaning;
|
||||
doPostRunCleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::setInactive()
|
||||
{
|
||||
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();
|
||||
d->portsGatherer.stop();
|
||||
if (d->connection) {
|
||||
disconnect(d->connection.data(), 0, this, 0);
|
||||
SshConnectionManager::instance().releaseConnection(d->connection);
|
||||
d->connection = SshConnection::Ptr();
|
||||
}
|
||||
if (m_d->cleaner)
|
||||
disconnect(m_d->cleaner.data(), 0, this, 0);
|
||||
m_d->stopRequested = false;
|
||||
m_d->state = Inactive;
|
||||
if (d->cleaner)
|
||||
disconnect(d->cleaner.data(), 0, this, 0);
|
||||
d->stopRequested = false;
|
||||
d->state = Inactive;
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::emitError(const QString &errorMsg, bool force)
|
||||
{
|
||||
if (m_d->state != Inactive) {
|
||||
if (d->state != Inactive) {
|
||||
setInactive();
|
||||
emit error(errorMsg);
|
||||
} else if (force) {
|
||||
@@ -333,7 +333,7 @@ void AbstractRemoteLinuxApplicationRunner::emitError(const QString &errorMsg, bo
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handlePortsGathererError(const QString &errorMsg)
|
||||
{
|
||||
if (m_d->state != Inactive) {
|
||||
if (d->state != Inactive) {
|
||||
if (connection()->errorState() != SshNoError) {
|
||||
emitError(errorMsg);
|
||||
} else {
|
||||
@@ -345,26 +345,26 @@ void AbstractRemoteLinuxApplicationRunner::handlePortsGathererError(const QStrin
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleUsedPortsAvailable()
|
||||
{
|
||||
QTC_ASSERT(m_d->state == GatheringPorts, return);
|
||||
QTC_ASSERT(d->state == GatheringPorts, return);
|
||||
|
||||
if (m_d->stopRequested) {
|
||||
if (d->stopRequested) {
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
return;
|
||||
}
|
||||
|
||||
m_d->state = AdditionalInitializing;
|
||||
d->state = AdditionalInitializing;
|
||||
doAdditionalInitializations();
|
||||
}
|
||||
|
||||
bool AbstractRemoteLinuxApplicationRunner::canRun(QString &whyNot) const
|
||||
{
|
||||
if (m_d->remoteExecutable.isEmpty()) {
|
||||
if (d->remoteExecutable.isEmpty()) {
|
||||
whyNot = tr("No remote executable set.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_d->devConfig) {
|
||||
if (!d->devConfig) {
|
||||
whyNot = tr("No device configuration set.");
|
||||
return false;
|
||||
}
|
||||
@@ -374,80 +374,80 @@ bool AbstractRemoteLinuxApplicationRunner::canRun(QString &whyNot) const
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::setDeviceConfiguration(const LinuxDeviceConfiguration::ConstPtr &deviceConfig)
|
||||
{
|
||||
m_d->devConfig = deviceConfig;
|
||||
d->devConfig = deviceConfig;
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleDeviceSetupDone(bool success)
|
||||
{
|
||||
QTC_ASSERT(m_d->state == SettingUpDevice, return);
|
||||
QTC_ASSERT(d->state == SettingUpDevice, return);
|
||||
|
||||
if (!success || m_d->stopRequested) {
|
||||
if (!success || d->stopRequested) {
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
return;
|
||||
}
|
||||
|
||||
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)),
|
||||
d->connection = SshConnectionManager::instance().acquireConnection(d->devConfig->sshParameters());
|
||||
d->state = Connecting;
|
||||
d->exitStatus = -1;
|
||||
d->freePorts = d->initialFreePorts;
|
||||
connect(d->connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
|
||||
connect(d->connection.data(), SIGNAL(error(Utils::SshError)),
|
||||
SLOT(handleConnectionFailure()));
|
||||
if (m_d->connection->state() == SshConnection::Connected) {
|
||||
if (d->connection->state() == SshConnection::Connected) {
|
||||
handleConnected();
|
||||
} else {
|
||||
emit reportProgress(tr("Connecting to device..."));
|
||||
if (m_d->connection->state() == Utils::SshConnection::Unconnected)
|
||||
m_d->connection->connectToHost();
|
||||
if (d->connection->state() == Utils::SshConnection::Unconnected)
|
||||
d->connection->connectToHost();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleInitialCleanupDone(bool success)
|
||||
{
|
||||
QTC_ASSERT(m_d->state == AdditionalPreRunCleaning, return);
|
||||
QTC_ASSERT(d->state == AdditionalPreRunCleaning, return);
|
||||
|
||||
if (!success || m_d->stopRequested) {
|
||||
if (!success || d->stopRequested) {
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
return;
|
||||
}
|
||||
|
||||
m_d->state = GatheringPorts;
|
||||
m_d->portsGatherer.start(m_d->connection, m_d->devConfig);
|
||||
d->state = GatheringPorts;
|
||||
d->portsGatherer.start(d->connection, d->devConfig);
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handleInitializationsDone(bool success)
|
||||
{
|
||||
QTC_ASSERT(m_d->state == AdditionalInitializing, return);
|
||||
QTC_ASSERT(d->state == AdditionalInitializing, return);
|
||||
|
||||
if (!success) {
|
||||
setInactive();
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
return;
|
||||
}
|
||||
if (m_d->stopRequested) {
|
||||
m_d->state = PostRunCleaning;
|
||||
if (d->stopRequested) {
|
||||
d->state = PostRunCleaning;
|
||||
doPostRunCleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
m_d->state = ReadyForExecution;
|
||||
d->state = ReadyForExecution;
|
||||
emit readyForExecution();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxApplicationRunner::handlePostRunCleanupDone()
|
||||
{
|
||||
QTC_ASSERT(m_d->state == PostRunCleaning, return);
|
||||
QTC_ASSERT(d->state == PostRunCleaning, return);
|
||||
|
||||
const bool wasStopRequested = m_d->stopRequested;
|
||||
const bool wasStopRequested = d->stopRequested;
|
||||
setInactive();
|
||||
if (wasStopRequested)
|
||||
emit remoteProcessFinished(InvalidExitCode);
|
||||
else if (m_d->exitStatus == SshRemoteProcess::ExitedNormally)
|
||||
emit remoteProcessFinished(m_d->runner->exitCode());
|
||||
else if (d->exitStatus == SshRemoteProcess::ExitedNormally)
|
||||
emit remoteProcessFinished(d->runner->exitCode());
|
||||
else
|
||||
emit error(tr("Error running remote process: %1").arg(m_d->runner->errorString()));
|
||||
emit error(tr("Error running remote process: %1").arg(d->runner->errorString()));
|
||||
}
|
||||
|
||||
const qint64 AbstractRemoteLinuxApplicationRunner::InvalidExitCode = std::numeric_limits<qint64>::min();
|
||||
|
||||
Reference in New Issue
Block a user