forked from qt-creator/qt-creator
Maemo: More refactoring in run control classes.
Move more common parts into base class. Reviewed-by: kh1
This commit is contained in:
@@ -71,12 +71,16 @@ AbstractMaemoRunControl::~AbstractMaemoRunControl()
|
|||||||
void AbstractMaemoRunControl::start()
|
void AbstractMaemoRunControl::start()
|
||||||
{
|
{
|
||||||
m_stoppedByUser = false;
|
m_stoppedByUser = false;
|
||||||
|
emit started();
|
||||||
startInternal();
|
startInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractMaemoRunControl::stop()
|
void AbstractMaemoRunControl::stop()
|
||||||
{
|
{
|
||||||
m_stoppedByUser = true;
|
m_stoppedByUser = true;
|
||||||
|
if (isDeploying())
|
||||||
|
stopDeployment();
|
||||||
|
else
|
||||||
stopInternal();
|
stopInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +88,12 @@ void AbstractMaemoRunControl::startDeployment(bool forDebugging)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(m_runConfig, return);
|
QTC_ASSERT(m_runConfig, return);
|
||||||
|
|
||||||
if (m_stoppedByUser) {
|
if (!m_devConfig.isValid()) {
|
||||||
handleDeploymentFinished(false);
|
handleError(tr("No device configuration set for run configuration."));
|
||||||
} else if (m_devConfig.isValid()) {
|
emit finished();
|
||||||
|
} else if (m_stoppedByUser) {
|
||||||
|
emit finished();
|
||||||
|
} else {
|
||||||
m_deployables.clear();
|
m_deployables.clear();
|
||||||
if (m_runConfig->currentlyNeedsDeployment(m_devConfig.host)) {
|
if (m_runConfig->currentlyNeedsDeployment(m_devConfig.host)) {
|
||||||
m_deployables.append(Deployable(executableFileName(),
|
m_deployables.append(Deployable(executableFileName(),
|
||||||
@@ -101,13 +108,9 @@ void AbstractMaemoRunControl::startDeployment(bool forDebugging)
|
|||||||
}
|
}
|
||||||
|
|
||||||
deploy();
|
deploy();
|
||||||
} else {
|
|
||||||
handleError(tr("No device configuration set for run configuration."));
|
|
||||||
handleDeploymentFinished(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractMaemoRunControl::deploy()
|
void AbstractMaemoRunControl::deploy()
|
||||||
{
|
{
|
||||||
Core::ICore::instance()->progressManager()
|
Core::ICore::instance()->progressManager()
|
||||||
@@ -127,17 +130,16 @@ void AbstractMaemoRunControl::deploy()
|
|||||||
emit addToOutputWindow(this, tr("Files to deploy: %1.").arg(files.join(" ")));
|
emit addToOutputWindow(this, tr("Files to deploy: %1.").arg(files.join(" ")));
|
||||||
m_sshDeployer.reset(new MaemoSshDeployer(m_devConfig, deploySpecs));
|
m_sshDeployer.reset(new MaemoSshDeployer(m_devConfig, deploySpecs));
|
||||||
connect(m_sshDeployer.data(), SIGNAL(finished()),
|
connect(m_sshDeployer.data(), SIGNAL(finished()),
|
||||||
this, SLOT(deployThreadFinished()));
|
this, SLOT(handleDeployThreadFinished()));
|
||||||
connect(m_sshDeployer.data(), SIGNAL(fileCopied(QString)),
|
connect(m_sshDeployer.data(), SIGNAL(fileCopied(QString)),
|
||||||
this, SLOT(handleFileCopied()));
|
this, SLOT(handleFileCopied()));
|
||||||
m_progress.setProgressRange(0, m_deployables.count());
|
m_progress.setProgressRange(0, m_deployables.count());
|
||||||
m_progress.setProgressValue(0);
|
m_progress.setProgressValue(0);
|
||||||
m_progress.reportStarted();
|
m_progress.reportStarted();
|
||||||
emit started();
|
|
||||||
m_sshDeployer->start();
|
m_sshDeployer->start();
|
||||||
} else {
|
} else {
|
||||||
m_progress.reportFinished();
|
m_progress.reportFinished();
|
||||||
handleDeploymentFinished(true);
|
startExecution();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,10 +160,14 @@ bool AbstractMaemoRunControl::isDeploying() const
|
|||||||
return m_sshDeployer && m_sshDeployer->isRunning();
|
return m_sshDeployer && m_sshDeployer->isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractMaemoRunControl::run(const QString &remoteCall)
|
void AbstractMaemoRunControl::startExecution()
|
||||||
{
|
{
|
||||||
m_sshRunner.reset(new MaemoSshRunner(m_devConfig, remoteCall));
|
m_sshRunner.reset(new MaemoSshRunner(m_devConfig, remoteCall()));
|
||||||
handleExecutionAboutToStart(m_sshRunner.data());
|
connect(m_sshRunner.data(), SIGNAL(finished()),
|
||||||
|
this, SLOT(handleRunThreadFinished()));
|
||||||
|
connect(m_sshRunner.data(), SIGNAL(remoteOutput(QString)),
|
||||||
|
this, SLOT(handleRemoteOutput(QString)));
|
||||||
|
emit addToOutputWindow(this, tr("Starting remote application."));
|
||||||
m_sshRunner->start();
|
m_sshRunner->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,20 +201,42 @@ void AbstractMaemoRunControl::kill(const QStringList &apps)
|
|||||||
m_sshStopper->start();
|
m_sshStopper->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractMaemoRunControl::deployThreadFinished()
|
void AbstractMaemoRunControl::handleDeployThreadFinished()
|
||||||
{
|
{
|
||||||
const bool success = !m_sshDeployer->hasError();
|
bool cancel;
|
||||||
if (m_stoppedByUser) {
|
if (m_stoppedByUser) {
|
||||||
emit addToOutputWindow(this, tr("Deployment canceled by user."));
|
emit addToOutputWindow(this, tr("Deployment canceled by user."));
|
||||||
m_progress.reportCanceled();
|
cancel = true;
|
||||||
} else if (success) {
|
} else if (m_sshDeployer->hasError()) {
|
||||||
emit addToOutputWindow(this, tr("Deployment finished."));
|
|
||||||
} else {
|
|
||||||
handleError(tr("Deployment failed: %1").arg(m_sshDeployer->error()));
|
handleError(tr("Deployment failed: %1").arg(m_sshDeployer->error()));
|
||||||
m_progress.reportCanceled();
|
cancel = true;
|
||||||
|
} else {
|
||||||
|
emit addToOutputWindow(this, tr("Deployment finished."));
|
||||||
|
cancel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cancel) {
|
||||||
|
m_progress.reportCanceled();
|
||||||
m_progress.reportFinished();
|
m_progress.reportFinished();
|
||||||
handleDeploymentFinished(success && !m_stoppedByUser);
|
emit finished();
|
||||||
|
} else {
|
||||||
|
m_progress.reportFinished();
|
||||||
|
startExecution();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractMaemoRunControl::handleRunThreadFinished()
|
||||||
|
{
|
||||||
|
if (m_stoppedByUser) {
|
||||||
|
emit addToOutputWindow(this,
|
||||||
|
tr("Remote execution canceled due to user request."));
|
||||||
|
} else if (m_sshRunner->hasError()) {
|
||||||
|
emit addToOutputWindow(this, tr("Remote process exited with error: %1")
|
||||||
|
.arg(m_sshRunner->error()));
|
||||||
|
} else {
|
||||||
|
emit addToOutputWindow(this, tr("Remote process finished successfully."));
|
||||||
|
}
|
||||||
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString AbstractMaemoRunControl::executableOnHost() const
|
const QString AbstractMaemoRunControl::executableOnHost() const
|
||||||
@@ -286,55 +314,16 @@ void MaemoRunControl::startInternal()
|
|||||||
startDeployment(false);
|
startDeployment(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoRunControl::handleDeploymentFinished(bool success)
|
QString MaemoRunControl::remoteCall() const
|
||||||
{
|
{
|
||||||
if (success)
|
return QString::fromLocal8Bit("%1 %2 %3")
|
||||||
startExecution();
|
|
||||||
else
|
|
||||||
emit finished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoRunControl::handleExecutionAboutToStart(const MaemoSshRunner *runner)
|
|
||||||
{
|
|
||||||
connect(runner, SIGNAL(remoteOutput(QString)),
|
|
||||||
this, SLOT(handleRemoteOutput(QString)));
|
|
||||||
connect(runner, SIGNAL(finished()),
|
|
||||||
this, SLOT(executionFinished()));
|
|
||||||
emit addToOutputWindow(this, tr("Starting remote application."));
|
|
||||||
emit started();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoRunControl::startExecution()
|
|
||||||
{
|
|
||||||
const QString remoteCall = QString::fromLocal8Bit("%1 %2 %3")
|
|
||||||
.arg(targetCmdLinePrefix()).arg(executableOnTarget())
|
.arg(targetCmdLinePrefix()).arg(executableOnTarget())
|
||||||
.arg(m_runConfig->arguments().join(" "));
|
.arg(m_runConfig->arguments().join(" "));
|
||||||
run(remoteCall);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoRunControl::executionFinished()
|
|
||||||
{
|
|
||||||
MaemoSshRunner *runner = static_cast<MaemoSshRunner *>(sender());
|
|
||||||
if (m_stoppedByUser) {
|
|
||||||
emit addToOutputWindow(this, tr("Remote process stopped by user."));
|
|
||||||
} else if (runner->hasError()) {
|
|
||||||
emit addToOutputWindow(this, tr("Remote process exited with error: %1")
|
|
||||||
.arg(runner->error()));
|
|
||||||
} else {
|
|
||||||
emit addToOutputWindow(this, tr("Remote process finished successfully."));
|
|
||||||
}
|
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoRunControl::stopInternal()
|
void MaemoRunControl::stopInternal()
|
||||||
{
|
{
|
||||||
if (!isRunning())
|
|
||||||
return;
|
|
||||||
if (isDeploying()) {
|
|
||||||
stopDeployment();
|
|
||||||
} else {
|
|
||||||
AbstractMaemoRunControl::stopRunning(false);
|
AbstractMaemoRunControl::stopRunning(false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoRunControl::handleRemoteOutput(const QString &output)
|
void MaemoRunControl::handleRemoteOutput(const QString &output)
|
||||||
@@ -378,41 +367,18 @@ MaemoDebugRunControl::~MaemoDebugRunControl()
|
|||||||
|
|
||||||
void MaemoDebugRunControl::startInternal()
|
void MaemoDebugRunControl::startInternal()
|
||||||
{
|
{
|
||||||
|
m_inferiorPid = -1;
|
||||||
startDeployment(true);
|
startDeployment(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDebugRunControl::handleDeploymentFinished(bool success)
|
QString MaemoDebugRunControl::remoteCall() const
|
||||||
{
|
{
|
||||||
if (success) {
|
return QString::fromLocal8Bit("%1 gdbserver :%2 %3 %4")
|
||||||
startGdbServer();
|
.arg(targetCmdLinePrefix()).arg(gdbServerPort())
|
||||||
} else {
|
.arg(executableOnTarget()).arg(m_runConfig->arguments().join(" "));
|
||||||
emit finished();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDebugRunControl::handleExecutionAboutToStart(const MaemoSshRunner *runner)
|
void MaemoDebugRunControl::handleRemoteOutput(const QString &output)
|
||||||
{
|
|
||||||
m_inferiorPid = -1;
|
|
||||||
connect(runner, SIGNAL(remoteOutput(QString)),
|
|
||||||
this, SLOT(gdbServerStarted(QString)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoDebugRunControl::startGdbServer()
|
|
||||||
{
|
|
||||||
const QString remoteCall(QString::fromLocal8Bit("%1 gdbserver :%2 %3 %4").
|
|
||||||
arg(targetCmdLinePrefix()).arg(gdbServerPort())
|
|
||||||
.arg(executableOnTarget()).arg(m_runConfig->arguments().join(" ")));
|
|
||||||
run(remoteCall);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoDebugRunControl::gdbServerStartFailed(const QString &reason)
|
|
||||||
{
|
|
||||||
handleError(tr("Debugging failed: %1").arg(reason));
|
|
||||||
m_debuggerManager->exitDebugger();
|
|
||||||
emit finished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoDebugRunControl::gdbServerStarted(const QString &output)
|
|
||||||
{
|
{
|
||||||
qDebug("gdbserver's stderr output: %s", output.toLatin1().data());
|
qDebug("gdbserver's stderr output: %s", output.toLatin1().data());
|
||||||
if (m_inferiorPid != -1)
|
if (m_inferiorPid != -1)
|
||||||
@@ -429,14 +395,12 @@ void MaemoDebugRunControl::gdbServerStarted(const QString &output)
|
|||||||
bool ok;
|
bool ok;
|
||||||
const int pid = pidString.toInt(&ok);
|
const int pid = pidString.toInt(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
gdbServerStartFailed(tr("Debugging failed, could not parse gdb "
|
handleError(tr("Debugging failed: Could not parse gdbserver output."));
|
||||||
"server pid!"));
|
m_debuggerManager->exitDebugger();
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
m_inferiorPid = pid;
|
m_inferiorPid = pid;
|
||||||
qDebug("inferiorPid = %d", m_inferiorPid);
|
|
||||||
|
|
||||||
startDebugging();
|
startDebugging();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDebugRunControl::startDebugging()
|
void MaemoDebugRunControl::startDebugging()
|
||||||
@@ -446,14 +410,7 @@ void MaemoDebugRunControl::startDebugging()
|
|||||||
|
|
||||||
void MaemoDebugRunControl::stopInternal()
|
void MaemoDebugRunControl::stopInternal()
|
||||||
{
|
{
|
||||||
if (!isRunning())
|
|
||||||
return;
|
|
||||||
emit addToOutputWindow(this, tr("Stopping debugging operation ..."));
|
|
||||||
if (isDeploying()) {
|
|
||||||
stopDeployment();
|
|
||||||
} else {
|
|
||||||
m_debuggerManager->exitDebugger();
|
m_debuggerManager->exitDebugger();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaemoDebugRunControl::isRunning() const
|
bool MaemoDebugRunControl::isRunning() const
|
||||||
@@ -465,8 +422,6 @@ bool MaemoDebugRunControl::isRunning() const
|
|||||||
void MaemoDebugRunControl::debuggingFinished()
|
void MaemoDebugRunControl::debuggingFinished()
|
||||||
{
|
{
|
||||||
AbstractMaemoRunControl::stopRunning(true);
|
AbstractMaemoRunControl::stopRunning(true);
|
||||||
emit addToOutputWindow(this, tr("Debugging finished."));
|
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoDebugRunControl::debuggerOutput(const QString &output)
|
void MaemoDebugRunControl::debuggerOutput(const QString &output)
|
||||||
|
|||||||
@@ -75,9 +75,8 @@ protected:
|
|||||||
void deploy();
|
void deploy();
|
||||||
void stopDeployment();
|
void stopDeployment();
|
||||||
void stopRunning(bool forDebugging);
|
void stopRunning(bool forDebugging);
|
||||||
void run(const QString &remoteCall);
|
void startExecution();
|
||||||
void handleError(const QString &errString);
|
void handleError(const QString &errString);
|
||||||
bool isDeploying() const;
|
|
||||||
const QString executableOnHost() const;
|
const QString executableOnHost() const;
|
||||||
const QString executableOnTarget() const;
|
const QString executableOnTarget() const;
|
||||||
const QString executableFileName() const;
|
const QString executableFileName() const;
|
||||||
@@ -86,25 +85,27 @@ protected:
|
|||||||
const QString remoteDir() const;
|
const QString remoteDir() const;
|
||||||
const QStringList options() const;
|
const QStringList options() const;
|
||||||
private slots:
|
private slots:
|
||||||
void deployThreadFinished();
|
virtual void handleRemoteOutput(const QString &output)=0;
|
||||||
|
void handleDeployThreadFinished();
|
||||||
|
void handleRunThreadFinished();
|
||||||
void handleFileCopied();
|
void handleFileCopied();
|
||||||
|
|
||||||
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;
|
||||||
bool m_stoppedByUser;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void startInternal()=0;
|
virtual void startInternal()=0;
|
||||||
virtual void stopInternal()=0;
|
virtual void stopInternal()=0;
|
||||||
virtual void handleDeploymentFinished(bool success)=0;
|
virtual QString remoteCall() const=0;
|
||||||
virtual void handleExecutionAboutToStart(const MaemoSshRunner *runner)=0;
|
|
||||||
void kill(const QStringList &apps);
|
void kill(const QStringList &apps);
|
||||||
|
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;
|
||||||
|
bool m_stoppedByUser;
|
||||||
|
|
||||||
struct Deployable
|
struct Deployable
|
||||||
{
|
{
|
||||||
@@ -125,16 +126,11 @@ public:
|
|||||||
explicit MaemoRunControl(ProjectExplorer::RunConfiguration *runConfiguration);
|
explicit MaemoRunControl(ProjectExplorer::RunConfiguration *runConfiguration);
|
||||||
~MaemoRunControl();
|
~MaemoRunControl();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void executionFinished();
|
|
||||||
void handleRemoteOutput(const QString &output);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void startInternal();
|
virtual void startInternal();
|
||||||
virtual void stopInternal();
|
virtual void stopInternal();
|
||||||
virtual void handleDeploymentFinished(bool success);
|
virtual void handleRemoteOutput(const QString &output);
|
||||||
virtual void handleExecutionAboutToStart(const MaemoSshRunner *runner);
|
virtual QString remoteCall() const;
|
||||||
void startExecution();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MaemoDebugRunControl : public AbstractMaemoRunControl
|
class MaemoDebugRunControl : public AbstractMaemoRunControl
|
||||||
@@ -146,19 +142,16 @@ public:
|
|||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void gdbServerStarted(const QString &output);
|
|
||||||
void debuggerOutput(const QString &output);
|
void debuggerOutput(const QString &output);
|
||||||
void debuggingFinished();
|
void debuggingFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void startInternal();
|
virtual void startInternal();
|
||||||
virtual void stopInternal();
|
virtual void stopInternal();
|
||||||
virtual void handleDeploymentFinished(bool success);
|
virtual void handleRemoteOutput(const QString &output);
|
||||||
virtual void handleExecutionAboutToStart(const MaemoSshRunner *runner);
|
virtual QString remoteCall() const;
|
||||||
|
|
||||||
QString gdbServerPort() const;
|
QString gdbServerPort() const;
|
||||||
void startGdbServer();
|
|
||||||
void gdbServerStartFailed(const QString &reason);
|
|
||||||
void startDebugging();
|
void startDebugging();
|
||||||
|
|
||||||
Debugger::DebuggerManager *m_debuggerManager;
|
Debugger::DebuggerManager *m_debuggerManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user