forked from qt-creator/qt-creator
Maemo: Make SSH connections thread-safe.
This commit is contained in:
@@ -137,7 +137,6 @@ private slots:
|
|||||||
void passwordEditingFinished();
|
void passwordEditingFinished();
|
||||||
void keyFileEditingFinished();
|
void keyFileEditingFinished();
|
||||||
void testConfig();
|
void testConfig();
|
||||||
void enableTestStop();
|
|
||||||
void processSshOutput(const QString &data);
|
void processSshOutput(const QString &data);
|
||||||
void handleSshFinished();
|
void handleSshFinished();
|
||||||
void stopConfigTest();
|
void stopConfigTest();
|
||||||
@@ -397,6 +396,7 @@ void MaemoSettingsWidget::testConfig()
|
|||||||
if (m_deviceTester)
|
if (m_deviceTester)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_ui->testConfigButton->disconnect();
|
||||||
m_ui->testResultEdit->setPlainText(m_defaultTestOutput);
|
m_ui->testResultEdit->setPlainText(m_defaultTestOutput);
|
||||||
QLatin1String sysInfoCmd("uname -rsm");
|
QLatin1String sysInfoCmd("uname -rsm");
|
||||||
QLatin1String qtInfoCmd("dpkg -l |grep libqt "
|
QLatin1String qtInfoCmd("dpkg -l |grep libqt "
|
||||||
@@ -404,22 +404,15 @@ void MaemoSettingsWidget::testConfig()
|
|||||||
"|cut -d ' ' -f 2,3 |sed 's/~.*//g'");
|
"|cut -d ' ' -f 2,3 |sed 's/~.*//g'");
|
||||||
QString command(sysInfoCmd + " && " + qtInfoCmd);
|
QString command(sysInfoCmd + " && " + qtInfoCmd);
|
||||||
m_deviceTester = new MaemoSshRunner(currentConfig(), command);
|
m_deviceTester = new MaemoSshRunner(currentConfig(), command);
|
||||||
connect(m_deviceTester, SIGNAL(connectionEstablished()),
|
|
||||||
this, SLOT(enableTestStop()));
|
|
||||||
connect(m_deviceTester, SIGNAL(remoteOutput(QString)),
|
connect(m_deviceTester, SIGNAL(remoteOutput(QString)),
|
||||||
this, SLOT(processSshOutput(QString)));
|
this, SLOT(processSshOutput(QString)));
|
||||||
connect(m_deviceTester, SIGNAL(finished()),
|
connect(m_deviceTester, SIGNAL(finished()),
|
||||||
this, SLOT(handleSshFinished()));
|
this, SLOT(handleSshFinished()));
|
||||||
m_deviceTester->start();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoSettingsWidget::enableTestStop()
|
|
||||||
{
|
|
||||||
m_ui->testConfigButton->disconnect();
|
|
||||||
m_ui->testConfigButton->setText(tr("Stop test"));
|
m_ui->testConfigButton->setText(tr("Stop test"));
|
||||||
connect(m_ui->testConfigButton, SIGNAL(clicked()),
|
connect(m_ui->testConfigButton, SIGNAL(clicked()),
|
||||||
this, SLOT(stopConfigTest()));
|
this, SLOT(stopConfigTest()));
|
||||||
|
m_deviceTester->start();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoSettingsWidget::processSshOutput(const QString &data)
|
void MaemoSettingsWidget::processSshOutput(const QString &data)
|
||||||
@@ -453,15 +446,14 @@ void MaemoSettingsWidget::stopConfigTest()
|
|||||||
qDebug("================> %s", Q_FUNC_INFO);
|
qDebug("================> %s", Q_FUNC_INFO);
|
||||||
if (m_deviceTester) {
|
if (m_deviceTester) {
|
||||||
qDebug("Actually doing something");
|
qDebug("Actually doing something");
|
||||||
m_deviceTester->disconnect();
|
m_ui->testConfigButton->disconnect();
|
||||||
const bool buttonWasEnabled = m_ui->testConfigButton->isEnabled();
|
const bool buttonWasEnabled = m_ui->testConfigButton->isEnabled();
|
||||||
m_ui->testConfigButton->setEnabled(false);
|
m_deviceTester->disconnect();
|
||||||
m_deviceTester->stop();
|
m_deviceTester->stop();
|
||||||
delete m_deviceTester;
|
delete m_deviceTester;
|
||||||
m_deviceTester = 0;
|
m_deviceTester = 0;
|
||||||
m_deviceTestOutput.clear();
|
m_deviceTestOutput.clear();
|
||||||
m_ui->testConfigButton->setText(tr("Test"));
|
m_ui->testConfigButton->setText(tr("Test"));
|
||||||
m_ui->testConfigButton->disconnect();
|
|
||||||
connect(m_ui->testConfigButton, SIGNAL(clicked()),
|
connect(m_ui->testConfigButton, SIGNAL(clicked()),
|
||||||
this, SLOT(testConfig()));
|
this, SLOT(testConfig()));
|
||||||
m_ui->testConfigButton->setEnabled(buttonWasEnabled);
|
m_ui->testConfigButton->setEnabled(buttonWasEnabled);
|
||||||
|
@@ -47,7 +47,7 @@ namespace Qt4ProjectManager {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
MaemoSshThread::MaemoSshThread(const MaemoDeviceConfig &devConf)
|
MaemoSshThread::MaemoSshThread(const MaemoDeviceConfig &devConf)
|
||||||
: m_devConf(devConf)
|
: m_stopRequested(false), m_devConf(devConf)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,8 @@ MaemoSshThread::~MaemoSshThread()
|
|||||||
void MaemoSshThread::run()
|
void MaemoSshThread::run()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
runInternal();
|
if (!m_stopRequested)
|
||||||
|
runInternal();
|
||||||
} catch (const MaemoSshException &e) {
|
} catch (const MaemoSshException &e) {
|
||||||
m_error = e.error();
|
m_error = e.error();
|
||||||
}
|
}
|
||||||
@@ -68,13 +69,21 @@ void MaemoSshThread::run()
|
|||||||
|
|
||||||
void MaemoSshThread::stop()
|
void MaemoSshThread::stop()
|
||||||
{
|
{
|
||||||
m_connection->stop();
|
m_mutex.lock();
|
||||||
|
m_stopRequested = true;
|
||||||
|
const bool hasConnection = !m_connection.isNull();
|
||||||
|
m_mutex.unlock();
|
||||||
|
if (hasConnection)
|
||||||
|
m_connection->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoSshThread::setConnection(const MaemoSshConnection::Ptr &connection)
|
template <class Conn> typename Conn::Ptr MaemoSshThread::createConnection()
|
||||||
{
|
{
|
||||||
|
typename Conn::Ptr connection = Conn::create(m_devConf);
|
||||||
|
m_mutex.lock();
|
||||||
m_connection = connection;
|
m_connection = connection;
|
||||||
emit connectionEstablished();
|
m_mutex.unlock();
|
||||||
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
MaemoSshRunner::MaemoSshRunner(const MaemoDeviceConfig &devConf,
|
MaemoSshRunner::MaemoSshRunner(const MaemoDeviceConfig &devConf,
|
||||||
@@ -86,8 +95,9 @@ MaemoSshRunner::MaemoSshRunner(const MaemoDeviceConfig &devConf,
|
|||||||
void MaemoSshRunner::runInternal()
|
void MaemoSshRunner::runInternal()
|
||||||
{
|
{
|
||||||
MaemoInteractiveSshConnection::Ptr connection
|
MaemoInteractiveSshConnection::Ptr connection
|
||||||
= MaemoInteractiveSshConnection::create(m_devConf);
|
= createConnection<MaemoInteractiveSshConnection>();
|
||||||
setConnection(connection);
|
if (stopRequested())
|
||||||
|
return;
|
||||||
connect(connection.data(), SIGNAL(remoteOutput(QString)),
|
connect(connection.data(), SIGNAL(remoteOutput(QString)),
|
||||||
this, SIGNAL(remoteOutput(QString)));
|
this, SIGNAL(remoteOutput(QString)));
|
||||||
connection->runCommand(m_command);
|
connection->runCommand(m_command);
|
||||||
@@ -102,8 +112,9 @@ MaemoSshDeployer::MaemoSshDeployer(const MaemoDeviceConfig &devConf,
|
|||||||
void MaemoSshDeployer::runInternal()
|
void MaemoSshDeployer::runInternal()
|
||||||
{
|
{
|
||||||
MaemoSftpConnection::Ptr connection
|
MaemoSftpConnection::Ptr connection
|
||||||
= MaemoSftpConnection::create(m_devConf);
|
= createConnection<MaemoSftpConnection>();
|
||||||
setConnection(connection);
|
if (stopRequested())
|
||||||
|
return;
|
||||||
connect(connection.data(), SIGNAL(fileCopied(QString)),
|
connect(connection.data(), SIGNAL(fileCopied(QString)),
|
||||||
this, SIGNAL(fileCopied(QString)));
|
this, SIGNAL(fileCopied(QString)));
|
||||||
connection->transferFiles(m_filePaths, m_targetDirs);
|
connection->transferFiles(m_filePaths, m_targetDirs);
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
#include "maemodeviceconfigurations.h"
|
#include "maemodeviceconfigurations.h"
|
||||||
#include "maemosshconnection.h"
|
#include "maemosshconnection.h"
|
||||||
|
|
||||||
|
#include <QtCore/QMutex>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
|
||||||
@@ -64,19 +65,18 @@ public:
|
|||||||
virtual void run();
|
virtual void run();
|
||||||
~MaemoSshThread();
|
~MaemoSshThread();
|
||||||
|
|
||||||
signals:
|
|
||||||
void connectionEstablished();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MaemoSshThread(const MaemoDeviceConfig &devConf);
|
MaemoSshThread(const MaemoDeviceConfig &devConf);
|
||||||
virtual void runInternal()=0;
|
template <class Conn> typename Conn::Ptr createConnection();
|
||||||
void setConnection(const MaemoSshConnection::Ptr &connection);
|
bool stopRequested() const { return m_stopRequested; }
|
||||||
|
|
||||||
const MaemoDeviceConfig m_devConf;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void runInternal()=0;
|
||||||
|
|
||||||
|
bool m_stopRequested;
|
||||||
QString m_error;
|
QString m_error;
|
||||||
|
QMutex m_mutex;
|
||||||
|
const MaemoDeviceConfig m_devConf;
|
||||||
MaemoSshConnection::Ptr m_connection;
|
MaemoSshConnection::Ptr m_connection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user