forked from qt-creator/qt-creator
Clean up SshConnectionManager interface
Change-Id: Id1541f83f431171dbdd94d5dd48f93e1c2cdf6fb Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
This commit is contained in:
@@ -113,7 +113,7 @@ SftpFileSystemModel::~SftpFileSystemModel()
|
|||||||
void SftpFileSystemModel::setSshConnection(const SshConnectionParameters &sshParams)
|
void SftpFileSystemModel::setSshConnection(const SshConnectionParameters &sshParams)
|
||||||
{
|
{
|
||||||
QSSH_ASSERT_AND_RETURN(!d->sshConnection);
|
QSSH_ASSERT_AND_RETURN(!d->sshConnection);
|
||||||
d->sshConnection = SshConnectionManager::instance().acquireConnection(sshParams);
|
d->sshConnection = QSsh::acquireConnection(sshParams);
|
||||||
connect(d->sshConnection, SIGNAL(error(QSsh::SshError)), SLOT(handleSshConnectionFailure()));
|
connect(d->sshConnection, SIGNAL(error(QSsh::SshError)), SLOT(handleSshConnectionFailure()));
|
||||||
if (d->sshConnection->state() == SshConnection::Connected) {
|
if (d->sshConnection->state() == SshConnection::Connected) {
|
||||||
handleSshConnectionEstablished();
|
handleSshConnectionEstablished();
|
||||||
@@ -267,7 +267,7 @@ void SftpFileSystemModel::shutDown()
|
|||||||
}
|
}
|
||||||
if (d->sshConnection) {
|
if (d->sshConnection) {
|
||||||
disconnect(d->sshConnection, 0, this, 0);
|
disconnect(d->sshConnection, 0, this, 0);
|
||||||
SshConnectionManager::instance().releaseConnection(d->sshConnection);
|
QSsh::releaseConnection(d->sshConnection);
|
||||||
d->sshConnection = 0;
|
d->sshConnection = 0;
|
||||||
}
|
}
|
||||||
delete d->rootNode;
|
delete d->rootNode;
|
||||||
|
|||||||
@@ -41,25 +41,17 @@
|
|||||||
namespace QSsh {
|
namespace QSsh {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class SshConnectionManagerPrivate : public QObject
|
class SshConnectionManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
SshConnectionManager()
|
||||||
static QMutex instanceMutex;
|
|
||||||
static SshConnectionManager &instance()
|
|
||||||
{
|
|
||||||
static SshConnectionManager manager;
|
|
||||||
return manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
SshConnectionManagerPrivate()
|
|
||||||
{
|
{
|
||||||
moveToThread(QCoreApplication::instance()->thread());
|
moveToThread(QCoreApplication::instance()->thread());
|
||||||
}
|
}
|
||||||
|
|
||||||
~SshConnectionManagerPrivate()
|
~SshConnectionManager()
|
||||||
{
|
{
|
||||||
foreach (SshConnection * const connection, m_unacquiredConnections) {
|
foreach (SshConnection * const connection, m_unacquiredConnections) {
|
||||||
disconnect(connection, 0, this, 0);
|
disconnect(connection, 0, this, 0);
|
||||||
@@ -215,38 +207,32 @@ private:
|
|||||||
QMutex m_listMutex;
|
QMutex m_listMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
QMutex SshConnectionManagerPrivate::instanceMutex;
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
SshConnectionManager &SshConnectionManager::instance()
|
static QMutex instanceMutex;
|
||||||
|
|
||||||
|
static Internal::SshConnectionManager &instance()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&Internal::SshConnectionManagerPrivate::instanceMutex);
|
static Internal::SshConnectionManager manager;
|
||||||
return Internal::SshConnectionManagerPrivate::instance();
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
SshConnectionManager::SshConnectionManager()
|
SshConnection *acquireConnection(const SshConnectionParameters &sshParams)
|
||||||
: d(new Internal::SshConnectionManagerPrivate)
|
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&instanceMutex);
|
||||||
|
return instance().acquireConnection(sshParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
SshConnectionManager::~SshConnectionManager()
|
void releaseConnection(SshConnection *connection)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&instanceMutex);
|
||||||
|
instance().releaseConnection(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
SshConnection *SshConnectionManager::acquireConnection(const SshConnectionParameters &sshParams)
|
void forceNewConnection(const SshConnectionParameters &sshParams)
|
||||||
{
|
{
|
||||||
return d->acquireConnection(sshParams);
|
QMutexLocker locker(&instanceMutex);
|
||||||
}
|
instance().forceNewConnection(sshParams);
|
||||||
|
|
||||||
void SshConnectionManager::releaseConnection(SshConnection *connection)
|
|
||||||
{
|
|
||||||
d->releaseConnection(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshConnectionManager::forceNewConnection(const SshConnectionParameters &sshParams)
|
|
||||||
{
|
|
||||||
d->forceNewConnection(sshParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QSsh
|
} // namespace QSsh
|
||||||
|
|||||||
@@ -32,32 +32,16 @@
|
|||||||
|
|
||||||
#include "ssh_global.h"
|
#include "ssh_global.h"
|
||||||
|
|
||||||
#include <QScopedPointer>
|
|
||||||
|
|
||||||
namespace QSsh {
|
namespace QSsh {
|
||||||
|
|
||||||
class SshConnection;
|
class SshConnection;
|
||||||
class SshConnectionParameters;
|
class SshConnectionParameters;
|
||||||
namespace Internal { class SshConnectionManagerPrivate; }
|
|
||||||
|
|
||||||
class QSSH_EXPORT SshConnectionManager
|
QSSH_EXPORT SshConnection *acquireConnection(const SshConnectionParameters &sshParams);
|
||||||
{
|
QSSH_EXPORT void releaseConnection(SshConnection *connection);
|
||||||
friend class Internal::SshConnectionManagerPrivate;
|
|
||||||
public:
|
|
||||||
static SshConnectionManager &instance();
|
|
||||||
|
|
||||||
SshConnection *acquireConnection(const SshConnectionParameters &sshParams);
|
// Make sure the next acquireConnection with the given parameters will return a new connection.
|
||||||
void releaseConnection(SshConnection *connection);
|
QSSH_EXPORT void forceNewConnection(const SshConnectionParameters &sshParams);
|
||||||
// Make sure the next acquireConnection with the given parameters will return a new connection.
|
|
||||||
void forceNewConnection(const SshConnectionParameters &sshParams);
|
|
||||||
|
|
||||||
private:
|
|
||||||
explicit SshConnectionManager();
|
|
||||||
virtual ~SshConnectionManager();
|
|
||||||
SshConnectionManager(const SshConnectionManager &);
|
|
||||||
SshConnectionManager &operator=(const SshConnectionManager &);
|
|
||||||
|
|
||||||
const QScopedPointer<Internal::SshConnectionManagerPrivate> d;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace QSsh
|
} // namespace QSsh
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ void SshRemoteProcessRunner::runInternal(const QByteArray &command,
|
|||||||
d->m_exitSignal = SshRemoteProcess::NoSignal;
|
d->m_exitSignal = SshRemoteProcess::NoSignal;
|
||||||
d->m_exitCode = -1;
|
d->m_exitCode = -1;
|
||||||
d->m_command = command;
|
d->m_command = command;
|
||||||
d->m_connection = SshConnectionManager::instance().acquireConnection(sshParams);
|
d->m_connection = QSsh::acquireConnection(sshParams);
|
||||||
connect(d->m_connection, SIGNAL(error(QSsh::SshError)),
|
connect(d->m_connection, SIGNAL(error(QSsh::SshError)),
|
||||||
SLOT(handleConnectionError(QSsh::SshError)));
|
SLOT(handleConnectionError(QSsh::SshError)));
|
||||||
connect(d->m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
|
connect(d->m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
|
||||||
@@ -211,7 +211,7 @@ void SshRemoteProcessRunner::setState(int newState)
|
|||||||
}
|
}
|
||||||
if (d->m_connection) {
|
if (d->m_connection) {
|
||||||
disconnect(d->m_connection, 0, this, 0);
|
disconnect(d->m_connection, 0, this, 0);
|
||||||
SshConnectionManager::instance().releaseConnection(d->m_connection);
|
QSsh::releaseConnection(d->m_connection);
|
||||||
d->m_connection = 0;
|
d->m_connection = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ void DeviceApplicationRunner::connectToServer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->connection = SshConnectionManager::instance().acquireConnection(d->device->sshParameters());
|
d->connection = QSsh::acquireConnection(d->device->sshParameters());
|
||||||
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionFailure()));
|
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionFailure()));
|
||||||
if (d->connection->state() == SshConnection::Connected) {
|
if (d->connection->state() == SshConnection::Connected) {
|
||||||
handleConnected();
|
handleConnected();
|
||||||
@@ -212,7 +212,7 @@ void DeviceApplicationRunner::setFinished()
|
|||||||
}
|
}
|
||||||
if (d->connection) {
|
if (d->connection) {
|
||||||
d->connection->disconnect(this);
|
d->connection->disconnect(this);
|
||||||
SshConnectionManager::instance().releaseConnection(d->connection);
|
QSsh::releaseConnection(d->connection);
|
||||||
d->connection = 0;
|
d->connection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ void DeviceUsedPortsGatherer::start(const IDevice::ConstPtr &device)
|
|||||||
QTC_ASSERT(device && device->portsGatheringMethod(), return);
|
QTC_ASSERT(device && device->portsGatheringMethod(), return);
|
||||||
|
|
||||||
d->device = device;
|
d->device = device;
|
||||||
d->connection = SshConnectionManager::instance().acquireConnection(device->sshParameters());
|
d->connection = QSsh::acquireConnection(device->sshParameters());
|
||||||
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
|
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
|
||||||
if (d->connection->state() == SshConnection::Connected) {
|
if (d->connection->state() == SshConnection::Connected) {
|
||||||
handleConnectionEstablished();
|
handleConnectionEstablished();
|
||||||
@@ -108,7 +108,7 @@ void DeviceUsedPortsGatherer::stop()
|
|||||||
disconnect(d->process.data(), 0, this, 0);
|
disconnect(d->process.data(), 0, this, 0);
|
||||||
d->process.clear();
|
d->process.clear();
|
||||||
disconnect(d->connection, 0, this, 0);
|
disconnect(d->connection, 0, this, 0);
|
||||||
SshConnectionManager::instance().releaseConnection(d->connection);
|
QSsh::releaseConnection(d->connection);
|
||||||
d->connection = 0;
|
d->connection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ void SshDeviceProcess::start(const QString &executable, const QStringList &argum
|
|||||||
d->exitCode = -1;
|
d->exitCode = -1;
|
||||||
d->executable = executable;
|
d->executable = executable;
|
||||||
d->arguments = arguments;
|
d->arguments = arguments;
|
||||||
d->connection
|
d->connection = QSsh::acquireConnection(device()->sshParameters());
|
||||||
= QSsh::SshConnectionManager::instance().acquireConnection(device()->sshParameters());
|
|
||||||
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
|
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
|
||||||
connect(d->connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
|
connect(d->connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
|
||||||
if (d->connection->state() == QSsh::SshConnection::Connected) {
|
if (d->connection->state() == QSsh::SshConnection::Connected) {
|
||||||
@@ -321,7 +320,7 @@ void SshDeviceProcess::SshDeviceProcessPrivate::setState(SshDeviceProcess::SshDe
|
|||||||
process->disconnect(q);
|
process->disconnect(q);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
connection->disconnect(q);
|
connection->disconnect(q);
|
||||||
QSsh::SshConnectionManager::instance().releaseConnection(connection);
|
QSsh::releaseConnection(connection);
|
||||||
connection = 0;
|
connection = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ void AbstractRemoteLinuxDeployService::handleDeviceSetupDone(bool success)
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->state = Connecting;
|
d->state = Connecting;
|
||||||
d->connection = SshConnectionManager::instance().acquireConnection(deviceConfiguration()->sshParameters());
|
d->connection = QSsh::acquireConnection(deviceConfiguration()->sshParameters());
|
||||||
connect(d->connection, SIGNAL(error(QSsh::SshError)),
|
connect(d->connection, SIGNAL(error(QSsh::SshError)),
|
||||||
SLOT(handleConnectionFailure()));
|
SLOT(handleConnectionFailure()));
|
||||||
if (d->connection->state() == SshConnection::Connected) {
|
if (d->connection->state() == SshConnection::Connected) {
|
||||||
@@ -328,7 +328,7 @@ void AbstractRemoteLinuxDeployService::setFinished()
|
|||||||
d->state = Inactive;
|
d->state = Inactive;
|
||||||
if (d->connection) {
|
if (d->connection) {
|
||||||
disconnect(d->connection, 0, this, 0);
|
disconnect(d->connection, 0, this, 0);
|
||||||
SshConnectionManager::instance().releaseConnection(d->connection);
|
QSsh::releaseConnection(d->connection);
|
||||||
d->connection = 0;
|
d->connection = 0;
|
||||||
}
|
}
|
||||||
d->stopRequested = false;
|
d->stopRequested = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user