Maemo: Kill old instances before deploying the application.

Reviewed-by: kh1
This commit is contained in:
ck
2010-04-13 16:30:52 +02:00
parent 44ce228a6a
commit 18a134ec37
2 changed files with 48 additions and 14 deletions

View File

@@ -72,18 +72,43 @@ void AbstractMaemoRunControl::start()
{ {
m_stoppedByUser = false; m_stoppedByUser = false;
emit started(); emit started();
startInternal(); startInitialCleanup();
}
void AbstractMaemoRunControl::startInitialCleanup()
{
emit addToOutputWindow(this, tr("Cleaning up remote leftovers first ..."));
const QStringList appsToKill
= QStringList() << executableFileName() << QLatin1String("gdbserver");
killRemoteProcesses(appsToKill, true);
} }
void AbstractMaemoRunControl::stop() void AbstractMaemoRunControl::stop()
{ {
m_stoppedByUser = true; m_stoppedByUser = true;
if (isDeploying()) if (isCleaning())
stopDeployment(); m_initialCleaner->stop();
else if (isDeploying())
m_sshDeployer->stop();
else else
stopInternal(); stopInternal();
} }
void AbstractMaemoRunControl::handleInitialCleanupFinished()
{
if (m_stoppedByUser) {
emit addToOutputWindow(this, tr("Initial cleanup canceled by user."));
emit finished();
} else if (m_initialCleaner->hasError()) {
handleError(tr("Error running initial cleanup: %1.")
.arg(m_initialCleaner->error()));
emit finished();
} else {
emit addToOutputWindow(this, tr("Initial cleanup done."));
startInternal();
}
}
void AbstractMaemoRunControl::startDeployment(bool forDebugging) void AbstractMaemoRunControl::startDeployment(bool forDebugging)
{ {
QTC_ASSERT(m_runConfig, return); QTC_ASSERT(m_runConfig, return);
@@ -150,16 +175,16 @@ void AbstractMaemoRunControl::handleFileCopied()
m_progress.setProgressValue(m_progress.progressValue() + 1); m_progress.setProgressValue(m_progress.progressValue() + 1);
} }
void AbstractMaemoRunControl::stopDeployment()
{
m_sshDeployer->stop();
}
bool AbstractMaemoRunControl::isDeploying() const bool AbstractMaemoRunControl::isDeploying() const
{ {
return m_sshDeployer && m_sshDeployer->isRunning(); return m_sshDeployer && m_sshDeployer->isRunning();
} }
bool AbstractMaemoRunControl::isCleaning() const
{
return m_initialCleaner && m_initialCleaner->isRunning();
}
void AbstractMaemoRunControl::startExecution() void AbstractMaemoRunControl::startExecution()
{ {
m_sshRunner.reset(new MaemoSshRunner(m_devConfig, remoteCall())); m_sshRunner.reset(new MaemoSshRunner(m_devConfig, remoteCall()));
@@ -183,11 +208,12 @@ void AbstractMaemoRunControl::stopRunning(bool forDebugging)
QStringList apps(executableFileName()); QStringList apps(executableFileName());
if (forDebugging) if (forDebugging)
apps << QLatin1String("gdbserver"); apps << QLatin1String("gdbserver");
kill(apps); killRemoteProcesses(apps, false);
} }
} }
void AbstractMaemoRunControl::kill(const QStringList &apps) void AbstractMaemoRunControl::killRemoteProcesses(const QStringList &apps,
bool initialCleanup)
{ {
QString niceKill; QString niceKill;
QString brutalKill; QString brutalKill;
@@ -197,8 +223,13 @@ void AbstractMaemoRunControl::kill(const QStringList &apps)
} }
const QString remoteCall const QString remoteCall
= niceKill + QLatin1String("sleep 1; ") + brutalKill; = niceKill + QLatin1String("sleep 1; ") + brutalKill;
m_sshStopper.reset(new MaemoSshRunner(m_devConfig, remoteCall)); QScopedPointer<MaemoSshRunner> &runner
m_sshStopper->start(); = initialCleanup ? m_initialCleaner : m_sshStopper;
runner.reset(new MaemoSshRunner(m_devConfig, remoteCall));
if (initialCleanup)
connect(runner.data(), SIGNAL(finished()),
this, SLOT(handleInitialCleanupFinished()));
runner->start();
} }
void AbstractMaemoRunControl::handleDeployThreadFinished() void AbstractMaemoRunControl::handleDeployThreadFinished()

View File

@@ -73,7 +73,6 @@ protected:
void startDeployment(bool forDebugging); void startDeployment(bool forDebugging);
void deploy(); void deploy();
void stopDeployment();
void stopRunning(bool forDebugging); void stopRunning(bool forDebugging);
void startExecution(); void startExecution();
void handleError(const QString &errString); void handleError(const QString &errString);
@@ -86,6 +85,7 @@ protected:
const QStringList options() const; const QStringList options() const;
private slots: private slots:
virtual void handleRemoteOutput(const QString &output)=0; virtual void handleRemoteOutput(const QString &output)=0;
void handleInitialCleanupFinished();
void handleDeployThreadFinished(); void handleDeployThreadFinished();
void handleRunThreadFinished(); void handleRunThreadFinished();
void handleFileCopied(); void handleFileCopied();
@@ -98,13 +98,16 @@ private:
virtual void startInternal()=0; virtual void startInternal()=0;
virtual void stopInternal()=0; virtual void stopInternal()=0;
virtual QString remoteCall() const=0; virtual QString remoteCall() const=0;
void kill(const QStringList &apps); void startInitialCleanup();
void killRemoteProcesses(const QStringList &apps, bool initialCleanup);
bool isCleaning() const;
bool isDeploying() const; bool isDeploying() const;
QFutureInterface<void> m_progress; QFutureInterface<void> m_progress;
QScopedPointer<MaemoSshDeployer> m_sshDeployer; QScopedPointer<MaemoSshDeployer> m_sshDeployer;
QScopedPointer<MaemoSshRunner> m_sshRunner; QScopedPointer<MaemoSshRunner> m_sshRunner;
QScopedPointer<MaemoSshRunner> m_sshStopper; QScopedPointer<MaemoSshRunner> m_sshStopper;
QScopedPointer<MaemoSshRunner> m_initialCleaner;
bool m_stoppedByUser; bool m_stoppedByUser;
struct Deployable struct Deployable