SSH: Use plain pointers to SshConnection objects.

It used to be shared pointers so that existing connection objects could
easily be passed around in order not to open a new connection to the same
server. Since the introduction of the SshConnectionManager, this
is no longer necessary.

Change-Id: I13fd3eceaf35d562e6260e9969abbffb01edd6b5
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Christian Kandeler
2012-05-29 13:22:33 +02:00
parent 6886dcb787
commit 94ab29519b
34 changed files with 198 additions and 177 deletions

View File

@@ -86,7 +86,7 @@ SftpDirNode *indexToDirNode(const QModelIndex &index)
class SftpFileSystemModelPrivate
{
public:
SshConnection::Ptr sshConnection;
SshConnection *sshConnection;
SftpChannel::Ptr sftpChannel;
QString rootDirectory;
SftpFileNode *rootNode;
@@ -101,6 +101,7 @@ using namespace Internal;
SftpFileSystemModel::SftpFileSystemModel(QObject *parent)
: QAbstractItemModel(parent), d(new SftpFileSystemModelPrivate)
{
d->sshConnection = 0;
d->rootDirectory = QLatin1String("/");
d->rootNode = 0;
d->statJobId = SftpInvalidJob;
@@ -116,13 +117,12 @@ void SftpFileSystemModel::setSshConnection(const SshConnectionParameters &sshPar
{
QSSH_ASSERT_AND_RETURN(!d->sshConnection);
d->sshConnection = SshConnectionManager::instance().acquireConnection(sshParams);
connect(d->sshConnection.data(), SIGNAL(error(QSsh::SshError)),
SLOT(handleSshConnectionFailure()));
connect(d->sshConnection, SIGNAL(error(QSsh::SshError)), SLOT(handleSshConnectionFailure()));
if (d->sshConnection->state() == SshConnection::Connected) {
handleSshConnectionEstablished();
return;
}
connect(d->sshConnection.data(), SIGNAL(connected()), SLOT(handleSshConnectionEstablished()));
connect(d->sshConnection, SIGNAL(connected()), SLOT(handleSshConnectionEstablished()));
if (d->sshConnection->state() == SshConnection::Unconnected)
d->sshConnection->connectToHost();
}
@@ -269,9 +269,9 @@ void SftpFileSystemModel::shutDown()
d->sftpChannel.clear();
}
if (d->sshConnection) {
disconnect(d->sshConnection.data(), 0, this, 0);
disconnect(d->sshConnection, 0, this, 0);
SshConnectionManager::instance().releaseConnection(d->sshConnection);
d->sshConnection.clear();
d->sshConnection = 0;
}
delete d->rootNode;
d->rootNode = 0;

View File

@@ -107,12 +107,6 @@ bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters
// TODO: Mechanism for checking the host key. First connection to host: save, later: compare
SshConnection::Ptr SshConnection::create(const SshConnectionParameters &serverInfo)
{
doStaticInitializationsIfNecessary();
return Ptr(new SshConnection(serverInfo));
}
SshConnection::SshConnection(const SshConnectionParameters &serverInfo)
: d(new Internal::SshConnectionPrivate(this, serverInfo))
{
@@ -208,6 +202,8 @@ SshConnectionPrivate::SshConnectionPrivate(SshConnection *conn,
m_connParams(serverInfo), m_error(SshNoError), m_ignoreNextPacket(false),
m_conn(conn)
{
doStaticInitializationsIfNecessary();
setupPacketHandlers();
m_socket->setProxy(m_connParams.proxyType == SshConnectionParameters::DefaultProxy
? QNetworkProxy::DefaultProxy : QNetworkProxy::NoProxy);

View File

@@ -90,9 +90,8 @@ class QSSH_EXPORT SshConnection : public QObject
public:
enum State { Unconnected, Connecting, Connected };
typedef QSharedPointer<SshConnection> Ptr;
static Ptr create(const SshConnectionParameters &serverInfo);
SshConnection(const SshConnectionParameters &serverInfo);
void connectToHost();
void disconnectFromHost();
@@ -114,8 +113,6 @@ signals:
void error(QSsh::SshError);
private:
SshConnection(const SshConnectionParameters &serverInfo);
Internal::SshConnectionPrivate *d;
};

View File

@@ -62,12 +62,23 @@ public:
moveToThread(QCoreApplication::instance()->thread());
}
QSharedPointer<SshConnection> acquireConnection(const SshConnectionParameters &sshParams)
~SshConnectionManagerPrivate()
{
foreach (SshConnection * const connection, m_unacquiredConnections) {
disconnect(connection, 0, this, 0);
delete connection;
}
QSSH_ASSERT(m_acquiredConnections.isEmpty());
QSSH_ASSERT(m_deprecatedConnections.isEmpty());
}
SshConnection *acquireConnection(const SshConnectionParameters &sshParams)
{
QMutexLocker locker(&m_listMutex);
// Check in-use connections:
foreach (SshConnection::Ptr connection, m_acquiredConnections) {
foreach (SshConnection * const connection, m_acquiredConnections) {
if (connection->connectionParameters() != sshParams)
continue;
@@ -82,7 +93,7 @@ public:
}
// Checked cached open connections:
foreach (SshConnection::Ptr connection, m_unacquiredConnections) {
foreach (SshConnection * const connection, m_unacquiredConnections) {
if (connection->state() != SshConnection::Connected
|| connection->connectionParameters() != sshParams)
continue;
@@ -90,7 +101,7 @@ public:
if (connection->thread() != QThread::currentThread()) {
QMetaObject::invokeMethod(this, "switchToCallerThread",
Qt::BlockingQueuedConnection,
Q_ARG(SshConnection *, connection.data()),
Q_ARG(SshConnection *, connection),
Q_ARG(QObject *, QThread::currentThread()));
}
@@ -100,35 +111,50 @@ public:
}
// create a new connection:
SshConnection::Ptr connection = SshConnection::create(sshParams);
connect(connection.data(), SIGNAL(disconnected()), this, SLOT(cleanup()));
SshConnection * const connection = new SshConnection(sshParams);
connect(connection, SIGNAL(disconnected()), this, SLOT(cleanup()));
m_acquiredConnections.append(connection);
return connection;
}
void releaseConnection(const SshConnection::Ptr &connection)
void releaseConnection(SshConnection *connection)
{
QMutexLocker locker(&m_listMutex);
m_acquiredConnections.removeOne(connection);
if (!m_acquiredConnections.contains(connection)) {
// no longer in use:
connection->moveToThread(QCoreApplication::instance()->thread());
if (m_deprecatedConnections.contains(connection))
m_deprecatedConnections.removeAll(connection);
else if (connection->state() == SshConnection::Connected) {
// Make sure to only keep one connection open
bool haveConnection = false;
foreach (SshConnection::Ptr conn, m_unacquiredConnections) {
if (conn->connectionParameters() == connection->connectionParameters()) {
haveConnection = true;
break;
}
const bool wasAquired = m_acquiredConnections.removeOne(connection);
QSSH_ASSERT_AND_RETURN(wasAquired);
if (m_acquiredConnections.contains(connection))
return;
bool doDelete = false;
connection->moveToThread(QCoreApplication::instance()->thread());
if (m_deprecatedConnections.removeOne(connection)
|| connection->state() != SshConnection::Connected) {
doDelete = true;
} else {
QSSH_ASSERT_AND_RETURN(!m_unacquiredConnections.contains(connection));
// It can happen that two or more connections with the same parameters were acquired
// if the clients were running in different threads. Only keep one of them in
// such a case.
bool haveConnection = false;
foreach (SshConnection * const conn, m_unacquiredConnections) {
if (conn->connectionParameters() == connection->connectionParameters()) {
haveConnection = true;
break;
}
if (!haveConnection)
m_unacquiredConnections.append(connection);
}
if (!haveConnection)
m_unacquiredConnections.append(connection);
else
doDelete = true;
}
if (doDelete) {
disconnect(connection, 0, this, 0);
m_deprecatedConnections.removeAll(connection);
delete connection;
}
}
@@ -136,25 +162,22 @@ public:
{
QMutexLocker locker(&m_listMutex);
SshConnection::Ptr toReset;
foreach (SshConnection::Ptr connection, m_unacquiredConnections) {
for (int i = 0; i < m_unacquiredConnections.count(); ++i) {
SshConnection * const connection = m_unacquiredConnections.at(i);
if (connection->connectionParameters() == sshParams) {
toReset = connection;
disconnect(connection, 0, this, 0);
delete connection;
m_unacquiredConnections.removeAt(i);
break;
}
}
if (toReset.isNull()) {
foreach (SshConnection::Ptr connection, m_acquiredConnections) {
if (connection->connectionParameters() == sshParams) {
toReset = connection;
break;
}
foreach (SshConnection * const connection, m_acquiredConnections) {
if (connection->connectionParameters() == sshParams) {
if (!m_deprecatedConnections.contains(connection))
m_deprecatedConnections.append(connection);
}
}
if (!toReset.isNull() && !m_deprecatedConnections.contains(toReset))
m_deprecatedConnections.append(toReset);
}
private:
@@ -172,9 +195,9 @@ private slots:
if (!currentConnection)
return;
for (int i = m_unacquiredConnections.count() - 1; i >= 0; --i) {
if (m_unacquiredConnections.at(i) == currentConnection)
m_unacquiredConnections.removeAt(i);
if (m_unacquiredConnections.removeOne(currentConnection)) {
disconnect(currentConnection, 0, this, 0);
currentConnection->deleteLater();
}
}
@@ -182,9 +205,12 @@ private:
// We expect the number of concurrently open connections to be small.
// If that turns out to not be the case, we can still use a data
// structure with faster access.
QList<SshConnection::Ptr> m_unacquiredConnections;
QList<SshConnection::Ptr> m_acquiredConnections;
QList<SshConnection::Ptr> m_deprecatedConnections;
QList<SshConnection *> m_unacquiredConnections;
// Can contain the same connection more than once; this acts as a reference count.
QList<SshConnection *> m_acquiredConnections;
QList<SshConnection *> m_deprecatedConnections;
QMutex m_listMutex;
};
@@ -207,12 +233,12 @@ SshConnectionManager::~SshConnectionManager()
{
}
SshConnection::Ptr SshConnectionManager::acquireConnection(const SshConnectionParameters &sshParams)
SshConnection *SshConnectionManager::acquireConnection(const SshConnectionParameters &sshParams)
{
return d->acquireConnection(sshParams);
}
void SshConnectionManager::releaseConnection(const SshConnection::Ptr &connection)
void SshConnectionManager::releaseConnection(SshConnection *connection)
{
d->releaseConnection(connection);
}

View File

@@ -36,7 +36,6 @@
#include "ssh_global.h"
#include <QScopedPointer>
#include <QSharedPointer>
namespace QSsh {
class SshConnection;
@@ -49,8 +48,8 @@ class QSSH_EXPORT SshConnectionManager
public:
static SshConnectionManager &instance();
QSharedPointer<SshConnection> acquireConnection(const SshConnectionParameters &sshParams);
void releaseConnection(const QSharedPointer<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);

View File

@@ -54,7 +54,7 @@ public:
SshRemoteProcessRunnerPrivate() : m_state(Inactive) {}
SshRemoteProcess::Ptr m_process;
SshConnection::Ptr m_connection;
SshConnection *m_connection;
bool m_runInTerminal;
SshPseudoTerminal m_terminal;
QByteArray m_command;
@@ -112,13 +112,13 @@ void SshRemoteProcessRunner::runInternal(const QByteArray &command,
d->m_exitCode = -1;
d->m_command = command;
d->m_connection = SshConnectionManager::instance().acquireConnection(sshParams);
connect(d->m_connection.data(), SIGNAL(error(QSsh::SshError)),
connect(d->m_connection, SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionError(QSsh::SshError)));
connect(d->m_connection.data(), SIGNAL(disconnected()), SLOT(handleDisconnected()));
connect(d->m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
if (d->m_connection->state() == SshConnection::Connected) {
handleConnected();
} else {
connect(d->m_connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(d->m_connection, SIGNAL(connected()), SLOT(handleConnected()));
if (d->m_connection->state() == SshConnection::Unconnected)
d->m_connection->connectToHost();
}
@@ -208,9 +208,9 @@ void SshRemoteProcessRunner::setState(int newState)
d->m_process.clear();
}
if (d->m_connection) {
disconnect(d->m_connection.data(), 0, this, 0);
disconnect(d->m_connection, 0, this, 0);
SshConnectionManager::instance().releaseConnection(d->m_connection);
d->m_connection.clear();
d->m_connection = 0;
}
}
}

View File

@@ -50,7 +50,7 @@ namespace Internal {
RemoteGdbProcess::RemoteGdbProcess(const QSsh::SshConnectionParameters &connParams,
RemotePlainGdbAdapter *adapter, QObject *parent)
: AbstractGdbProcess(parent), m_connParams(connParams),
: AbstractGdbProcess(parent), m_connParams(connParams), m_conn(0),
m_state(Inactive), m_adapter(adapter)
{
}
@@ -93,12 +93,11 @@ void RemoteGdbProcess::realStart(const QString &cmd, const QStringList &args,
m_errorOutput.clear();
m_inputToSend.clear();
m_conn = SshConnectionManager::instance().acquireConnection(m_connParams);
connect(m_conn.data(), SIGNAL(error(QSsh::SshError)), this,
SLOT(handleConnectionError()));
connect(m_conn, SIGNAL(error(QSsh::SshError)), this, SLOT(handleConnectionError()));
if (m_conn->state() == SshConnection::Connected) {
handleConnected();
} else {
connect(m_conn.data(), SIGNAL(connected()), this, SLOT(handleConnected()));
connect(m_conn, SIGNAL(connected()), this, SLOT(handleConnected()));
if (m_conn->state() == SshConnection::Unconnected)
m_conn->connectToHost();
}
@@ -397,9 +396,9 @@ void RemoteGdbProcess::setState(State newState)
disconnect(m_fifoCreator.data(), 0, this, 0);
m_fifoCreator = QSsh::SshRemoteProcess::Ptr();
}
disconnect(m_conn.data(), 0, this, 0);
disconnect(m_conn, 0, this, 0);
SshConnectionManager::instance().releaseConnection(m_conn);
m_conn.clear();
m_conn = 0;
}
}

View File

@@ -107,7 +107,7 @@ private:
void setState(State newState);
QSsh::SshConnectionParameters m_connParams;
QSsh::SshConnection::Ptr m_conn;
QSsh::SshConnection *m_conn;
QSsh::SshRemoteProcess::Ptr m_gdbProc;
QSsh::SshRemoteProcess::Ptr m_appOutputReader;
QSsh::SshRemoteProcess::Ptr m_fifoCreator;

View File

@@ -128,7 +128,7 @@ void MaddeDeviceTester::handleGenericTestFinished(TestResult result)
m_stdout.clear();
m_stderr.clear();
m_state = QtTest;
m_processRunner->run(qtInfoCmd.toUtf8(), m_genericTester->connection()->connectionParameters());
m_processRunner->run(qtInfoCmd.toUtf8(), m_deviceConfiguration->sshParameters());
}
void MaddeDeviceTester::handleConnectionError()
@@ -196,7 +196,7 @@ void MaddeDeviceTester::handleQtTestFinished(int exitStatus)
emit progressMessage(tr("Checking for connectivity support..."));
m_state = MadDeveloperTest;
m_processRunner->run(QString(QLatin1String("test -x") + MaemoGlobal::devrootshPath()).toUtf8(),
m_genericTester->connection()->connectionParameters());
m_deviceConfiguration->sshParameters());
}
void MaddeDeviceTester::handleMadDeveloperTestFinished(int exitStatus)
@@ -233,8 +233,7 @@ void MaddeDeviceTester::handleMadDeveloperTestFinished(int exitStatus)
emit progressMessage(tr("Checking for QML tooling support..."));
m_state = QmlToolingTest;
m_processRunner->run(QString(QLatin1String("test -d ")
+ QLatin1String(QmlToolingDirectory)).toUtf8(),
m_genericTester->connection()->connectionParameters());
+ QLatin1String(QmlToolingDirectory)).toUtf8(), m_deviceConfiguration->sshParameters());
}
void MaddeDeviceTester::handleQmlToolingTestFinished(int exitStatus)

View File

@@ -70,7 +70,7 @@ MaemoDeploymentMounter::MaemoDeploymentMounter(QObject *parent)
MaemoDeploymentMounter::~MaemoDeploymentMounter() {}
void MaemoDeploymentMounter::setupMounts(const SshConnection::Ptr &connection,
void MaemoDeploymentMounter::setupMounts(SshConnection *connection,
const LinuxDeviceConfiguration::ConstPtr &devConf,
const QList<MaemoMountSpecification> &mountSpecs,
const Qt4BuildConfiguration *bc)
@@ -82,8 +82,7 @@ void MaemoDeploymentMounter::setupMounts(const SshConnection::Ptr &connection,
m_devConf = devConf;
m_mounter->setConnection(m_connection, m_devConf);
m_buildConfig = bc;
connect(m_connection.data(), SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionError()));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
setState(UnmountingOldDirs);
unmount();
}
@@ -205,8 +204,8 @@ void MaemoDeploymentMounter::setState(State newState)
if (m_state == newState)
return;
if (newState == Inactive && m_connection) {
disconnect(m_connection.data(), 0, this, 0);
m_connection.clear();
disconnect(m_connection, 0, this, 0);
m_connection = 0;
}
m_state = newState;
}

View File

@@ -61,7 +61,7 @@ public:
~MaemoDeploymentMounter();
// Connection must be in connected state.
void setupMounts(const QSharedPointer<QSsh::SshConnection> &connection,
void setupMounts(QSsh::SshConnection *connection,
const QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> &devConf,
const QList<MaemoMountSpecification> &mountSpecs,
const Qt4ProjectManager::Qt4BuildConfiguration *bc);
@@ -93,7 +93,7 @@ private:
void setState(State newState);
State m_state;
QSharedPointer<QSsh::SshConnection> m_connection;
QSsh::SshConnection *m_connection;
QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> m_devConf;
MaemoRemoteMounter * const m_mounter;
RemoteLinux::RemoteLinuxUsedPortsGatherer * const m_portsGatherer;

View File

@@ -52,7 +52,7 @@ MaemoRemoteCopyFacility::MaemoRemoteCopyFacility(QObject *parent) :
MaemoRemoteCopyFacility::~MaemoRemoteCopyFacility() {}
void MaemoRemoteCopyFacility::copyFiles(const SshConnection::Ptr &connection,
void MaemoRemoteCopyFacility::copyFiles(SshConnection *connection,
const LinuxDeviceConfiguration::ConstPtr &devConf,
const QList<DeployableFile> &deployables, const QString &mountPoint)
{

View File

@@ -59,7 +59,7 @@ public:
explicit MaemoRemoteCopyFacility(QObject *parent = 0);
~MaemoRemoteCopyFacility();
void copyFiles(const QSharedPointer<QSsh::SshConnection> &connection,
void copyFiles(QSsh::SshConnection *connection,
const QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> &devConf,
const QList<RemoteLinux::DeployableFile> &deployables, const QString &mountPoint);
void cancel();

View File

@@ -66,7 +66,7 @@ MaemoRemoteMounter::~MaemoRemoteMounter()
killAllUtfsServers();
}
void MaemoRemoteMounter::setConnection(const SshConnection::Ptr &connection,
void MaemoRemoteMounter::setConnection(SshConnection *connection,
const LinuxDeviceConfiguration::ConstPtr &devConf)
{
QTC_ASSERT(m_state == Inactive, return);

View File

@@ -68,7 +68,7 @@ public:
~MaemoRemoteMounter();
// Must already be connected.
void setConnection(const QSharedPointer<QSsh::SshConnection> &connection,
void setConnection(QSsh::SshConnection *connection,
const QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> &devConf);
void setBuildConfiguration(const Qt4ProjectManager::Qt4BuildConfiguration *bc);
@@ -123,7 +123,7 @@ private:
int remotePort;
};
QSharedPointer<QSsh::SshConnection> m_connection;
QSsh::SshConnection *m_connection;
QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> m_devConf;
QList<MountInfo> m_mountSpecs;
QSharedPointer<QSsh::SshRemoteProcess> m_mountProcess;

View File

@@ -83,11 +83,12 @@ const char LastDeployedTimesKey[] = "Qt4ProjectManager.MaemoRunConfiguration.Las
class AbstractRemoteLinuxDeployServicePrivate
{
public:
AbstractRemoteLinuxDeployServicePrivate() : state(Inactive), stopRequested(false) {}
AbstractRemoteLinuxDeployServicePrivate()
: connection(0), state(Inactive), stopRequested(false) {}
LinuxDeviceConfiguration::ConstPtr deviceConfiguration;
QPointer<Qt4BuildConfiguration> buildConfiguration;
SshConnection::Ptr connection;
SshConnection *connection;
State state;
bool stopRequested;
@@ -117,7 +118,7 @@ LinuxDeviceConfiguration::ConstPtr AbstractRemoteLinuxDeployService::deviceConfi
return d->deviceConfiguration;
}
SshConnection::Ptr AbstractRemoteLinuxDeployService::connection() const
SshConnection *AbstractRemoteLinuxDeployService::connection() const
{
return d->connection;
}
@@ -263,12 +264,12 @@ void AbstractRemoteLinuxDeployService::handleDeviceSetupDone(bool success)
d->state = Connecting;
d->connection = SshConnectionManager::instance().acquireConnection(d->deviceConfiguration->sshParameters());
connect(d->connection.data(), SIGNAL(error(QSsh::SshError)),
connect(d->connection, SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionFailure()));
if (d->connection->state() == SshConnection::Connected) {
handleConnected();
} else {
connect(d->connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(d->connection, SIGNAL(connected()), SLOT(handleConnected()));
emit progressMessage(tr("Connecting to device..."));
if (d->connection->state() == SshConnection::Unconnected)
d->connection->connectToHost();
@@ -322,9 +323,9 @@ void AbstractRemoteLinuxDeployService::setFinished()
{
d->state = Inactive;
if (d->connection) {
disconnect(d->connection.data(), 0, this, 0);
disconnect(d->connection, 0, this, 0);
SshConnectionManager::instance().releaseConnection(d->connection);
d->connection = SshConnection::Ptr();
d->connection = 0;
}
d->stopRequested = false;
emit finished();

View File

@@ -82,7 +82,7 @@ signals:
protected:
const Qt4ProjectManager::Qt4BuildConfiguration *qt4BuildConfiguration() const;
QSharedPointer<const LinuxDeviceConfiguration> deviceConfiguration() const;
QSharedPointer<QSsh::SshConnection> connection() const;
QSsh::SshConnection *connection() const;
void saveDeploymentTimeStamp(const DeployableFile &deployableFile);
bool hasChangedSinceLastDeployment(const DeployableFile &deployableFile) const;

View File

@@ -51,10 +51,10 @@ enum State { Inactive, Connecting, RunningUname, TestingPorts };
class GenericLinuxDeviceTesterPrivate
{
public:
GenericLinuxDeviceTesterPrivate() : state(Inactive) {}
GenericLinuxDeviceTesterPrivate() : connection(0), state(Inactive) {}
LinuxDeviceConfiguration::ConstPtr deviceConfiguration;
SshConnection::Ptr connection;
SshConnection *connection;
SshRemoteProcess::Ptr process;
RemoteLinuxUsedPortsGatherer portsGatherer;
State state;
@@ -76,6 +76,7 @@ GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
{
delete d->connection;
delete d;
}
@@ -84,9 +85,9 @@ void GenericLinuxDeviceTester::testDevice(const LinuxDeviceConfiguration::ConstP
QTC_ASSERT(d->state == Inactive, return);
d->deviceConfiguration = deviceConfiguration;
d->connection = SshConnection::create(deviceConfiguration->sshParameters());
connect(d->connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(d->connection.data(), SIGNAL(error(QSsh::SshError)),
d->connection = new SshConnection(deviceConfiguration->sshParameters());
connect(d->connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(d->connection, SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionFailure()));
emit progressMessage(tr("Connecting to host..."));
@@ -115,11 +116,6 @@ void GenericLinuxDeviceTester::stopTest()
setFinished(TestFailure);
}
SshConnection::Ptr GenericLinuxDeviceTester::connection() const
{
return d->connection;
}
void GenericLinuxDeviceTester::handleConnected()
{
QTC_ASSERT(d->state == Connecting, return);
@@ -190,8 +186,10 @@ void GenericLinuxDeviceTester::handlePortListReady()
void GenericLinuxDeviceTester::setFinished(TestResult result)
{
d->state = Inactive;
disconnect(d->connection.data(), 0, this, 0);
disconnect(d->connection, 0, this, 0);
disconnect(&d->portsGatherer, 0, this, 0);
delete d->connection;
d->connection = 0;
emit finished(result);
}

View File

@@ -80,8 +80,6 @@ public:
void testDevice(const QSharedPointer<const LinuxDeviceConfiguration> &deviceConfiguration);
void stopTest();
QSharedPointer<QSsh::SshConnection> connection() const;
private slots:
void handleConnected();
void handleConnectionFailure();

View File

@@ -42,7 +42,7 @@ namespace RemoteLinux {
namespace Internal {
PackageUploader::PackageUploader(QObject *parent) :
QObject(parent), m_state(Inactive)
QObject(parent), m_state(Inactive), m_connection(0)
{
}
@@ -50,7 +50,7 @@ PackageUploader::~PackageUploader()
{
}
void PackageUploader::uploadPackage(const SshConnection::Ptr &connection,
void PackageUploader::uploadPackage(SshConnection *connection,
const QString &localFilePath, const QString &remoteFilePath)
{
QTC_ASSERT(m_state == Inactive, return);
@@ -61,8 +61,7 @@ void PackageUploader::uploadPackage(const SshConnection::Ptr &connection,
m_localFilePath = localFilePath;
m_remoteFilePath = remoteFilePath;
m_connection = connection;
connect(m_connection.data(), SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionFailure()));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionFailure()));
m_uploader = m_connection->createSftpChannel();
connect(m_uploader.data(), SIGNAL(initialized()), this,
SLOT(handleSftpChannelInitialized()));
@@ -149,8 +148,8 @@ void PackageUploader::setState(State newState)
m_uploader.clear();
}
if (m_connection) {
disconnect(m_connection.data(), 0, this, 0);
m_connection.clear();
disconnect(m_connection, 0, this, 0);
m_connection = 0;
}
}
m_state = newState;

View File

@@ -55,7 +55,7 @@ public:
~PackageUploader();
// Connection has to be established already.
void uploadPackage(const QSharedPointer<QSsh::SshConnection> &connection,
void uploadPackage(QSsh::SshConnection *connection,
const QString &localFilePath, const QString &remoteFilePath);
void cancelUpload();
@@ -76,7 +76,7 @@ private:
void setState(State newState);
State m_state;
QSharedPointer<QSsh::SshConnection> m_connection;
QSsh::SshConnection *m_connection;
QSharedPointer<QSsh::SftpChannel> m_uploader;
QString m_localFilePath;
QString m_remoteFilePath;

View File

@@ -68,6 +68,7 @@ public:
appArguments(runConfig->arguments()),
commandPrefix(runConfig->commandPrefix()),
initialFreePorts(runConfig->freePorts()),
connection(0),
stopRequested(false),
state(Inactive)
{
@@ -80,7 +81,7 @@ public:
const QString commandPrefix;
const PortList initialFreePorts;
QSsh::SshConnection::Ptr connection;
QSsh::SshConnection *connection;
QSsh::SshRemoteProcess::Ptr runner;
QSsh::SshRemoteProcess::Ptr cleaner;
@@ -108,7 +109,7 @@ AbstractRemoteLinuxApplicationRunner::~AbstractRemoteLinuxApplicationRunner()
delete d;
}
SshConnection::Ptr AbstractRemoteLinuxApplicationRunner::connection() const
SshConnection *AbstractRemoteLinuxApplicationRunner::connection() const
{
return d->connection;
}
@@ -310,9 +311,9 @@ void AbstractRemoteLinuxApplicationRunner::setInactive()
{
d->portsGatherer.stop();
if (d->connection) {
disconnect(d->connection.data(), 0, this, 0);
disconnect(d->connection, 0, this, 0);
SshConnectionManager::instance().releaseConnection(d->connection);
d->connection = SshConnection::Ptr();
d->connection = 0;
}
if (d->cleaner)
disconnect(d->cleaner.data(), 0, this, 0);
@@ -400,8 +401,8 @@ void AbstractRemoteLinuxApplicationRunner::handleDeviceSetupDone(bool success)
d->state = Connecting;
d->exitStatus = -1;
d->freePorts = d->initialFreePorts;
connect(d->connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(d->connection.data(), SIGNAL(error(QSsh::SshError)),
connect(d->connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(d->connection, SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionFailure()));
if (d->connection->state() == SshConnection::Connected) {
handleConnected();

View File

@@ -62,8 +62,8 @@ public:
void startExecution(const QByteArray &remoteCall);
QSharedPointer<QSsh::SshConnection> connection() const;
QSharedPointer<const LinuxDeviceConfiguration> devConfig() const;
QSsh::SshConnection *connection() const;
const RemoteLinuxUsedPortsGatherer *usedPortsGatherer() const;
Utils::PortList *freePorts();
QString remoteExecutable() const;

View File

@@ -49,7 +49,7 @@ namespace Internal {
class RemoteLinuxUsedPortsGathererPrivate
{
public:
SshConnection::Ptr connection;
SshConnection *connection;
SshRemoteProcess::Ptr process;
PortList portsToCheck;
QList<int> usedPorts;
@@ -64,6 +64,7 @@ using namespace Internal;
RemoteLinuxUsedPortsGatherer::RemoteLinuxUsedPortsGatherer(QObject *parent) :
QObject(parent), d(new RemoteLinuxUsedPortsGathererPrivate)
{
d->connection = 0;
}
RemoteLinuxUsedPortsGatherer::~RemoteLinuxUsedPortsGatherer()
@@ -76,12 +77,12 @@ void RemoteLinuxUsedPortsGatherer::start(const LinuxDeviceConfiguration::ConstPt
QTC_ASSERT(!d->connection, return);
d->portsToCheck = devConf->freePorts();
d->connection = SshConnectionManager::instance().acquireConnection(devConf->sshParameters());
connect(d->connection.data(), SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
connect(d->connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
if (d->connection->state() == SshConnection::Connected) {
handleConnectionEstablished();
return;
}
connect(d->connection.data(), SIGNAL(connected()), SLOT(handleConnectionEstablished()));
connect(d->connection, SIGNAL(connected()), SLOT(handleConnectionEstablished()));
if (d->connection->state() == SshConnection::Unconnected)
d->connection->connectToHost();
}
@@ -119,9 +120,9 @@ void RemoteLinuxUsedPortsGatherer::stop()
if (d->process)
disconnect(d->process.data(), 0, this, 0);
d->process.clear();
disconnect(d->connection.data(), 0, this, 0);
disconnect(d->connection, 0, this, 0);
SshConnectionManager::instance().releaseConnection(d->connection);
d->connection.clear();
d->connection = 0;
}
int RemoteLinuxUsedPortsGatherer::getNextFreePort(PortList *freePorts) const

View File

@@ -102,7 +102,7 @@ private:
Option m_lastOption;
// remote callgrind support
QSsh::SshConnection::Ptr m_ssh;
QSsh::SshConnection *m_ssh;
QString m_tempDataFile;
QSsh::SshRemoteProcess::Ptr m_findRemoteFile;
QSsh::SftpChannel::Ptr m_sftp;

View File

@@ -152,11 +152,12 @@ RemoteValgrindProcess::RemoteValgrindProcess(const QSsh::SshConnectionParameters
QObject *parent)
: ValgrindProcess(parent)
, m_params(sshParams)
, m_connection(0)
, m_error(QProcess::UnknownError)
, m_pid(0)
{}
RemoteValgrindProcess::RemoteValgrindProcess(const QSsh::SshConnection::Ptr &connection, QObject *parent)
RemoteValgrindProcess::RemoteValgrindProcess(QSsh::SshConnection *connection, QObject *parent)
: ValgrindProcess(parent)
, m_params(connection->connectionParameters())
, m_connection(connection)
@@ -164,6 +165,11 @@ RemoteValgrindProcess::RemoteValgrindProcess(const QSsh::SshConnection::Ptr &con
, m_pid(0)
{}
RemoteValgrindProcess::~RemoteValgrindProcess()
{
delete m_connection;
}
bool RemoteValgrindProcess::isRunning() const
{
return m_process && m_process->isRunning();
@@ -179,12 +185,11 @@ void RemoteValgrindProcess::run(const QString &valgrindExecutable, const QString
// connect to host and wait for connection
if (!m_connection)
m_connection = QSsh::SshConnection::create(m_params);
m_connection = new QSsh::SshConnection(m_params);
if (m_connection->state() != QSsh::SshConnection::Connected) {
connect(m_connection.data(), SIGNAL(connected()),
this, SLOT(connected()));
connect(m_connection.data(), SIGNAL(error(QSsh::SshError)),
connect(m_connection, SIGNAL(connected()), this, SLOT(connected()));
connect(m_connection, SIGNAL(error(QSsh::SshError)),
this, SLOT(error(QSsh::SshError)));
if (m_connection->state() == QSsh::SshConnection::Unconnected)
m_connection->connectToHost();
@@ -219,7 +224,7 @@ void RemoteValgrindProcess::connected()
m_process->start();
}
QSsh::SshConnection::Ptr RemoteValgrindProcess::connection() const
QSsh::SshConnection *RemoteValgrindProcess::connection() const
{
return m_connection;
}

View File

@@ -120,8 +120,9 @@ class RemoteValgrindProcess : public ValgrindProcess
public:
explicit RemoteValgrindProcess(const QSsh::SshConnectionParameters &sshParams,
QObject *parent = 0);
explicit RemoteValgrindProcess(const QSsh::SshConnection::Ptr &connection,
explicit RemoteValgrindProcess(QSsh::SshConnection *connection,
QObject *parent = 0);
~RemoteValgrindProcess();
virtual bool isRunning() const;
@@ -139,7 +140,7 @@ public:
virtual qint64 pid() const;
QSsh::SshConnection::Ptr connection() const;
QSsh::SshConnection *connection() const;
private slots:
void closed(int);
@@ -152,7 +153,7 @@ private slots:
private:
QSsh::SshConnectionParameters m_params;
QSsh::SshConnection::Ptr m_connection;
QSsh::SshConnection *m_connection;
QSsh::SshRemoteProcess::Ptr m_process;
QString m_workingDir;
QString m_valgrindExe;

View File

@@ -48,7 +48,7 @@ public:
Test()
{
m_timeoutTimer.setSingleShot(true);
m_connection = SshConnection::create(SshConnectionParameters());
m_connection = new SshConnection(SshConnectionParameters());
if (m_connection->state() != SshConnection::Unconnected) {
qDebug("Error: Newly created SSH connection has state %d.",
m_connection->state());
@@ -107,7 +107,10 @@ public:
runNextTest();
}
~Test();
~Test()
{
delete m_connection;
}
private slots:
void handleConnected()
@@ -164,17 +167,15 @@ private slots:
private:
void runNextTest()
{
if (m_connection)
disconnect(m_connection.data(), 0, this, 0);
m_connection = SshConnection::create(m_testSet.first().params);
connect(m_connection.data(), SIGNAL(connected()), this,
SLOT(handleConnected()));
connect(m_connection.data(), SIGNAL(disconnected()), this,
SLOT(handleDisconnected()));
connect(m_connection.data(), SIGNAL(dataAvailable(QString)), this,
SLOT(handleDataAvailable(QString)));
connect(m_connection.data(), SIGNAL(error(QSsh::SshError)), this,
SLOT(handleError(QSsh::SshError)));
if (m_connection) {
disconnect(m_connection, 0, this, 0);
delete m_connection;
}
m_connection = new SshConnection(m_testSet.first().params);
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
connect(m_connection, SIGNAL(dataAvailable(QString)), SLOT(handleDataAvailable(QString)));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleError(QSsh::SshError)));
const TestItem &nextItem = m_testSet.first();
m_timeoutTimer.stop();
m_timeoutTimer.setInterval(qMax(10000, nextItem.params.timeout * 1000));
@@ -182,7 +183,7 @@ private:
m_connection->connectToHost();
}
SshConnection::Ptr m_connection;
SshConnection *m_connection;
typedef QList<SshError> ErrorList;
struct TestItem {
TestItem(const char *d, const SshConnectionParameters &p,
@@ -196,8 +197,6 @@ private:
QTimer m_timeoutTimer;
};
Test::~Test() {}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

View File

@@ -47,6 +47,7 @@ const QByteArray StderrOutput("ChannelTest");
RemoteProcessTest::RemoteProcessTest(const SshConnectionParameters &params)
: m_sshParams(params),
m_timeoutTimer(new QTimer(this)),
m_sshConnection(0),
m_remoteRunner(new SshRemoteProcessRunner(this)),
m_state(Inactive)
{
@@ -54,7 +55,10 @@ RemoteProcessTest::RemoteProcessTest(const SshConnectionParameters &params)
connect(m_timeoutTimer, SIGNAL(timeout()), SLOT(handleTimeout()));
}
RemoteProcessTest::~RemoteProcessTest() { }
RemoteProcessTest::~RemoteProcessTest()
{
delete m_sshConnection;
}
void RemoteProcessTest::run()
{
@@ -214,9 +218,9 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
}
std::cout << "Ok.\nTesting I/O device functionality... " << std::flush;
m_state = TestingIoDevice;
m_sshConnection = QSsh::SshConnection::create(m_sshParams);
connect(m_sshConnection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(m_sshConnection.data(), SIGNAL(error(QSsh::SshError)),
m_sshConnection = new QSsh::SshConnection(m_sshParams);
connect(m_sshConnection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_sshConnection, SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionError()));
m_sshConnection->connectToHost();
m_timeoutTimer->start();

View File

@@ -76,7 +76,7 @@ private:
QSsh::SshRemoteProcessRunner * const m_remoteRunner;
QSsh::SshRemoteProcess::Ptr m_catProcess;
QSsh::SshRemoteProcess::Ptr m_echoProcess;
QSsh::SshConnection::Ptr m_sshConnection;
QSsh::SshConnection *m_sshConnection;
QByteArray m_remoteStdout;
QByteArray m_remoteStderr;
QByteArray m_remoteData;

View File

@@ -43,7 +43,7 @@
using namespace QSsh;
SftpTest::SftpTest(const Parameters &params)
: m_parameters(params), m_state(Inactive), m_error(false),
: m_parameters(params), m_state(Inactive), m_error(false), m_connection(0),
m_bigFileUploadJob(SftpInvalidJob),
m_bigFileDownloadJob(SftpInvalidJob),
m_bigFileRemovalJob(SftpInvalidJob),
@@ -57,17 +57,15 @@ SftpTest::SftpTest(const Parameters &params)
SftpTest::~SftpTest()
{
removeFiles(true);
delete m_connection;
}
void SftpTest::run()
{
m_connection = SshConnection::create(m_parameters.sshParams);
connect(m_connection.data(), SIGNAL(connected()), this,
SLOT(handleConnected()));
connect(m_connection.data(), SIGNAL(error(QSsh::SshError)), this,
SLOT(handleError()));
connect(m_connection.data(), SIGNAL(disconnected()), this,
SLOT(handleDisconnected()));
m_connection = new SshConnection(m_parameters.sshParams);
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleError()));
connect(m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
std::cout << "Connecting to host '"
<< qPrintable(m_parameters.sshParams.host) << "'..." << std::endl;
m_state = Connecting;

View File

@@ -90,7 +90,7 @@ private:
const Parameters m_parameters;
State m_state;
bool m_error;
QSsh::SshConnection::Ptr m_connection;
QSsh::SshConnection *m_connection;
QSsh::SftpChannel::Ptr m_channel;
QList<FilePtr> m_localSmallFiles;
JobMap m_smallFilesUploadJobs;

View File

@@ -45,16 +45,17 @@ using namespace QSsh;
Shell::Shell(const QSsh::SshConnectionParameters &parameters, QObject *parent)
: QObject(parent),
m_connection(SshConnection::create(parameters)),
m_connection(new SshConnection(parameters)),
m_stdin(new QFile(this))
{
connect(m_connection.data(), SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection.data(), SIGNAL(dataAvailable(QString)), SLOT(handleShellMessage(QString)));
connect(m_connection.data(), SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(dataAvailable(QString)), SLOT(handleShellMessage(QString)));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
}
Shell::~Shell()
{
delete m_connection;
}
void Shell::run()

View File

@@ -67,7 +67,7 @@ private slots:
void handleStdin();
private:
QSharedPointer<QSsh::SshConnection> m_connection;
QSsh::SshConnection *m_connection;
QSharedPointer<QSsh::SshRemoteProcess> m_shell;
QFile * const m_stdin;
};