Maemo: Implement remote execution based on SSH library.

Currently deactivated via #ifdef, but has been tested successfully.
This commit is contained in:
ck
2010-01-05 16:42:57 +01:00
parent 469ee5b40c
commit 39c466658a
2 changed files with 64 additions and 5 deletions

View File

@@ -111,6 +111,11 @@ public:
AbstractMaemoRunControl(RunConfiguration *runConfig); AbstractMaemoRunControl(RunConfiguration *runConfig);
virtual ~AbstractMaemoRunControl() {} virtual ~AbstractMaemoRunControl() {}
#ifdef USE_SSH_LIB
protected slots:
void handleRemoteOutput(const QString &output);
#endif
protected: protected:
void startDeployment(bool forDebugging); void startDeployment(bool forDebugging);
void deploy(); void deploy();
@@ -180,8 +185,13 @@ private:
virtual void handleDeploymentFinished(bool success); virtual void handleDeploymentFinished(bool success);
void startExecution(); void startExecution();
#ifdef USE_SSH_LIB
QScopedPointer<MaemoSshRunner> sshRunner;
QScopedPointer<MaemoSshRunner> sshStopper;
#else
QProcess sshProcess; QProcess sshProcess;
QProcess stopProcess; QProcess stopProcess;
#endif // USE_SSH_LIB
bool stoppedByUser; bool stoppedByUser;
}; };
@@ -1248,12 +1258,21 @@ void AbstractMaemoRunControl::readStandardOutput()
} }
// #endif // USE_SSH_LIB // #endif // USE_SSH_LIB
#ifdef USE_SSH_LIB
void AbstractMaemoRunControl::handleRemoteOutput(const QString &output)
{
emit addToOutputWindowInline(this, output);
}
#endif // USE_SSH_LIB
// #pragma mark -- MaemoRunControl // #pragma mark -- MaemoRunControl
MaemoRunControl::MaemoRunControl(RunConfiguration *runConfiguration) MaemoRunControl::MaemoRunControl(RunConfiguration *runConfiguration)
: AbstractMaemoRunControl(runConfiguration) : AbstractMaemoRunControl(runConfiguration)
{ {
#ifndef USE_SSH_LIB
setProcessEnvironment(sshProcess); setProcessEnvironment(sshProcess);
setProcessEnvironment(stopProcess); setProcessEnvironment(stopProcess);
@@ -1265,12 +1284,15 @@ MaemoRunControl::MaemoRunControl(RunConfiguration *runConfiguration)
SLOT(executionFinished())); SLOT(executionFinished()));
connect(&sshProcess, SIGNAL(error(QProcess::ProcessError)), &dumper, connect(&sshProcess, SIGNAL(error(QProcess::ProcessError)), &dumper,
SLOT(printToStream(QProcess::ProcessError))); SLOT(printToStream(QProcess::ProcessError)));
#endif // USE_SSH_LIB
} }
MaemoRunControl::~MaemoRunControl() MaemoRunControl::~MaemoRunControl()
{ {
stop(); stop();
#ifndef USE_SSH_LIB
stopProcess.waitForFinished(5000); stopProcess.waitForFinished(5000);
#endif
} }
void MaemoRunControl::start() void MaemoRunControl::start()
@@ -1289,6 +1311,19 @@ void MaemoRunControl::handleDeploymentFinished(bool success)
void MaemoRunControl::startExecution() void MaemoRunControl::startExecution()
{ {
#ifdef USE_SSH_LIB
const QString remoteCall = QString::fromLocal8Bit("%1 %2 %3")
.arg(targetCmdLinePrefix()).arg(executableOnTarget())
.arg(runConfig->arguments().join(" "));
sshRunner.reset(new MaemoSshRunner(devConfig, remoteCall));
connect(sshRunner.data(), SIGNAL(remoteOutput(QString)),
this, SLOT(handleRemoteOutput(QString)));
connect(sshRunner.data(), SIGNAL(finished()),
this, SLOT(executionFinished()));
emit addToOutputWindow(this, tr("Starting remote application."));
emit started();
sshRunner->start();
#else
const QString remoteCall = QString::fromLocal8Bit("%1 %2 %3") const QString remoteCall = QString::fromLocal8Bit("%1 %2 %3")
.arg(targetCmdLinePrefix()).arg(executableOnTarget()) .arg(targetCmdLinePrefix()).arg(executableOnTarget())
.arg(runConfig->arguments().join(" ")); .arg(runConfig->arguments().join(" "));
@@ -1306,14 +1341,21 @@ void MaemoRunControl::startExecution()
emit error(this, tr("Could not start ssh!")); emit error(this, tr("Could not start ssh!"));
sshProcess.kill(); sshProcess.kill();
} }
#endif // USE_SSH_LIB
} }
void MaemoRunControl::executionFinished() void MaemoRunControl::executionFinished()
{ {
if (stoppedByUser) if (stoppedByUser)
emit addToOutputWindow(this, tr("Remote process stopped by user.")); emit addToOutputWindow(this, tr("Remote process stopped by user."));
#ifdef USE_SSH_LIB
else if (sshRunner->hasError())
emit addToOutputWindow(this, tr("Remote process exited with error: ")
% sshRunner->error());
#else
else if (sshProcess.exitCode() != 0) else if (sshProcess.exitCode() != 0)
emit addToOutputWindow(this, tr("Remote process exited with error.")); emit addToOutputWindow(this, tr("Remote process exited with error."));
#endif // USE_SSH_LIB
else else
emit addToOutputWindow(this, tr("Remote process finished successfully.")); emit addToOutputWindow(this, tr("Remote process finished successfully."));
emit finished(); emit finished();
@@ -1328,6 +1370,12 @@ void MaemoRunControl::stop()
if (isDeploying()) { if (isDeploying()) {
stopDeployment(); stopDeployment();
} else { } else {
#ifdef USE_SSH_LIB
const QString remoteCall = QString::fromLocal8Bit("pkill -x %1; "
"sleep 1; pkill -x -9 %1").arg(executableFileName());
sshStopper.reset(new MaemoSshRunner(devConfig, remoteCall));
sshStopper->start();
#else
stopProcess.kill(); stopProcess.kill();
QStringList cmdArgs; QStringList cmdArgs;
const QString remoteCall = QString::fromLocal8Bit("pkill -x %1; " const QString remoteCall = QString::fromLocal8Bit("pkill -x %1; "
@@ -1335,12 +1383,18 @@ void MaemoRunControl::stop()
cmdArgs << "-n" << "-p" << port() << "-l" << devConfig.uname cmdArgs << "-n" << "-p" << port() << "-l" << devConfig.uname
<< options() << devConfig.host << remoteCall; << options() << devConfig.host << remoteCall;
stopProcess.start(runConfig->sshCmd(), cmdArgs); stopProcess.start(runConfig->sshCmd(), cmdArgs);
#endif // USE_SSH_LIB
} }
} }
bool MaemoRunControl::isRunning() const bool MaemoRunControl::isRunning() const
{ {
return isDeploying() || sshProcess.state() != QProcess::NotRunning; return isDeploying()
#ifdef USE_SSH_LIB
|| (!sshRunner.isNull() && sshRunner->isRunning());
#else
|| sshProcess.state() != QProcess::NotRunning;
#endif // USE_SSH_LIB
} }

View File

@@ -45,13 +45,14 @@
#include "maemodeviceconfigurations.h" #include "maemodeviceconfigurations.h"
#include "/opt/ne7ssh/include/ne7ssh.h" #include "/opt/ne7sshModified/include/ne7ssh.h"
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QStringBuilder> #include <QtCore/QStringBuilder>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <cstdio> #include <cstdio>
#include <cstring>
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
namespace Internal { namespace Internal {
@@ -121,13 +122,17 @@ void MaemoInteractiveSshConnection::runCommand(const QString &command)
bool done; bool done;
do { do {
done = ssh.waitFor(channel(), m_prompt, 2); done = ssh.waitFor(channel(), m_prompt, 1);
const char * const error = lastError(); const char * const error = lastError();
if (error) if (error)
throw MaemoSshException(tr("SSH error: %1").arg(error)); throw MaemoSshException(tr("SSH error: %1").arg(error));
const char * const output = ssh.read(channel()); ssh.lock();
if (output) const char * output = ssh.read(channel(), false);
if (output) {
emit remoteOutput(QLatin1String(output)); emit remoteOutput(QLatin1String(output));
ssh.resetInput(channel(), false);
}
ssh.unlock();
} while (!done && !stopRequested()); } while (!done && !stopRequested());
} }