Commit a15fec9b authored by Daniel Teske's avatar Daniel Teske

DeviceAppliactionRunner: Remove unused connection

The whole class can be removed easily now. But I was promised further
refactorings in that area anyway.

Change-Id: I20d200c6acc52604cd2c273f336374ef22626323
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 5bf147d1
...@@ -43,13 +43,12 @@ using namespace QSsh; ...@@ -43,13 +43,12 @@ using namespace QSsh;
namespace ProjectExplorer { namespace ProjectExplorer {
namespace { namespace {
enum State { Inactive, Connecting, Run }; enum State { Inactive, Run };
} // anonymous namespace } // anonymous namespace
class DeviceApplicationRunner::DeviceApplicationRunnerPrivate class DeviceApplicationRunner::DeviceApplicationRunnerPrivate
{ {
public: public:
SshConnection *connection;
DeviceProcess *deviceProcess; DeviceProcess *deviceProcess;
IDevice::ConstPtr device; IDevice::ConstPtr device;
QTimer stopTimer; QTimer stopTimer;
...@@ -66,7 +65,6 @@ public: ...@@ -66,7 +65,6 @@ public:
DeviceApplicationRunner::DeviceApplicationRunner(QObject *parent) : DeviceApplicationRunner::DeviceApplicationRunner(QObject *parent) :
QObject(parent), d(new DeviceApplicationRunnerPrivate) QObject(parent), d(new DeviceApplicationRunnerPrivate)
{ {
d->connection = 0;
d->deviceProcess = 0; d->deviceProcess = 0;
d->state = Inactive; d->state = Inactive;
...@@ -102,7 +100,13 @@ void DeviceApplicationRunner::start(const IDevice::ConstPtr &device, ...@@ -102,7 +100,13 @@ void DeviceApplicationRunner::start(const IDevice::ConstPtr &device,
d->stopRequested = false; d->stopRequested = false;
d->success = true; d->success = true;
connectToServer(); if (!d->device) {
emit reportError(tr("Cannot run: No device."));
setFinished();
return;
}
runApplication();
} }
void DeviceApplicationRunner::stop() void DeviceApplicationRunner::stop()
...@@ -113,9 +117,6 @@ void DeviceApplicationRunner::stop() ...@@ -113,9 +117,6 @@ void DeviceApplicationRunner::stop()
d->success = false; d->success = false;
emit reportProgress(tr("User requested stop. Shutting down...")); emit reportProgress(tr("User requested stop. Shutting down..."));
switch (d->state) { switch (d->state) {
case Connecting:
setFinished();
break;
case Run: case Run:
d->stopTimer.start(10000); d->stopTimer.start(10000);
d->deviceProcess->terminate(); d->deviceProcess->terminate();
...@@ -125,30 +126,6 @@ void DeviceApplicationRunner::stop() ...@@ -125,30 +126,6 @@ void DeviceApplicationRunner::stop()
} }
} }
void DeviceApplicationRunner::connectToServer()
{
QTC_CHECK(!d->connection);
d->state = Connecting;
if (!d->device) {
emit reportError(tr("Cannot run: No device."));
setFinished();
return;
}
d->connection = QSsh::acquireConnection(d->device->sshParameters());
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionFailure()));
if (d->connection->state() == SshConnection::Connected) {
handleConnected();
} else {
emit reportProgress(tr("Connecting to device..."));
connect(d->connection, SIGNAL(connected()), SLOT(handleConnected()));
if (d->connection->state() == QSsh::SshConnection::Unconnected)
d->connection->connectToHost();
}
}
void DeviceApplicationRunner::setFinished() void DeviceApplicationRunner::setFinished()
{ {
if (d->state == Inactive) if (d->state == Inactive)
...@@ -159,48 +136,11 @@ void DeviceApplicationRunner::setFinished() ...@@ -159,48 +136,11 @@ void DeviceApplicationRunner::setFinished()
d->deviceProcess->deleteLater(); d->deviceProcess->deleteLater();
d->deviceProcess = 0; d->deviceProcess = 0;
} }
if (d->connection) {
d->connection->disconnect(this);
QSsh::releaseConnection(d->connection);
d->connection = 0;
}
d->state = Inactive; d->state = Inactive;
emit finished(d->success); emit finished(d->success);
} }
void DeviceApplicationRunner::handleConnected()
{
QTC_ASSERT(d->state == Connecting, return);
if (d->stopRequested) {
setFinished();
return;
}
runApplication();
}
void DeviceApplicationRunner::handleConnectionFailure()
{
QTC_ASSERT(d->state != Inactive, return);
emit reportError(tr("SSH connection failed: %1").arg(d->connection->errorString()));
d->success = false;
switch (d->state) {
case Inactive:
break; // Can't happen.
case Connecting:
setFinished();
break;
case Run:
d->stopTimer.stop();
d->deviceProcess->disconnect(this);
setFinished();
break;
}
}
void DeviceApplicationRunner::handleStopTimeout() void DeviceApplicationRunner::handleStopTimeout()
{ {
QTC_ASSERT(d->stopRequested && d->state == Run, return); QTC_ASSERT(d->stopRequested && d->state == Run, return);
...@@ -244,7 +184,7 @@ void DeviceApplicationRunner::handleRemoteStderr() ...@@ -244,7 +184,7 @@ void DeviceApplicationRunner::handleRemoteStderr()
void DeviceApplicationRunner::runApplication() void DeviceApplicationRunner::runApplication()
{ {
QTC_ASSERT(d->state == Connecting, return); QTC_ASSERT(d->state == Inactive, return);
d->state = Run; d->state = Run;
d->deviceProcess = d->device->createProcess(this); d->deviceProcess = d->device->createProcess(this);
......
...@@ -66,15 +66,12 @@ signals: ...@@ -66,15 +66,12 @@ signals:
void finished(bool success); void finished(bool success);
private slots: private slots:
void handleConnected();
void handleConnectionFailure();
void handleStopTimeout(); void handleStopTimeout();
void handleApplicationFinished(); void handleApplicationFinished();
void handleRemoteStdout(); void handleRemoteStdout();
void handleRemoteStderr(); void handleRemoteStderr();
private: private:
void connectToServer();
void runApplication(); void runApplication();
void setFinished(); void setFinished();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment