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