diff --git a/src/plugins/remotelinux/linuxdevicetester.cpp b/src/plugins/remotelinux/linuxdevicetester.cpp index 3c0c6c98a27..78d0875eb74 100644 --- a/src/plugins/remotelinux/linuxdevicetester.cpp +++ b/src/plugins/remotelinux/linuxdevicetester.cpp @@ -32,7 +32,7 @@ #include "linuxdevicetester.h" #include "linuxdeviceconfiguration.h" -#include "maemousedportsgatherer.h" +#include "remotelinuxusedportsgatherer.h" #include #include @@ -56,7 +56,7 @@ public: LinuxDeviceConfiguration::ConstPtr deviceConfiguration; SshConnection::Ptr connection; SshRemoteProcess::Ptr process; - MaemoUsedPortsGatherer portsGatherer; + RemoteLinuxUsedPortsGatherer portsGatherer; QByteArray remoteStdout; QByteArray remoteStderr; State state; diff --git a/src/plugins/remotelinux/maemodeploymentmounter.cpp b/src/plugins/remotelinux/maemodeploymentmounter.cpp index 9ee24742fe3..a0705416b94 100644 --- a/src/plugins/remotelinux/maemodeploymentmounter.cpp +++ b/src/plugins/remotelinux/maemodeploymentmounter.cpp @@ -34,9 +34,10 @@ #include "maemoglobal.h" #include "maemoremotemounter.h" -#include "maemousedportsgatherer.h" #include +#include +#include #include #include @@ -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())); diff --git a/src/plugins/remotelinux/maemodeploymentmounter.h b/src/plugins/remotelinux/maemodeploymentmounter.h index 6ae82e5d2ea..aac42add035 100644 --- a/src/plugins/remotelinux/maemodeploymentmounter.h +++ b/src/plugins/remotelinux/maemodeploymentmounter.h @@ -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 m_connection; QSharedPointer m_devConf; MaemoRemoteMounter * const m_mounter; - MaemoUsedPortsGatherer * const m_portsGatherer; + RemoteLinuxUsedPortsGatherer * const m_portsGatherer; PortList m_freePorts; QList m_mountSpecs; const Qt4ProjectManager::Qt4BuildConfiguration *m_buildConfig; diff --git a/src/plugins/remotelinux/maemoremotemounter.cpp b/src/plugins/remotelinux/maemoremotemounter.cpp index 4fba5863653..d84be8abb83 100644 --- a/src/plugins/remotelinux/maemoremotemounter.cpp +++ b/src/plugins/remotelinux/maemoremotemounter.cpp @@ -33,13 +33,14 @@ #include "maemoremotemounter.h" #include "maemoglobal.h" -#include "maemousedportsgatherer.h" #include "qt4maemotarget.h" #include #include #include #include +#include +#include #include #include @@ -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); diff --git a/src/plugins/remotelinux/maemoremotemounter.h b/src/plugins/remotelinux/maemoremotemounter.h index df53037c53c..324ba281a59 100644 --- a/src/plugins/remotelinux/maemoremotemounter.h +++ b/src/plugins/remotelinux/maemoremotemounter.h @@ -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; diff --git a/src/plugins/remotelinux/remotelinux.pro b/src/plugins/remotelinux/remotelinux.pro index 95923694a6f..4cba01a4be2 100644 --- a/src/plugins/remotelinux/remotelinux.pro +++ b/src/plugins/remotelinux/remotelinux.pro @@ -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 \ diff --git a/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp b/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp index ee49cf45a11..ad2288606b0 100644 --- a/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp +++ b/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp @@ -33,7 +33,7 @@ #include "linuxdeviceconfiguration.h" #include "remotelinuxrunconfiguration.h" -#include "maemousedportsgatherer.h" +#include "remotelinuxusedportsgatherer.h" #include #include @@ -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; } diff --git a/src/plugins/remotelinux/remotelinuxapplicationrunner.h b/src/plugins/remotelinux/remotelinuxapplicationrunner.h index 15fda4c09ee..ca09c87a2aa 100644 --- a/src/plugins/remotelinux/remotelinuxapplicationrunner.h +++ b/src/plugins/remotelinux/remotelinuxapplicationrunner.h @@ -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 connection() const; QSharedPointer devConfig() const; - const Internal::MaemoUsedPortsGatherer *usedPortsGatherer() const; + const RemoteLinuxUsedPortsGatherer *usedPortsGatherer() const; PortList *freePorts(); QString remoteExecutable() const; QString arguments() const; diff --git a/src/plugins/remotelinux/remotelinuxdebugsupport.cpp b/src/plugins/remotelinux/remotelinuxdebugsupport.cpp index 98836587d4f..ff4368ac997 100644 --- a/src/plugins/remotelinux/remotelinuxdebugsupport.cpp +++ b/src/plugins/remotelinux/remotelinuxdebugsupport.cpp @@ -32,9 +32,9 @@ #include "remotelinuxdebugsupport.h" #include "linuxdeviceconfiguration.h" -#include "maemousedportsgatherer.h" #include "qt4maemotarget.h" #include "remotelinuxapplicationrunner.h" +#include "remotelinuxusedportsgatherer.h" #include #include diff --git a/src/plugins/remotelinux/maemousedportsgatherer.cpp b/src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp similarity index 53% rename from src/plugins/remotelinux/maemousedportsgatherer.cpp rename to src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp index c72371989c1..22f95c6889a 100644 --- a/src/plugins/remotelinux/maemousedportsgatherer.cpp +++ b/src/plugins/remotelinux/remotelinuxusedportsgatherer.cpp @@ -28,82 +28,103 @@ ** Nokia at info@qt.nokia.com. ** **************************************************************************/ +#include "remotelinuxusedportsgatherer.h" -#include "maemousedportsgatherer.h" - -#include "maemoglobal.h" +#include "linuxdeviceconfiguration.h" #include +#include + 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 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 RemoteLinuxUsedPortsGatherer::usedPorts() const { - const QList &portStrings = m_remoteStdout.split('\n'); + return m_d->usedPorts; +} + +void RemoteLinuxUsedPortsGatherer::setupUsedPorts() +{ + const QList &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 diff --git a/src/plugins/remotelinux/maemousedportsgatherer.h b/src/plugins/remotelinux/remotelinuxusedportsgatherer.h similarity index 80% rename from src/plugins/remotelinux/maemousedportsgatherer.h rename to src/plugins/remotelinux/remotelinuxusedportsgatherer.h index d9d68488eaf..2bf42d09c9a 100644 --- a/src/plugins/remotelinux/maemousedportsgatherer.h +++ b/src/plugins/remotelinux/remotelinuxusedportsgatherer.h @@ -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 #include #include -#include + +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 &connection, const QSharedPointer &devConf); void stop(); int getNextFreePort(PortList *freePorts) const; // returns -1 if no more are left - QList usedPorts() const { return m_usedPorts; } + QList usedPorts() const; signals: void error(const QString &errMsg); @@ -73,14 +76,9 @@ private slots: private: void setupUsedPorts(); - QSharedPointer m_procRunner; - QList 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