Commit bbbda740 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

RemoteLinux: Rename and export MaemoUsedPortsGatherer.

Class is not Maemo-specific.

Change-Id: I14473cb329e4955d24dae1a1a4961eb6ebff869c
Reviewed-on: http://codereview.qt.nokia.com/2042

Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 9d5f420f
......@@ -32,7 +32,7 @@
#include "linuxdevicetester.h"
#include "linuxdeviceconfiguration.h"
#include "maemousedportsgatherer.h"
#include "remotelinuxusedportsgatherer.h"
#include <utils/qtcassert.h>
#include <utils/ssh/sshremoteprocess.h>
......@@ -56,7 +56,7 @@ public:
LinuxDeviceConfiguration::ConstPtr deviceConfiguration;
SshConnection::Ptr connection;
SshRemoteProcess::Ptr process;
MaemoUsedPortsGatherer portsGatherer;
RemoteLinuxUsedPortsGatherer portsGatherer;
QByteArray remoteStdout;
QByteArray remoteStderr;
State state;
......
......@@ -34,9 +34,10 @@
#include "maemoglobal.h"
#include "maemoremotemounter.h"
#include "maemousedportsgatherer.h"
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <remotelinux/linuxdeviceconfiguration.h>
#include <remotelinux/remotelinuxusedportsgatherer.h>
#include <utils/qtcassert.h>
#include <utils/ssh/sshconnection.h>
......@@ -50,7 +51,7 @@ MaemoDeploymentMounter::MaemoDeploymentMounter(QObject *parent)
: QObject(parent),
m_state(Inactive),
m_mounter(new MaemoRemoteMounter(this)),
m_portsGatherer(new MaemoUsedPortsGatherer(this))
m_portsGatherer(new RemoteLinuxUsedPortsGatherer(this))
{
connect(m_mounter, SIGNAL(error(QString)), SLOT(handleMountError(QString)));
connect(m_mounter, SIGNAL(mounted()), SLOT(handleMounted()));
......
......@@ -45,10 +45,10 @@ namespace Qt4ProjectManager { class Qt4BuildConfiguration; }
namespace RemoteLinux {
class LinuxDeviceConfiguration;
class RemoteLinuxUsedPortsGatherer;
namespace Internal {
class MaemoRemoteMounter;
class MaemoUsedPortsGatherer;
class MaemoDeploymentMounter : public QObject
{
......@@ -93,7 +93,7 @@ private:
QSharedPointer<Utils::SshConnection> m_connection;
QSharedPointer<const LinuxDeviceConfiguration> m_devConf;
MaemoRemoteMounter * const m_mounter;
MaemoUsedPortsGatherer * const m_portsGatherer;
RemoteLinuxUsedPortsGatherer * const m_portsGatherer;
PortList m_freePorts;
QList<MaemoMountSpecification> m_mountSpecs;
const Qt4ProjectManager::Qt4BuildConfiguration *m_buildConfig;
......
......@@ -33,13 +33,14 @@
#include "maemoremotemounter.h"
#include "maemoglobal.h"
#include "maemousedportsgatherer.h"
#include "qt4maemotarget.h"
#include <utils/ssh/sshconnection.h>
#include <utils/ssh/sshremoteprocess.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qtsupport/baseqtversion.h>
#include <remotelinux/linuxdeviceconfiguration.h>
#include <remotelinux/remotelinuxusedportsgatherer.h>
#include <utils/qtcassert.h>
#include <QtCore/QTimer>
......@@ -98,7 +99,7 @@ bool MaemoRemoteMounter::hasValidMountSpecifications() const
}
void MaemoRemoteMounter::mount(PortList *freePorts,
const MaemoUsedPortsGatherer *portsGatherer)
const RemoteLinuxUsedPortsGatherer *portsGatherer)
{
QTC_ASSERT(m_state == Inactive, return);
......
......@@ -54,9 +54,9 @@ namespace Qt4ProjectManager { class Qt4BuildConfiguration; }
namespace RemoteLinux {
class LinuxDeviceConfiguration;
class PortList;
class RemoteLinuxUsedPortsGatherer;
namespace Internal {
class MaemoUsedPortsGatherer;
class MaemoRemoteMounter : public QObject
{
......@@ -75,7 +75,7 @@ public:
bool hasValidMountSpecifications() const;
void resetMountSpecifications() { m_mountSpecs.clear(); }
void mount(PortList *freePorts,
const MaemoUsedPortsGatherer *portsGatherer);
const RemoteLinuxUsedPortsGatherer *portsGatherer);
void unmount();
void stop();
......@@ -135,7 +135,7 @@ private:
QByteArray m_utfsClientStderr;
QByteArray m_umountStderr;
PortList *m_freePorts;
const MaemoUsedPortsGatherer *m_portsGatherer;
const RemoteLinuxUsedPortsGatherer *m_portsGatherer;
bool m_remoteMountsAllowed;
QString m_maddeRoot;
......
......@@ -25,7 +25,6 @@ HEADERS += \
maemomountspecification.h \
maemoremotemounter.h \
maemoprofilesupdatedialog.h \
maemousedportsgatherer.h \
maemopublishingwizardfactories.h \
maemopublishingbuildsettingspagefremantlefree.h \
maemopublishingfileselectiondialog.h \
......@@ -96,7 +95,8 @@ HEADERS += \
remotelinuxenvironmentreader.h \
sshkeydeployer.h \
typespecificdeviceconfigurationlistmodel.h \
sshkeycreationdialog.h
sshkeycreationdialog.h \
remotelinuxusedportsgatherer.h
SOURCES += \
remotelinuxplugin.cpp \
......@@ -117,7 +117,6 @@ SOURCES += \
maemomountspecification.cpp \
maemoremotemounter.cpp \
maemoprofilesupdatedialog.cpp \
maemousedportsgatherer.cpp \
maemopublishingwizardfactories.cpp \
maemopublishingbuildsettingspagefremantlefree.cpp \
maemopublishingfileselectiondialog.cpp \
......@@ -185,7 +184,8 @@ SOURCES += \
remotelinuxenvironmentreader.cpp \
sshkeydeployer.cpp \
typespecificdeviceconfigurationlistmodel.cpp \
sshkeycreationdialog.cpp
sshkeycreationdialog.cpp \
remotelinuxusedportsgatherer.cpp
FORMS += \
maemopackagecreationwidget.ui \
......
......@@ -33,7 +33,7 @@
#include "linuxdeviceconfiguration.h"
#include "remotelinuxrunconfiguration.h"
#include "maemousedportsgatherer.h"
#include "remotelinuxusedportsgatherer.h"
#include <utils/qtcassert.h>
#include <utils/ssh/sshconnection.h>
......@@ -71,7 +71,7 @@ public:
{
}
MaemoUsedPortsGatherer portsGatherer;
RemoteLinuxUsedPortsGatherer portsGatherer;
const LinuxDeviceConfiguration::ConstPtr devConfig;
const QString remoteExecutable;
const QString appArguments;
......@@ -116,7 +116,7 @@ LinuxDeviceConfiguration::ConstPtr AbstractRemoteLinuxApplicationRunner::devConf
return m_d->devConfig;
}
const MaemoUsedPortsGatherer *AbstractRemoteLinuxApplicationRunner::usedPortsGatherer() const
const RemoteLinuxUsedPortsGatherer *AbstractRemoteLinuxApplicationRunner::usedPortsGatherer() const
{
return &m_d->portsGatherer;
}
......
......@@ -47,10 +47,10 @@ class SshRemoteProcess;
namespace RemoteLinux {
class LinuxDeviceConfiguration;
class RemoteLinuxRunConfiguration;
class RemoteLinuxUsedPortsGatherer;
namespace Internal {
class AbstractRemoteLinuxApplicationRunnerPrivate;
class MaemoUsedPortsGatherer;
}
class REMOTELINUX_EXPORT AbstractRemoteLinuxApplicationRunner : public QObject
......@@ -68,7 +68,7 @@ public:
QSharedPointer<Utils::SshConnection> connection() const;
QSharedPointer<const LinuxDeviceConfiguration> devConfig() const;
const Internal::MaemoUsedPortsGatherer *usedPortsGatherer() const;
const RemoteLinuxUsedPortsGatherer *usedPortsGatherer() const;
PortList *freePorts();
QString remoteExecutable() const;
QString arguments() const;
......
......@@ -32,9 +32,9 @@
#include "remotelinuxdebugsupport.h"
#include "linuxdeviceconfiguration.h"
#include "maemousedportsgatherer.h"
#include "qt4maemotarget.h"
#include "remotelinuxapplicationrunner.h"
#include "remotelinuxusedportsgatherer.h"
#include <debugger/debuggerengine.h>
#include <projectexplorer/abi.h>
......
......@@ -28,82 +28,103 @@
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "remotelinuxusedportsgatherer.h"
#include "maemousedportsgatherer.h"
#include "maemoglobal.h"
#include "linuxdeviceconfiguration.h"
#include <utils/ssh/sshremoteprocessrunner.h>
#include <QtCore/QString>
using namespace Utils;
namespace RemoteLinux {
namespace Internal {
MaemoUsedPortsGatherer::MaemoUsedPortsGatherer(QObject *parent) :
QObject(parent), m_running(false)
class RemoteLinuxUsedPortsGathererPrivate
{
public:
RemoteLinuxUsedPortsGathererPrivate() : running(false) {}
SshRemoteProcessRunner::Ptr procRunner;
QList<int> usedPorts;
QByteArray remoteStdout;
QByteArray remoteStderr;
bool running;
};
} // namespace Internal
using namespace Internal;
RemoteLinuxUsedPortsGatherer::RemoteLinuxUsedPortsGatherer(QObject *parent) :
QObject(parent), m_d(new RemoteLinuxUsedPortsGathererPrivate)
{
}
MaemoUsedPortsGatherer::~MaemoUsedPortsGatherer() {}
RemoteLinuxUsedPortsGatherer::~RemoteLinuxUsedPortsGatherer()
{
delete m_d;
}
void MaemoUsedPortsGatherer::start(const Utils::SshConnection::Ptr &connection,
void RemoteLinuxUsedPortsGatherer::start(const Utils::SshConnection::Ptr &connection,
const LinuxDeviceConfiguration::ConstPtr &devConf)
{
if (m_running)
if (m_d->running)
qWarning("Unexpected call of %s in running state", Q_FUNC_INFO);
m_usedPorts.clear();
m_remoteStdout.clear();
m_remoteStderr.clear();
m_procRunner = SshRemoteProcessRunner::create(connection);
connect(m_procRunner.data(), SIGNAL(connectionError(Utils::SshError)),
m_d->usedPorts.clear();
m_d->remoteStdout.clear();
m_d->remoteStderr.clear();
m_d->procRunner = SshRemoteProcessRunner::create(connection);
connect(m_d->procRunner.data(), SIGNAL(connectionError(Utils::SshError)),
SLOT(handleConnectionError()));
connect(m_procRunner.data(), SIGNAL(processClosed(int)),
connect(m_d->procRunner.data(), SIGNAL(processClosed(int)),
SLOT(handleProcessClosed(int)));
connect(m_procRunner.data(), SIGNAL(processOutputAvailable(QByteArray)),
connect(m_d->procRunner.data(), SIGNAL(processOutputAvailable(QByteArray)),
SLOT(handleRemoteStdOut(QByteArray)));
connect(m_procRunner.data(), SIGNAL(processErrorOutputAvailable(QByteArray)),
connect(m_d->procRunner.data(), SIGNAL(processErrorOutputAvailable(QByteArray)),
SLOT(handleRemoteStdErr(QByteArray)));
QString command = QLatin1String("lsof -nPi4tcp:") + devConf->freePorts().toString()
const QString command = QLatin1String("lsof -nPi4tcp:") + devConf->freePorts().toString()
+ QLatin1String(" -F n |grep '^n' |sed -r 's/[^:]*:([[:digit:]]+).*/\\1/g' |sort -n |uniq");
if (devConf->osType() != LinuxDeviceConfiguration::HarmattanOsType) { // devrootsh is broken on Harmattan
command.prepend(MaemoGlobal::remoteSudo(devConf->osType(),
devConf->sshParameters().userName) + QLatin1Char(' '));
}
m_procRunner->run(command.toUtf8());
m_running = true;
m_d->procRunner->run(command.toUtf8());
m_d->running = true;
}
void MaemoUsedPortsGatherer::stop()
void RemoteLinuxUsedPortsGatherer::stop()
{
if (!m_running)
if (!m_d->running)
return;
m_running = false;
disconnect(m_procRunner->connection().data(), 0, this, 0);
if (m_procRunner->process())
m_procRunner->process()->closeChannel();
m_d->running = false;
disconnect(m_d->procRunner->connection().data(), 0, this, 0);
if (m_d->procRunner->process())
m_d->procRunner->process()->closeChannel();
}
int MaemoUsedPortsGatherer::getNextFreePort(PortList *freePorts) const
int RemoteLinuxUsedPortsGatherer::getNextFreePort(PortList *freePorts) const
{
while (freePorts->hasMore()) {
const int port = freePorts->getNext();
if (!m_usedPorts.contains(port))
if (!m_d->usedPorts.contains(port))
return port;
}
return -1;
}
void MaemoUsedPortsGatherer::setupUsedPorts()
QList<int> RemoteLinuxUsedPortsGatherer::usedPorts() const
{
const QList<QByteArray> &portStrings = m_remoteStdout.split('\n');
return m_d->usedPorts;
}
void RemoteLinuxUsedPortsGatherer::setupUsedPorts()
{
const QList<QByteArray> &portStrings = m_d->remoteStdout.split('\n');
foreach (const QByteArray &portString, portStrings) {
if (portString.isEmpty())
continue;
bool ok;
const int port = portString.toInt(&ok);
if (ok) {
m_usedPorts << port;
m_d->usedPorts << port;
} else {
qWarning("%s: Unexpected string '%s' is not a port.",
Q_FUNC_INFO, portString.data());
......@@ -112,35 +133,35 @@ void MaemoUsedPortsGatherer::setupUsedPorts()
emit portListReady();
}
void MaemoUsedPortsGatherer::handleConnectionError()
void RemoteLinuxUsedPortsGatherer::handleConnectionError()
{
if (!m_running)
if (!m_d->running)
return;
emit error(tr("Connection error: %1").
arg(m_procRunner->connection()->errorString()));
arg(m_d->procRunner->connection()->errorString()));
stop();
}
void MaemoUsedPortsGatherer::handleProcessClosed(int exitStatus)
void RemoteLinuxUsedPortsGatherer::handleProcessClosed(int exitStatus)
{
if (!m_running)
if (!m_d->running)
return;
QString errMsg;
switch (exitStatus) {
case SshRemoteProcess::FailedToStart:
errMsg = tr("Could not start remote process: %1")
.arg(m_procRunner->process()->errorString());
.arg(m_d->procRunner->process()->errorString());
break;
case SshRemoteProcess::KilledBySignal:
errMsg = tr("Remote process crashed: %1")
.arg(m_procRunner->process()->errorString());
.arg(m_d->procRunner->process()->errorString());
break;
case SshRemoteProcess::ExitedNormally:
if (m_procRunner->process()->exitCode() == 0) {
if (m_d->procRunner->process()->exitCode() == 0) {
setupUsedPorts();
} else {
errMsg = tr("Remote process failed: %1")
.arg(m_procRunner->process()->errorString());
.arg(m_d->procRunner->process()->errorString());
}
break;
default:
......@@ -148,24 +169,23 @@ void MaemoUsedPortsGatherer::handleProcessClosed(int exitStatus)
}
if (!errMsg.isEmpty()) {
if (!m_remoteStderr.isEmpty()) {
if (!m_d->remoteStderr.isEmpty()) {
errMsg += tr("\nRemote error output was: %1")
.arg(QString::fromUtf8(m_remoteStderr));
.arg(QString::fromUtf8(m_d->remoteStderr));
}
emit error(errMsg);
}
stop();
}
void MaemoUsedPortsGatherer::handleRemoteStdOut(const QByteArray &output)
void RemoteLinuxUsedPortsGatherer::handleRemoteStdOut(const QByteArray &output)
{
m_remoteStdout += output;
m_d->remoteStdout += output;
}
void MaemoUsedPortsGatherer::handleRemoteStdErr(const QByteArray &output)
void RemoteLinuxUsedPortsGatherer::handleRemoteStdErr(const QByteArray &output)
{
m_remoteStderr += output;
m_d->remoteStderr += output;
}
} // namespace Internal
} // namespace RemoteLinux
......@@ -28,37 +28,40 @@
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef REMOTELINUXUSEDPORTSGATHERER_H
#define REMOTELINUXUSEDPORTSGATHERER_H
#ifndef MAEMOUSEDPORTSGATHERER_H
#define MAEMOUSEDPORTSGATHERER_H
#include "remotelinux_export.h"
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
QT_FORWARD_DECLARE_CLASS(QString)
namespace Utils {
class SshConnection;
class SshRemoteProcessRunner;
}
} // namespace Utils
namespace RemoteLinux {
class LinuxDeviceConfiguration;
class PortList;
namespace Internal {
class RemoteLinuxUsedPortsGathererPrivate;
} // namespace Internal
class MaemoUsedPortsGatherer : public QObject
class REMOTELINUX_EXPORT RemoteLinuxUsedPortsGatherer : public QObject
{
Q_OBJECT
public:
explicit MaemoUsedPortsGatherer(QObject *parent = 0);
~MaemoUsedPortsGatherer();
explicit RemoteLinuxUsedPortsGatherer(QObject *parent = 0);
~RemoteLinuxUsedPortsGatherer();
void start(const QSharedPointer<Utils::SshConnection> &connection,
const QSharedPointer<const LinuxDeviceConfiguration> &devConf);
void stop();
int getNextFreePort(PortList *freePorts) const; // returns -1 if no more are left
QList<int> usedPorts() const { return m_usedPorts; }
QList<int> usedPorts() const;
signals:
void error(const QString &errMsg);
......@@ -73,14 +76,9 @@ private slots:
private:
void setupUsedPorts();
QSharedPointer<Utils::SshRemoteProcessRunner> m_procRunner;
QList<int> m_usedPorts;
QByteArray m_remoteStdout;
QByteArray m_remoteStderr;
bool m_running;
Internal::RemoteLinuxUsedPortsGathererPrivate * const m_d;
};
} // namespace Internal
} // namespace RemoteLinux
#endif // MAEMOUSEDPORTSGATHERER_H
#endif // REMOTELINUXUSEDPORTSGATHERER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment