summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2013-09-10 18:52:17 +0200
committerhjk <hjk121@nokiamail.com>2013-09-11 15:08:27 +0200
commit122b7344d95f594a601974727bfbf27b3e61b6a1 (patch)
treed7157caaff96ae79491a384d42a2ec9294b8c338
parent8336a1b7ecb111f87d2478b790c9946a9ad0f76d (diff)
downloadqt-creator-122b7344d95f594a601974727bfbf27b3e61b6a1.tar.gz
Clean up SshConnectionManager interface
Change-Id: Id1541f83f431171dbdd94d5dd48f93e1c2cdf6fb Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
-rw-r--r--src/libs/ssh/sftpfilesystemmodel.cpp4
-rw-r--r--src/libs/ssh/sshconnectionmanager.cpp46
-rw-r--r--src/libs/ssh/sshconnectionmanager.h26
-rw-r--r--src/libs/ssh/sshremoteprocessrunner.cpp4
-rw-r--r--src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp4
-rw-r--r--src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp4
-rw-r--r--src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp5
-rw-r--r--src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp4
8 files changed, 33 insertions, 64 deletions
diff --git a/src/libs/ssh/sftpfilesystemmodel.cpp b/src/libs/ssh/sftpfilesystemmodel.cpp
index 1f79a2b99a..d4f7ead25f 100644
--- a/src/libs/ssh/sftpfilesystemmodel.cpp
+++ b/src/libs/ssh/sftpfilesystemmodel.cpp
@@ -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;
diff --git a/src/libs/ssh/sshconnectionmanager.cpp b/src/libs/ssh/sshconnectionmanager.cpp
index 0abde1d521..9431982898 100644
--- a/src/libs/ssh/sshconnectionmanager.cpp
+++ b/src/libs/ssh/sshconnectionmanager.cpp
@@ -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()
-{
- QMutexLocker locker(&Internal::SshConnectionManagerPrivate::instanceMutex);
- return Internal::SshConnectionManagerPrivate::instance();
-}
-
-SshConnectionManager::SshConnectionManager()
- : d(new Internal::SshConnectionManagerPrivate)
-{
-}
+static QMutex instanceMutex;
-SshConnectionManager::~SshConnectionManager()
+static Internal::SshConnectionManager &instance()
{
+ static Internal::SshConnectionManager manager;
+ return manager;
}
-SshConnection *SshConnectionManager::acquireConnection(const SshConnectionParameters &sshParams)
+SshConnection *acquireConnection(const SshConnectionParameters &sshParams)
{
- return d->acquireConnection(sshParams);
+ QMutexLocker locker(&instanceMutex);
+ return instance().acquireConnection(sshParams);
}
-void SshConnectionManager::releaseConnection(SshConnection *connection)
+void releaseConnection(SshConnection *connection)
{
- d->releaseConnection(connection);
+ QMutexLocker locker(&instanceMutex);
+ instance().releaseConnection(connection);
}
-void SshConnectionManager::forceNewConnection(const SshConnectionParameters &sshParams)
+void forceNewConnection(const SshConnectionParameters &sshParams)
{
- d->forceNewConnection(sshParams);
+ QMutexLocker locker(&instanceMutex);
+ instance().forceNewConnection(sshParams);
}
} // namespace QSsh
diff --git a/src/libs/ssh/sshconnectionmanager.h b/src/libs/ssh/sshconnectionmanager.h
index a38e4c7ba8..65dab048a4 100644
--- a/src/libs/ssh/sshconnectionmanager.h
+++ b/src/libs/ssh/sshconnectionmanager.h
@@ -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();
-
- 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 &);
+QSSH_EXPORT SshConnection *acquireConnection(const SshConnectionParameters &sshParams);
+QSSH_EXPORT void releaseConnection(SshConnection *connection);
- 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
diff --git a/src/libs/ssh/sshremoteprocessrunner.cpp b/src/libs/ssh/sshremoteprocessrunner.cpp
index 159f5e9f77..8714502c25 100644
--- a/src/libs/ssh/sshremoteprocessrunner.cpp
+++ b/src/libs/ssh/sshremoteprocessrunner.cpp
@@ -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;
}
}
diff --git a/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp b/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp
index deda2ebb2e..11ee968e46 100644
--- a/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp
+++ b/src/plugins/projectexplorer/devicesupport/deviceapplicationrunner.cpp
@@ -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;
}
diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp
index 73b4b83941..2e89492e5f 100644
--- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp
+++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp
@@ -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;
}
diff --git a/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp b/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
index 7703c3edcd..ae9e661489 100644
--- a/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
+++ b/src/plugins/projectexplorer/devicesupport/sshdeviceprocess.cpp
@@ -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;
}
}
diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp
index 0cd603b625..8c916a311b 100644
--- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp
+++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp
@@ -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;