Maemo: Factor SSH operations out of run control classes.

Preparation for removing MaemoDebugRunControl.

Reviewed-by: kh1
This commit is contained in:
ck
2010-07-14 17:26:51 +02:00
parent 01fb9cdbaf
commit 032e7dc4c6
10 changed files with 392 additions and 229 deletions

View File

@@ -57,6 +57,15 @@ struct CORE_EXPORT SshConnectionParameters
enum AuthType { AuthByPwd, AuthByKey } authType; enum AuthType { AuthByPwd, AuthByKey } authType;
quint16 port; quint16 port;
}; };
CORE_EXPORT inline bool operator==(const SshConnectionParameters &p1,
const SshConnectionParameters &p2)
{
return p1.host == p2.host && p1.uname == p2.uname
&& p1.authType == p2.authType
&& (p1.authType == SshConnectionParameters::AuthByPwd ?
p1.pwd == p2.pwd : p1.privateKeyFile == p2.privateKeyFile)
&& p1.timeout == p2.timeout && p1.port == p2.port;
}
/* /*

View File

@@ -85,8 +85,7 @@ QString RemotePlainGdbAdapter::fromLocalEncoding(const QByteArray &b) const
void RemotePlainGdbAdapter::handleApplicationOutput(const QByteArray &output) void RemotePlainGdbAdapter::handleApplicationOutput(const QByteArray &output)
{ {
// FIXME: Remote encoding? showMessage(QString::fromUtf8(output), AppOutput);
showMessage(QString::fromLatin1(output), AppOutput);
} }
} // namespace Internal } // namespace Internal

View File

@@ -29,9 +29,9 @@
#include "maemorunconfiguration.h" #include "maemorunconfiguration.h"
#include "maemodeployables.h"
#include "maemodeploystep.h" #include "maemodeploystep.h"
#include "maemoglobal.h" #include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemorunconfigurationwidget.h" #include "maemorunconfigurationwidget.h"
#include "maemotoolchain.h" #include "maemotoolchain.h"
#include "qemuruntimemanager.h" #include "qemuruntimemanager.h"
@@ -217,7 +217,7 @@ const QString MaemoRunConfiguration::dumperLib() const
return qt4bc->qtVersion()->debuggingHelperLibrary(); return qt4bc->qtVersion()->debuggingHelperLibrary();
} }
QString MaemoRunConfiguration::executable() const QString MaemoRunConfiguration::localExecutableFilePath() const
{ {
TargetInformation ti = qt4Target()->qt4Project()->rootProjectNode() TargetInformation ti = qt4Target()->qt4Project()->rootProjectNode()
->targetInformation(m_proFilePath); ->targetInformation(m_proFilePath);
@@ -227,6 +227,12 @@ QString MaemoRunConfiguration::executable() const
return QDir::cleanPath(ti.workingDir + QLatin1Char('/') + ti.target); return QDir::cleanPath(ti.workingDir + QLatin1Char('/') + ti.target);
} }
QString MaemoRunConfiguration::remoteExecutableFilePath() const
{
return deployStep()->deployables()
->remoteExecutableFilePath(localExecutableFilePath());
}
QString MaemoRunConfiguration::runtimeGdbServerPort() const QString MaemoRunConfiguration::runtimeGdbServerPort() const
{ {
if (Qt4BuildConfiguration *qt4bc = activeQt4BuildConfiguration()) { if (Qt4BuildConfiguration *qt4bc = activeQt4BuildConfiguration()) {

View File

@@ -75,7 +75,8 @@ public:
MaemoDeployStep *deployStep() const; MaemoDeployStep *deployStep() const;
QString maddeRoot() const; QString maddeRoot() const;
QString executable() const; QString localExecutableFilePath() const;
QString remoteExecutableFilePath() const;
const QString sysRoot() const; const QString sysRoot() const;
const QString targetRoot() const; const QString targetRoot() const;
const QStringList arguments() const; const QStringList arguments() const;

View File

@@ -83,7 +83,7 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
devConfLayout->addWidget(debuggerConfLabel); devConfLayout->addWidget(debuggerConfLabel);
mainLayout->addRow(new QLabel(tr("Device configuration:")), devConfWidget); mainLayout->addRow(new QLabel(tr("Device configuration:")), devConfWidget);
m_executableLabel = new QLabel(m_runConfiguration->executable()); m_executableLabel = new QLabel(m_runConfiguration->localExecutableFilePath());
mainLayout->addRow(tr("Executable:"), m_executableLabel); mainLayout->addRow(tr("Executable:"), m_executableLabel);
m_argsLineEdit = new QLineEdit(m_runConfiguration->arguments().join(" ")); m_argsLineEdit = new QLineEdit(m_runConfiguration->arguments().join(" "));
mainLayout->addRow(tr("Arguments:"), m_argsLineEdit); mainLayout->addRow(tr("Arguments:"), m_argsLineEdit);
@@ -118,7 +118,7 @@ void MaemoRunConfigurationWidget::argumentsEdited(const QString &text)
void MaemoRunConfigurationWidget::updateTargetInformation() void MaemoRunConfigurationWidget::updateTargetInformation()
{ {
m_executableLabel->setText(m_runConfiguration->executable()); m_executableLabel->setText(m_runConfiguration->localExecutableFilePath());
} }
void MaemoRunConfigurationWidget::deviceConfigurationChanged(const QString &name) void MaemoRunConfigurationWidget::deviceConfigurationChanged(const QString &name)

View File

@@ -34,15 +34,14 @@
#include "maemoruncontrol.h" #include "maemoruncontrol.h"
#include "maemodeployables.h"
#include "maemodeploystep.h" #include "maemodeploystep.h"
#include "maemoglobal.h" #include "maemoglobal.h"
#include "maemorunconfiguration.h" #include "maemorunconfiguration.h"
#include "maemosshrunner.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/ssh/sftpchannel.h> #include <coreplugin/ssh/sftpchannel.h>
#include <coreplugin/ssh/sshconnection.h> #include <coreplugin/ssh/sshconnection.h>
#include <coreplugin/ssh/sshremoteprocess.h>
#include <debugger/debuggerengine.h> #include <debugger/debuggerengine.h>
#include <debugger/debuggerplugin.h> #include <debugger/debuggerplugin.h>
#include <debugger/debuggerrunner.h> #include <debugger/debuggerrunner.h>
@@ -73,6 +72,8 @@ AbstractMaemoRunControl::AbstractMaemoRunControl(RunConfiguration *rc, QString m
: RunControl(rc, mode) : RunControl(rc, mode)
, m_runConfig(qobject_cast<MaemoRunConfiguration *>(rc)) , m_runConfig(qobject_cast<MaemoRunConfiguration *>(rc))
, m_devConfig(m_runConfig ? m_runConfig->deviceConfig() : MaemoDeviceConfig()) , m_devConfig(m_runConfig ? m_runConfig->deviceConfig() : MaemoDeviceConfig())
, m_runner(new MaemoSshRunner(this, m_runConfig))
, m_running(false)
{ {
} }
@@ -80,115 +81,62 @@ AbstractMaemoRunControl::~AbstractMaemoRunControl()
{ {
} }
// TODO: We can cache the connection. We'd have to check if the connection
// is active and its parameters are the same as m_devConfig. If yes,
// skip the connection step and jump right to handleConnected()
void AbstractMaemoRunControl::start() void AbstractMaemoRunControl::start()
{ {
if (!m_devConfig.isValid()) { if (!m_devConfig.isValid()) {
handleError(tr("No device configuration set for run configuration.")); handleError(tr("No device configuration set for run configuration."));
} else { } else {
emit appendMessage(this, tr("Preparing remote side ..."), false);
m_running = true;
m_stopped = false; m_stopped = false;
emit started(); emit started();
m_connection = SshConnection::create(); connect(m_runner, SIGNAL(error(QString)), this,
connect(m_connection.data(), SIGNAL(connected()), this, SLOT(handleSshError(QString)));
SLOT(handleConnected())); connect(m_runner, SIGNAL(readyForExecution()), this,
connect(m_connection.data(), SIGNAL(error(SshError)), this, SLOT(startExecution()));
SLOT(handleConnectionFailure())); connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)), this,
m_connection->connectToHost(m_devConfig.server); SLOT(handleRemoteErrorOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteOutput(QByteArray)), this,
SLOT(handleRemoteOutput(QByteArray)));
connect(m_runner, SIGNAL(remoteProcessStarted()), this,
SLOT(handleRemoteProcessStarted()));
connect(m_runner, SIGNAL(remoteProcessFinished(int)), this,
SLOT(handleRemoteProcessFinished(int)));
m_runner->start();
} }
} }
void AbstractMaemoRunControl::handleConnected()
{
if (m_stopped)
return;
emit appendMessage(this, tr("Cleaning up remote leftovers first ..."), false);
const QStringList appsToKill = QStringList() << executableFileName()
#ifdef USE_GDBSERVER
<< QLatin1String("gdbserver");
#else
<< QLatin1String("gdb");
#endif
killRemoteProcesses(appsToKill, true);
}
void AbstractMaemoRunControl::handleConnectionFailure()
{
if (m_stopped)
return;
handleError(tr("Could not connect to host: %1")
.arg(m_connection->errorString()));
emit finished();
}
void AbstractMaemoRunControl::stop() void AbstractMaemoRunControl::stop()
{ {
m_stopped = true; m_stopped = true;
if (m_connection && m_connection->state() == SshConnection::Connecting) { if (m_runner)
disconnect(m_connection.data(), 0, this, 0); m_runner->stop();
m_connection->disconnectFromHost();
emit finished();
} else if (m_initialCleaner && m_initialCleaner->isRunning()) {
disconnect(m_initialCleaner.data(), 0, this, 0);
emit finished();
} else {
stopInternal(); stopInternal();
}
} }
QString AbstractMaemoRunControl::executableFilePathOnTarget() const void AbstractMaemoRunControl::handleSshError(const QString &error)
{ {
const MaemoDeployables * const deployables handleError(error);
= m_runConfig->deployStep()->deployables(); setFinished();
return deployables->remoteExecutableFilePath(m_runConfig->executable());
}
void AbstractMaemoRunControl::startExecutionIfPossible()
{
if (executableFilePathOnTarget().isEmpty()) {
handleError(tr("Cannot run: No remote executable set."));
emit finished();
} else {
startExecution();
}
} }
void AbstractMaemoRunControl::startExecution() void AbstractMaemoRunControl::startExecution()
{ {
m_runner = m_connection->createRemoteProcess(remoteCall().toUtf8()); emit appendMessage(this, tr("Starting remote process ..."), false);
connect(m_runner.data(), SIGNAL(started()), this, m_runner->startExecution(QString::fromLocal8Bit("%1 %2 %3")
SLOT(handleRemoteProcessStarted())); .arg(targetCmdLinePrefix()).arg(m_runConfig->remoteExecutableFilePath())
connect(m_runner.data(), SIGNAL(closed(int)), this, .arg(arguments()).toUtf8());
SLOT(handleRemoteProcessFinished(int)));
connect(m_runner.data(), SIGNAL(outputAvailable(QByteArray)), this,
SLOT(handleRemoteOutput(QByteArray)));
connect(m_runner.data(), SIGNAL(errorOutputAvailable(QByteArray)), this,
SLOT(handleRemoteErrorOutput(QByteArray)));
emit appendMessage(this, tr("Starting remote application."), false);
m_runner->start();
} }
void AbstractMaemoRunControl::handleRemoteProcessFinished(int exitStatus) void AbstractMaemoRunControl::handleRemoteProcessFinished(int exitCode)
{ {
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (m_stopped) if (m_stopped)
return; return;
if (exitStatus == SshRemoteProcess::ExitedNormally) {
emit appendMessage(this, emit appendMessage(this,
tr("Finished running remote process. Exit code was %1.") tr("Finished running remote process. Exit code was %1.").arg(exitCode),
.arg(m_runner->exitCode()), false); false);
emit finished(); setFinished();
} else {
handleError(tr("Error running remote process: %1")
.arg(m_runner->errorString()));
}
} }
void AbstractMaemoRunControl::handleRemoteOutput(const QByteArray &output) void AbstractMaemoRunControl::handleRemoteOutput(const QByteArray &output)
@@ -203,84 +151,17 @@ void AbstractMaemoRunControl::handleRemoteErrorOutput(const QByteArray &output)
bool AbstractMaemoRunControl::isRunning() const bool AbstractMaemoRunControl::isRunning() const
{ {
return m_runner && m_runner->isRunning(); return m_running;
}
void AbstractMaemoRunControl::stopRunning(bool forDebugging)
{
if (m_runner && m_runner->isRunning()) {
disconnect(m_runner.data(), 0, this, 0);
QStringList apps(executableFileName());
if (forDebugging)
apps << QLatin1String("gdbserver");
killRemoteProcesses(apps, false);
emit finished();
}
}
void AbstractMaemoRunControl::killRemoteProcesses(const QStringList &apps,
bool initialCleanup)
{
QString niceKill;
QString brutalKill;
foreach (const QString &app, apps) {
niceKill += QString::fromLocal8Bit("pkill -x %1;").arg(app);
brutalKill += QString::fromLocal8Bit("pkill -x -9 %1;").arg(app);
}
QString remoteCall = niceKill + QLatin1String("sleep 1; ") + brutalKill;
remoteCall.remove(remoteCall.count() - 1, 1); // Get rid of trailing semicolon.
SshRemoteProcess::Ptr proc
= m_connection->createRemoteProcess(remoteCall.toUtf8());
if (initialCleanup) {
m_initialCleaner = proc;
connect(m_initialCleaner.data(), SIGNAL(closed(int)), this,
SLOT(handleInitialCleanupFinished(int)));
} else {
m_stopper = proc;
}
proc->start();
}
void AbstractMaemoRunControl::handleInitialCleanupFinished(int exitStatus)
{
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (m_stopped)
return;
if (exitStatus != SshRemoteProcess::ExitedNormally) {
handleError(tr("Initial cleanup failed: %1")
.arg(m_initialCleaner->errorString()));
} else {
emit appendMessage(this, tr("Initial cleanup done."), false);
startExecutionIfPossible();
}
}
const QString AbstractMaemoRunControl::executableOnHost() const
{
return m_runConfig->executable();
}
const QString AbstractMaemoRunControl::executableFileName() const
{
return QFileInfo(executableOnHost()).fileName();
}
const QString AbstractMaemoRunControl::uploadDir() const
{
return MaemoGlobal::homeDirOnDevice(m_devConfig.server.uname);
} }
const QString AbstractMaemoRunControl::targetCmdLinePrefix() const const QString AbstractMaemoRunControl::targetCmdLinePrefix() const
{ {
return QString::fromLocal8Bit("%1 chmod a+x %2 && source /etc/profile && DISPLAY=:0.0 ") return QString::fromLocal8Bit("%1 chmod a+x %2 && source /etc/profile && DISPLAY=:0.0 ")
.arg(MaemoGlobal::remoteSudo()).arg(executableFilePathOnTarget()); .arg(MaemoGlobal::remoteSudo())
.arg(m_runConfig->remoteExecutableFilePath());
} }
QString AbstractMaemoRunControl::targetCmdLineSuffix() const QString AbstractMaemoRunControl::arguments() const
{ {
return m_runConfig->arguments().join(" "); return m_runConfig->arguments().join(" ");
} }
@@ -292,12 +173,10 @@ void AbstractMaemoRunControl::handleError(const QString &errString)
stop(); stop();
} }
template<typename SshChannel> void AbstractMaemoRunControl::closeSshChannel(SshChannel &channel) void AbstractMaemoRunControl::setFinished()
{ {
if (channel) { m_running = false;
disconnect(channel.data(), 0, this, 0); emit finished();
// channel->closeChannel();
}
} }
@@ -311,15 +190,9 @@ MaemoRunControl::~MaemoRunControl()
stop(); stop();
} }
QString MaemoRunControl::remoteCall() const
{
return QString::fromLocal8Bit("%1 %2 %3").arg(targetCmdLinePrefix())
.arg(executableFilePathOnTarget()).arg(targetCmdLineSuffix());
}
void MaemoRunControl::stopInternal() void MaemoRunControl::stopInternal()
{ {
AbstractMaemoRunControl::stopRunning(false); setFinished();
} }
@@ -331,17 +204,19 @@ MaemoDebugRunControl::MaemoDebugRunControl(RunConfiguration *runConfiguration)
{ {
#ifdef USE_GDBSERVER #ifdef USE_GDBSERVER
m_startParams->startMode = AttachToRemote; m_startParams->startMode = AttachToRemote;
m_startParams->executable = executableOnHost(); m_startParams->executable = m_runConfig->localExecutableFilePath();
m_startParams->debuggerCommand = m_runConfig->gdbCmd(); m_startParams->debuggerCommand = m_runConfig->gdbCmd();
m_startParams->remoteChannel m_startParams->remoteChannel
= m_devConfig.server.host % QLatin1Char(':') % gdbServerPort(); = m_devConfig.server.host % QLatin1Char(':') % gdbServerPort();
m_startParams->remoteArchitecture = QLatin1String("arm"); m_startParams->remoteArchitecture = QLatin1String("arm");
m_runner->addProcsToKill(QStringList() << QLatin1String("gdbserver"));
#else #else
m_startParams->startMode = StartRemoteGdb; m_startParams->startMode = StartRemoteGdb;
m_startParams->executable = executableFilePathOnTarget(); m_startParams->executable = m_runConfig->remoteExecutableFilePath();
m_startParams->debuggerCommand = targetCmdLinePrefix() m_startParams->debuggerCommand = targetCmdLinePrefix()
+ QLatin1String(" /usr/bin/gdb"); + QLatin1String(" /usr/bin/gdb");
m_startParams->connParams = m_devConfig.server; m_startParams->connParams = m_devConfig.server;
m_runner->addProcsToKill(QStringList() << QLatin1String("gdb"));
#endif #endif
m_startParams->processArgs = m_runConfig->arguments(); m_startParams->processArgs = m_runConfig->arguments();
m_startParams->sysRoot = m_runConfig->sysRoot(); m_startParams->sysRoot = m_runConfig->sysRoot();
@@ -362,20 +237,13 @@ MaemoDebugRunControl::~MaemoDebugRunControl()
stop(); stop();
} }
QString MaemoDebugRunControl::remoteCall() const
{
return QString::fromLocal8Bit("%1 gdbserver :%2 %3 %4")
.arg(targetCmdLinePrefix()).arg(gdbServerPort())
.arg(executableFilePathOnTarget()).arg(targetCmdLineSuffix());
}
void MaemoDebugRunControl::startExecution() void MaemoDebugRunControl::startExecution()
{ {
const QString &dumperLib = m_runConfig->dumperLib(); const QString &dumperLib = m_runConfig->dumperLib();
if (!dumperLib.isEmpty() if (!dumperLib.isEmpty()
&& m_runConfig->deployStep()->currentlyNeedsDeployment(m_devConfig.server.host, && m_runConfig->deployStep()->currentlyNeedsDeployment(m_devConfig.server.host,
MaemoDeployable(dumperLib, uploadDir()))) { MaemoDeployable(dumperLib, uploadDir()))) {
m_uploader = m_connection->createSftpChannel(); m_uploader = m_runner->connection()->createSftpChannel();
connect(m_uploader.data(), SIGNAL(initialized()), this, connect(m_uploader.data(), SIGNAL(initialized()), this,
SLOT(handleSftpChannelInitialized())); SLOT(handleSftpChannelInitialized()));
connect(m_uploader.data(), SIGNAL(initializationFailed(QString)), this, connect(m_uploader.data(), SIGNAL(initializationFailed(QString)), this,
@@ -438,7 +306,10 @@ void MaemoDebugRunControl::handleSftpJobFinished(Core::SftpJobId job,
void MaemoDebugRunControl::startDebugging() void MaemoDebugRunControl::startDebugging()
{ {
#ifdef USE_GDBSERVER #ifdef USE_GDBSERVER
AbstractMaemoRunControl::startExecution(); m_runner->startExecution(QString::fromLocal8Bit("%1 gdbserver :%2 %3 %4")
.arg(targetCmdLinePrefix()).arg(gdbServerPort())
.arg(m_runConfig->remoteExecutableFilePath())
.arg(arguments()).toUtf8());
#else #else
DebuggerPlugin::startDebugger(m_debuggerRunControl); DebuggerPlugin::startDebugger(m_debuggerRunControl);
#endif #endif
@@ -455,27 +326,20 @@ void MaemoDebugRunControl::stopInternal()
disconnect(m_uploader.data(), 0, this, 0); disconnect(m_uploader.data(), 0, this, 0);
m_uploader->closeChannel(); m_uploader->closeChannel();
m_uploadJob = SftpInvalidJob; m_uploadJob = SftpInvalidJob;
emit finished(); setFinished();
} else if (m_debuggerRunControl && m_debuggerRunControl->engine()) { } else if (m_debuggerRunControl && m_debuggerRunControl->engine()) {
m_debuggerRunControl->engine()->quitDebugger(); m_debuggerRunControl->engine()->quitDebugger();
} else { } else {
emit finished(); setFinished();
} }
} }
bool MaemoDebugRunControl::isRunning() const
{
return isDeploying() || AbstractMaemoRunControl::isRunning()
|| m_debuggerRunControl->state() != DebuggerNotReady;
}
void MaemoDebugRunControl::debuggingFinished() void MaemoDebugRunControl::debuggingFinished()
{ {
#ifdef USE_GDBSERVER #ifdef USE_GDBSERVER
AbstractMaemoRunControl::stopRunning(true); m_runner->stop();
#else
emit finished();
#endif #endif
setFinished();
} }
void MaemoDebugRunControl::handleRemoteProcessStarted() void MaemoDebugRunControl::handleRemoteProcessStarted()
@@ -497,5 +361,10 @@ QString MaemoDebugRunControl::gdbServerPort() const
// but we will make sure we use the right port from the information file. // but we will make sure we use the right port from the information file.
} }
QString MaemoDebugRunControl::uploadDir() const
{
return MaemoGlobal::homeDirOnDevice(m_devConfig.server.uname);
}
} // namespace Internal } // namespace Internal
} // namespace Qt4ProjectManager } // namespace Qt4ProjectManager

View File

@@ -42,10 +42,6 @@
#include <QtCore/QString> #include <QtCore/QString>
QT_BEGIN_NAMESPACE
class QProcess;
QT_END_NAMESPACE
namespace Core { namespace Core {
class SftpChannel; class SftpChannel;
class SshConnection; class SshConnection;
@@ -60,57 +56,43 @@ namespace Debugger {
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
namespace Internal { namespace Internal {
class MaemoRunConfiguration; class MaemoRunConfiguration;
class MaemoSshRunner;
class AbstractMaemoRunControl : public ProjectExplorer::RunControl class AbstractMaemoRunControl : public ProjectExplorer::RunControl
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AbstractMaemoRunControl(ProjectExplorer::RunConfiguration *runConfig, QString mode); explicit AbstractMaemoRunControl(ProjectExplorer::RunConfiguration *runConfig, QString mode);
virtual ~AbstractMaemoRunControl(); virtual ~AbstractMaemoRunControl();
protected: protected:
virtual bool isRunning() const;
virtual void start(); virtual void start();
virtual void stop(); virtual void stop();
void stopRunning(bool forDebugging); void setFinished();
virtual void startExecution();
void handleError(const QString &errString); void handleError(const QString &errString);
const QString executableOnHost() const;
const QString executableFileName() const;
const QString targetCmdLinePrefix() const; const QString targetCmdLinePrefix() const;
QString targetCmdLineSuffix() const; QString arguments() const;
const QString uploadDir() const;
QString executableFilePathOnTarget() const;
private slots: private slots:
void handleConnected(); virtual void startExecution();
void handleConnectionFailure(); void handleSshError(const QString &error);
void handleInitialCleanupFinished(int exitStatus);
virtual void handleRemoteProcessStarted() {} virtual void handleRemoteProcessStarted() {}
void handleRemoteProcessFinished(int exitStatus); void handleRemoteProcessFinished(int exitCode);
void handleRemoteOutput(const QByteArray &output); void handleRemoteOutput(const QByteArray &output);
void handleRemoteErrorOutput(const QByteArray &output); void handleRemoteErrorOutput(const QByteArray &output);
protected: protected:
MaemoRunConfiguration *m_runConfig; // TODO this pointer can be invalid MaemoRunConfiguration *m_runConfig; // TODO this pointer can be invalid
const MaemoDeviceConfig m_devConfig; const MaemoDeviceConfig m_devConfig;
QSharedPointer<Core::SshConnection> m_connection; MaemoSshRunner * const m_runner;
bool m_stopped; bool m_stopped;
private: private:
virtual bool isRunning() const;
virtual void stopInternal()=0; virtual void stopInternal()=0;
virtual QString remoteCall() const=0;
void killRemoteProcesses(const QStringList &apps, bool initialCleanup); bool m_running;
void cancelActions();
template<class SshChannel> void closeSshChannel(SshChannel &channel);
void startExecutionIfPossible();
QSharedPointer<Core::SshRemoteProcess> m_runner;
QSharedPointer<Core::SshRemoteProcess> m_stopper;
QSharedPointer<Core::SshRemoteProcess> m_initialCleaner;
}; };
class MaemoRunControl : public AbstractMaemoRunControl class MaemoRunControl : public AbstractMaemoRunControl
@@ -122,7 +104,6 @@ public:
private: private:
virtual void stopInternal(); virtual void stopInternal();
virtual QString remoteCall() const;
}; };
class MaemoDebugRunControl : public AbstractMaemoRunControl class MaemoDebugRunControl : public AbstractMaemoRunControl
@@ -131,7 +112,6 @@ class MaemoDebugRunControl : public AbstractMaemoRunControl
public: public:
explicit MaemoDebugRunControl(ProjectExplorer::RunConfiguration *runConfiguration); explicit MaemoDebugRunControl(ProjectExplorer::RunConfiguration *runConfiguration);
~MaemoDebugRunControl(); ~MaemoDebugRunControl();
bool isRunning() const;
private slots: private slots:
virtual void handleRemoteProcessStarted(); virtual void handleRemoteProcessStarted();
@@ -144,7 +124,7 @@ private slots:
private: private:
virtual void stopInternal(); virtual void stopInternal();
virtual void startExecution(); virtual void startExecution();
virtual QString remoteCall() const; QString uploadDir() const;
QString gdbServerPort() const; QString gdbServerPort() const;
void startDebugging(); void startDebugging();

View File

@@ -0,0 +1,193 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemosshrunner.h"
#include "maemodeviceconfigurations.h"
#include "maemorunconfiguration.h"
#include <coreplugin/ssh/sshconnection.h>
#include <coreplugin/ssh/sshremoteprocess.h>
#include <QtCore/QFileInfo>
using namespace Core;
namespace Qt4ProjectManager {
namespace Internal {
MaemoSshRunner::MaemoSshRunner(QObject *parent,
MaemoRunConfiguration *runConfig)
: QObject(parent), m_runConfig(runConfig),
m_devConfig(runConfig->deviceConfig())
{
m_procsToKill << QFileInfo(m_runConfig->localExecutableFilePath()).fileName();
}
MaemoSshRunner::~MaemoSshRunner() {}
void MaemoSshRunner::setConnection(const QSharedPointer<Core::SshConnection> &connection)
{
m_connection = connection;
}
void MaemoSshRunner::addProcsToKill(const QStringList &appNames)
{
m_procsToKill << appNames;
}
void MaemoSshRunner::start()
{
m_stop = false;
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
const bool reUse = m_connection
&& m_connection->state() == SshConnection::Connected
&& m_connection->connectionParameters() == m_devConfig.server;
if (!reUse)
m_connection = SshConnection::create();
connect(m_connection.data(), SIGNAL(connected()), this,
SLOT(handleConnected()));
connect(m_connection.data(), SIGNAL(error(SshError)), this,
SLOT(handleConnectionFailure()));
if (reUse)
handleConnected();
else
m_connection->connectToHost(m_devConfig.server);
}
void MaemoSshRunner::stop()
{
m_stop = true;
disconnect(m_connection.data(), 0, this, 0);
if (m_initialCleaner)
disconnect(m_initialCleaner.data(), 0, this, 0);
if (m_runner) {
disconnect(m_runner.data(), 0, this, 0);
m_runner->closeChannel();
killRemoteProcs(false);
}
}
void MaemoSshRunner::handleConnected()
{
if (m_stop)
return;
killRemoteProcs(true);
}
void MaemoSshRunner::handleConnectionFailure()
{
emit error(tr("Could not connect to host: %1")
.arg(m_connection->errorString()));
}
void MaemoSshRunner::killRemoteProcs(bool initialCleanup)
{
QString niceKill;
QString brutalKill;
foreach (const QString &proc, m_procsToKill) {
niceKill += QString::fromLocal8Bit("pkill -x %1;").arg(proc);
brutalKill += QString::fromLocal8Bit("pkill -x -9 %1;").arg(proc);
}
QString remoteCall = niceKill + QLatin1String("sleep 1; ") + brutalKill;
remoteCall.remove(remoteCall.count() - 1, 1); // Get rid of trailing semicolon.
SshRemoteProcess::Ptr proc
= m_connection->createRemoteProcess(remoteCall.toUtf8());
if (initialCleanup) {
m_initialCleaner = proc;
connect(m_initialCleaner.data(), SIGNAL(closed(int)), this,
SLOT(handleInitialCleanupFinished(int)));
}
proc->start();
}
void MaemoSshRunner::handleInitialCleanupFinished(int exitStatus)
{
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (m_stop)
return;
if (exitStatus != SshRemoteProcess::ExitedNormally) {
emit error(tr("Initial cleanup failed: %1")
.arg(m_initialCleaner->errorString()));
} else {
emit readyForExecution();
}
}
void MaemoSshRunner::startExecution(const QByteArray &remoteCall)
{
if (m_runConfig->remoteExecutableFilePath().isEmpty()) {
emit error(tr("Cannot run: No remote executable set."));
return;
}
m_runner = m_connection->createRemoteProcess(remoteCall);
connect(m_runner.data(), SIGNAL(started()), this,
SIGNAL(remoteProcessStarted()));
connect(m_runner.data(), SIGNAL(closed(int)), this,
SLOT(handleRemoteProcessFinished(int)));
connect(m_runner.data(), SIGNAL(outputAvailable(QByteArray)), this,
SIGNAL(remoteOutput(QByteArray)));
connect(m_runner.data(), SIGNAL(errorOutputAvailable(QByteArray)), this,
SIGNAL(remoteErrorOutput(QByteArray)));
m_runner->start();
}
void MaemoSshRunner::handleRemoteProcessFinished(int exitStatus)
{
Q_ASSERT(exitStatus == SshRemoteProcess::FailedToStart
|| exitStatus == SshRemoteProcess::KilledBySignal
|| exitStatus == SshRemoteProcess::ExitedNormally);
if (m_stop)
return;
if (exitStatus == SshRemoteProcess::ExitedNormally) {
emit remoteProcessFinished(m_runner->exitCode());
} else {
emit error(tr("Error running remote process: %1")
.arg(m_runner->errorString()));
}
}
} // namespace Internal
} // namespace Qt4ProjectManager

View File

@@ -0,0 +1,104 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MAEMOSSHRUNNER_H
#define MAEMOSSHRUNNER_H
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include "maemodeviceconfigurations.h"
#include <coreplugin/ssh/sftpdefs.h>
#include <QtCore/QStringList>
namespace Core {
class SftpChannel;
class SshConnection;
class SshRemoteProcess;
}
namespace Qt4ProjectManager {
namespace Internal {
class MaemoRunConfiguration;
class MaemoSshRunner : public QObject
{
Q_OBJECT
public:
MaemoSshRunner(QObject *parent, MaemoRunConfiguration *runConfig);
~MaemoSshRunner();
void setConnection(const QSharedPointer<Core::SshConnection> &connection);
void addProcsToKill(const QStringList &appNames);
void start();
void stop();
void startExecution(const QByteArray &remoteCall);
QSharedPointer<Core::SshConnection> connection() const { return m_connection; }
signals:
void error(const QString &error);
void readyForExecution();
void remoteOutput(const QByteArray &output);
void remoteErrorOutput(const QByteArray &output);
void remoteProcessStarted();
void remoteProcessFinished(int exitCode);
private slots:
void handleConnected();
void handleConnectionFailure();
void handleInitialCleanupFinished(int exitStatus);
void handleRemoteProcessFinished(int exitStatus);
private:
void killRemoteProcs(bool initialCleanup);
MaemoRunConfiguration * const m_runConfig; // TODO this pointer can be invalid
const MaemoDeviceConfig m_devConfig;
QSharedPointer<Core::SshConnection> m_connection;
QSharedPointer<Core::SshRemoteProcess> m_runner;
QSharedPointer<Core::SshRemoteProcess> m_initialCleaner;
QStringList m_procsToKill;
bool m_stop;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // MAEMOSSHRUNNER_H

View File

@@ -23,7 +23,8 @@ HEADERS += \
$$PWD/maemodeploystep.h \ $$PWD/maemodeploystep.h \
$$PWD/maemodeploystepwidget.h \ $$PWD/maemodeploystepwidget.h \
$$PWD/maemodeploystepfactory.h \ $$PWD/maemodeploystepfactory.h \
$$PWD/maemoglobal.h $$PWD/maemoglobal.h \
$$PWD/maemosshrunner.h
SOURCES += \ SOURCES += \
$$PWD/maemoconfigtestdialog.cpp \ $$PWD/maemoconfigtestdialog.cpp \
@@ -48,7 +49,8 @@ SOURCES += \
$$PWD/maemodeploystep.cpp \ $$PWD/maemodeploystep.cpp \
$$PWD/maemodeploystepwidget.cpp \ $$PWD/maemodeploystepwidget.cpp \
$$PWD/maemodeploystepfactory.cpp \ $$PWD/maemodeploystepfactory.cpp \
$$PWD/maemoglobal.cpp $$PWD/maemoglobal.cpp \
$$PWD/maemosshrunner.cpp
FORMS += \ FORMS += \
$$PWD/maemoconfigtestdialog.ui \ $$PWD/maemoconfigtestdialog.ui \