diff options
author | Christian Kandeler <christian.kandeler@nokia.com> | 2011-06-22 10:00:50 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@nokia.com> | 2011-06-22 10:34:39 +0200 |
commit | 9197596000763f1d6eed9c2a25b1605a6fbf8347 (patch) | |
tree | ff815de49a329e23f1966ac67613a1b493298b45 /src/plugins | |
parent | b86872e7fdac1dc5d7d32eb54d152a1e9b155ddf (diff) | |
download | qt-creator-9197596000763f1d6eed9c2a25b1605a6fbf8347.tar.gz |
RemoteLinux: Put PortList class into its own set of files.
This also enables us to replace some includes by forward declarations.
Change-Id: Ica98c1925e49c65d15b9e47abe1c4aeba0790482
Reviewed-on: http://codereview.qt.nokia.com/583
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
Diffstat (limited to 'src/plugins')
22 files changed, 290 insertions, 197 deletions
diff --git a/src/plugins/analyzerbase/analyzerruncontrolfactory.cpp b/src/plugins/analyzerbase/analyzerruncontrolfactory.cpp index ddd3eed101..3e7efb81e8 100644 --- a/src/plugins/analyzerbase/analyzerruncontrolfactory.cpp +++ b/src/plugins/analyzerbase/analyzerruncontrolfactory.cpp @@ -41,6 +41,7 @@ #include <projectexplorer/applicationrunconfiguration.h> +#include <remotelinux/linuxdeviceconfiguration.h> #include <remotelinux/remotelinuxrunconfiguration.h> #include <QtCore/QDebug> diff --git a/src/plugins/remotelinux/abstractmaemodeploystep.h b/src/plugins/remotelinux/abstractmaemodeploystep.h index a26520283f..de10559764 100644 --- a/src/plugins/remotelinux/abstractmaemodeploystep.h +++ b/src/plugins/remotelinux/abstractmaemodeploystep.h @@ -34,7 +34,6 @@ #define ABSTRACTMAEMODEPLOYSTEP_H #include "abstractlinuxdevicedeploystep.h" -#include "linuxdeviceconfiguration.h" #include "maemodeployable.h" #include "maemodeployables.h" @@ -53,8 +52,6 @@ namespace Qt4ProjectManager { class Qt4BuildConfiguration; } namespace Utils { class SshConnection; } namespace RemoteLinux { -class LinuxDeviceConfiguration; - namespace Internal { class AbstractMaemoPackageCreationStep; class Qt4MaemoDeployConfiguration; diff --git a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizard.cpp b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizard.cpp index 54b5bbb671..74111352fd 100644 --- a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizard.cpp +++ b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizard.cpp @@ -83,7 +83,7 @@ LinuxDeviceConfiguration::Ptr GenericLinuxDeviceConfigurationWizard::deviceConfi sshParams.privateKeyFile = m_d->setupPage.privateKeyFilePath(); LinuxDeviceConfiguration::Ptr devConf = LinuxDeviceConfiguration::create(m_d->setupPage.configurationName(), LinuxDeviceConfiguration::GenericLinuxOsType, LinuxDeviceConfiguration::Physical, - QLatin1String("10000-10100"), sshParams); + PortList::fromString(QLatin1String("10000-10100")), sshParams); Internal::MaemoConfigTestDialog dlg(devConf, this); dlg.exec(); return devConf; diff --git a/src/plugins/remotelinux/linuxdeviceconfiguration.cpp b/src/plugins/remotelinux/linuxdeviceconfiguration.cpp index 12bf5ba6c1..76f02dad9e 100644 --- a/src/plugins/remotelinux/linuxdeviceconfiguration.cpp +++ b/src/plugins/remotelinux/linuxdeviceconfiguration.cpp @@ -58,141 +58,10 @@ const QLatin1String InternalIdKey("InternalId"); const AuthType DefaultAuthType(Utils::SshConnectionParameters::AuthenticationByKey); const int DefaultTimeout(10); const LinuxDeviceConfiguration::DeviceType DefaultDeviceType(LinuxDeviceConfiguration::Physical); - - -class PortsSpecParser -{ - struct ParseException { - ParseException(const char *error) : error(error) {} - const char * const error; - }; - -public: - PortsSpecParser(const QString &portsSpec) - : m_pos(0), m_portsSpec(portsSpec) { } - - /* - * Grammar: Spec -> [ ElemList ] - * ElemList -> Elem [ ',' ElemList ] - * Elem -> Port [ '-' Port ] - */ - PortList parse() - { - try { - if (!atEnd()) - parseElemList(); - } catch (ParseException &e) { - qWarning("Malformed ports specification: %s", e.error); - } - return m_portList; - } - -private: - void parseElemList() - { - if (atEnd()) - throw ParseException("Element list empty."); - parseElem(); - if (atEnd()) - return; - if (nextChar() != ',') { - throw ParseException("Element followed by something else " - "than a comma."); - } - ++m_pos; - parseElemList(); - } - - void parseElem() - { - const int startPort = parsePort(); - if (atEnd() || nextChar() != '-') { - m_portList.addPort(startPort); - return; - } - ++m_pos; - const int endPort = parsePort(); - if (endPort < startPort) - throw ParseException("Invalid range (end < start)."); - m_portList.addRange(startPort, endPort); - } - - int parsePort() - { - if (atEnd()) - throw ParseException("Empty port string."); - int port = 0; - do { - const char next = nextChar(); - if (!std::isdigit(next)) - break; - port = 10*port + next - '0'; - ++m_pos; - } while (!atEnd()); - if (port == 0 || port >= 2 << 16) - throw ParseException("Invalid port value."); - return port; - } - - bool atEnd() const { return m_pos == m_portsSpec.length(); } - char nextChar() const { return m_portsSpec.at(m_pos).toAscii(); } - - PortList m_portList; - int m_pos; - const QString &m_portsSpec; -}; - } // anonymous namespace -void PortList::addPort(int port) { addRange(port, port); } - -void PortList::addRange(int startPort, int endPort) -{ - m_ranges << Range(startPort, endPort); -} - -bool PortList::hasMore() const { return !m_ranges.isEmpty(); } - -int PortList::count() const -{ - int n = 0; - foreach (const Range &r, m_ranges) - n += r.second - r.first + 1; - return n; -} - -int PortList::getNext() -{ - Q_ASSERT(!m_ranges.isEmpty()); - Range &firstRange = m_ranges.first(); - const int next = firstRange.first++; - if (firstRange.first > firstRange.second) - m_ranges.removeFirst(); - return next; -} - -QString PortList::toString() const -{ - QString stringRep; - foreach (const Range &range, m_ranges) { - stringRep += QString::number(range.first); - if (range.second != range.first) - stringRep += QLatin1Char('-') + QString::number(range.second); - stringRep += QLatin1Char(','); - } - if (!stringRep.isEmpty()) - stringRep.remove(stringRep.length() - 1, 1); // Trailing comma. - return stringRep; -} - -QString PortList::regularExpression() -{ - const QLatin1String portExpr("(\\d)+"); - const QString listElemExpr = QString::fromLatin1("%1(-%1)?").arg(portExpr); - return QString::fromLatin1("((%1)(,%1)*)?").arg(listElemExpr); -} - +LinuxDeviceConfiguration::~LinuxDeviceConfiguration() {} LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QSettings &settings, Id &nextId) @@ -206,17 +75,17 @@ LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const ConstPtr &o } LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QString &name, - const QString &osType, DeviceType deviceType, const QString &freePortsSpec, + const QString &osType, DeviceType deviceType, const PortList &freePorts, const Utils::SshConnectionParameters &sshParams) { - return Ptr(new LinuxDeviceConfiguration(name, osType, deviceType, freePortsSpec, sshParams)); + return Ptr(new LinuxDeviceConfiguration(name, osType, deviceType, freePorts, sshParams)); } LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QString &osType, - DeviceType deviceType, const QString &freePortsSpec, + DeviceType deviceType, const PortList &freePorts, const Utils::SshConnectionParameters &sshParams) : m_sshParameters(sshParams), m_name(name), m_osType(osType), m_type(deviceType), - m_portsSpec(freePortsSpec), m_isDefault(false) + m_freePorts(freePorts), m_isDefault(false) { } @@ -243,7 +112,7 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QSettings &settings, } } - m_portsSpec = settings.value(PortsSpecKey, defaultPortsSpec(m_type)).toString(); + m_freePorts = PortList::fromString(settings.value(PortsSpecKey, QLatin1String("10000-10100")).toString()); m_sshParameters.host = settings.value(HostKey).toString(); m_sshParameters.port = settings.value(SshPortKey, 22).toInt(); m_sshParameters.userName = settings.value(UserNameKey).toString(); @@ -260,17 +129,12 @@ LinuxDeviceConfiguration::LinuxDeviceConfiguration(const LinuxDeviceConfiguratio m_name(other->m_name), m_osType(other->m_osType), m_type(other->type()), - m_portsSpec(other->m_portsSpec), + m_freePorts(other->freePorts()), m_isDefault(other->m_isDefault), m_internalId(other->m_internalId) { } -QString LinuxDeviceConfiguration::defaultPortsSpec(DeviceType type) const -{ - return QLatin1String(type == Physical ? "10000-10100" : "13219,14168"); -} - QString LinuxDeviceConfiguration::defaultPrivateKeyFilePath() { return QDesktopServices::storageLocation(QDesktopServices::HomeLocation) @@ -282,11 +146,6 @@ QString LinuxDeviceConfiguration::defaultPublicKeyFilePath() return defaultPrivateKeyFilePath() + QLatin1String(".pub"); } -PortList LinuxDeviceConfiguration::freePorts() const -{ - return PortsSpecParser(m_portsSpec).parse(); -} - void LinuxDeviceConfiguration::save(QSettings &settings) const { settings.setValue(NameKey, m_name); @@ -294,7 +153,7 @@ void LinuxDeviceConfiguration::save(QSettings &settings) const settings.setValue(TypeKey, m_type); settings.setValue(HostKey, m_sshParameters.host); settings.setValue(SshPortKey, m_sshParameters.port); - settings.setValue(PortsSpecKey, m_portsSpec); + settings.setValue(PortsSpecKey, m_freePorts.toString()); settings.setValue(UserNameKey, m_sshParameters.userName); settings.setValue(AuthKey, m_sshParameters.authenticationType); settings.setValue(PasswordKey, m_sshParameters.password); diff --git a/src/plugins/remotelinux/linuxdeviceconfiguration.h b/src/plugins/remotelinux/linuxdeviceconfiguration.h index 5f35947b18..a03b0f15b6 100644 --- a/src/plugins/remotelinux/linuxdeviceconfiguration.h +++ b/src/plugins/remotelinux/linuxdeviceconfiguration.h @@ -32,11 +32,11 @@ #ifndef LINUXDEVICECONFIGURATION_H #define LINUXDEVICECONFIGURATION_H +#include "portlist.h" #include "remotelinux_export.h" #include <utils/ssh/sshconnection.h> -#include <QtCore/QPair> #include <QtCore/QSharedPointer> #include <QtCore/QString> #include <QtCore/QStringList> @@ -53,24 +53,6 @@ namespace Internal { class LinuxDeviceConfigurations; } -class REMOTELINUX_EXPORT PortList -{ -public: - void addPort(int port); - void addRange(int startPort, int endPort); - bool hasMore() const; - int count() const; - int getNext(); - QString toString() const; - - static QString regularExpression(); - -private: - typedef QPair<int, int> Range; - QList<Range> m_ranges; -}; - - class REMOTELINUX_EXPORT LinuxDeviceConfiguration { friend class Internal::LinuxDeviceConfigurations; @@ -87,13 +69,14 @@ public: enum DeviceType { Physical, Emulator }; - PortList freePorts() const; + ~LinuxDeviceConfiguration(); + + PortList freePorts() const { return m_freePorts; } Utils::SshConnectionParameters sshParameters() const { return m_sshParameters; } QString name() const { return m_name; } void setName(const QString &name) { m_name = name; } QString osType() const { return m_osType; } DeviceType type() const { return m_type; } - QString portsSpec() const { return m_portsSpec; } Id internalId() const { return m_internalId; } bool isDefault() const { return m_isDefault; } @@ -103,10 +86,10 @@ public: static const Id InvalidId; static Ptr create(const QString &name, const QString &osType, DeviceType deviceType, - const QString &freePortsSpec, const Utils::SshConnectionParameters &sshParams); + const PortList &freePorts, const Utils::SshConnectionParameters &sshParams); private: LinuxDeviceConfiguration(const QString &name, const QString &osType, DeviceType deviceType, - const QString &freePortsSpec, const Utils::SshConnectionParameters &sshParams); + const PortList &freePorts, const Utils::SshConnectionParameters &sshParams); LinuxDeviceConfiguration(const QSettings &settings, Id &nextId); LinuxDeviceConfiguration(const ConstPtr &other); @@ -118,13 +101,12 @@ private: static Ptr create(const ConstPtr &other); void save(QSettings &settings) const; - QString defaultPortsSpec(DeviceType type) const; Utils::SshConnectionParameters m_sshParameters; QString m_name; QString m_osType; DeviceType m_type; - QString m_portsSpec; + PortList m_freePorts; bool m_isDefault; Id m_internalId; }; diff --git a/src/plugins/remotelinux/linuxdeviceconfigurations.cpp b/src/plugins/remotelinux/linuxdeviceconfigurations.cpp index d19c685e6b..77a5a2b1af 100644 --- a/src/plugins/remotelinux/linuxdeviceconfigurations.cpp +++ b/src/plugins/remotelinux/linuxdeviceconfigurations.cpp @@ -174,10 +174,10 @@ void LinuxDeviceConfigurations::setSshParameters(int i, m_devConfigs.at(i)->m_sshParameters = params; } -void LinuxDeviceConfigurations::setPortsSpec(int i, const QString &portsSpec) +void LinuxDeviceConfigurations::setFreePorts(int i, const PortList &freePorts) { Q_ASSERT(i >= 0 && i < rowCount()); - m_devConfigs.at(i)->m_portsSpec = portsSpec; + m_devConfigs.at(i)->m_freePorts = freePorts; } void LinuxDeviceConfigurations::setDefaultDevice(int idx) diff --git a/src/plugins/remotelinux/linuxdeviceconfigurations.h b/src/plugins/remotelinux/linuxdeviceconfigurations.h index 4a58954616..2e84c1976d 100644 --- a/src/plugins/remotelinux/linuxdeviceconfigurations.h +++ b/src/plugins/remotelinux/linuxdeviceconfigurations.h @@ -68,7 +68,7 @@ public: void removeConfiguration(int index); void setConfigurationName(int i, const QString &name); void setSshParameters(int i, const Utils::SshConnectionParameters ¶ms); - void setPortsSpec(int i, const QString &portsSpec); + void setFreePorts(int i, const PortList &freePorts); void setDefaultDevice(int index); virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/src/plugins/remotelinux/maemodebugsupport.cpp b/src/plugins/remotelinux/maemodebugsupport.cpp index b532775ec9..6bbd679e6b 100644 --- a/src/plugins/remotelinux/maemodebugsupport.cpp +++ b/src/plugins/remotelinux/maemodebugsupport.cpp @@ -28,7 +28,6 @@ ** Nokia at info@qt.nokia.com. ** **************************************************************************/ - #include "maemodebugsupport.h" #include "maemosshrunner.h" diff --git a/src/plugins/remotelinux/maemodeploymentmounter.cpp b/src/plugins/remotelinux/maemodeploymentmounter.cpp index 1cfd7bc872..a3e3d23dcd 100644 --- a/src/plugins/remotelinux/maemodeploymentmounter.cpp +++ b/src/plugins/remotelinux/maemodeploymentmounter.cpp @@ -67,6 +67,8 @@ MaemoDeploymentMounter::MaemoDeploymentMounter(QObject *parent) SLOT(handlePortListReady())); } +MaemoDeploymentMounter::~MaemoDeploymentMounter() {} + void MaemoDeploymentMounter::setupMounts(const SshConnection::Ptr &connection, const LinuxDeviceConfiguration::ConstPtr &devConf, const QList<MaemoMountSpecification> &mountSpecs, diff --git a/src/plugins/remotelinux/maemodeploymentmounter.h b/src/plugins/remotelinux/maemodeploymentmounter.h index 0ccf09f3de..6ae82e5d2e 100644 --- a/src/plugins/remotelinux/maemodeploymentmounter.h +++ b/src/plugins/remotelinux/maemodeploymentmounter.h @@ -33,8 +33,8 @@ #ifndef MAEMODEPLOYMENTMOUNTER_H #define MAEMODEPLOYMENTMOUNTER_H -#include "linuxdeviceconfiguration.h" #include "maemomountspecification.h" +#include "portlist.h" #include <QtCore/QList> #include <QtCore/QObject> @@ -55,6 +55,7 @@ class MaemoDeploymentMounter : public QObject Q_OBJECT public: explicit MaemoDeploymentMounter(QObject *parent = 0); + ~MaemoDeploymentMounter(); // Connection must be in connected state. void setupMounts(const QSharedPointer<Utils::SshConnection> &connection, diff --git a/src/plugins/remotelinux/maemodeviceconfigurationssettingswidget.cpp b/src/plugins/remotelinux/maemodeviceconfigurationssettingswidget.cpp index f6a5447aab..858a745b7a 100644 --- a/src/plugins/remotelinux/maemodeviceconfigurationssettingswidget.cpp +++ b/src/plugins/remotelinux/maemodeviceconfigurationssettingswidget.cpp @@ -227,7 +227,7 @@ void MaemoDeviceConfigurationsSettingsWidget::fillInValues() const SshConnectionParameters &sshParams = current->sshParameters(); m_ui->hostLineEdit->setText(sshParams.host); m_ui->sshPortSpinBox->setValue(sshParams.port); - m_ui->portsLineEdit->setText(current->portsSpec()); + m_ui->portsLineEdit->setText(current->freePorts().toString()); m_ui->timeoutSpinBox->setValue(sshParams.timeout); m_ui->userLineEdit->setText(sshParams.userName); m_ui->pwdLineEdit->setText(sshParams.password); @@ -325,7 +325,7 @@ void MaemoDeviceConfigurationsSettingsWidget::keyFileEditingFinished() void MaemoDeviceConfigurationsSettingsWidget::handleFreePortsChanged() { - m_devConfigs->setPortsSpec(currentIndex(), m_ui->portsLineEdit->text()); + m_devConfigs->setFreePorts(currentIndex(), PortList::fromString(m_ui->portsLineEdit->text())); updatePortsWarningLabel(); } diff --git a/src/plugins/remotelinux/maemodeviceconfigwizard.cpp b/src/plugins/remotelinux/maemodeviceconfigwizard.cpp index ff28b8627a..5a63e86cf8 100644 --- a/src/plugins/remotelinux/maemodeviceconfigwizard.cpp +++ b/src/plugins/remotelinux/maemodeviceconfigwizard.cpp @@ -626,7 +626,8 @@ LinuxDeviceConfiguration::Ptr MaemoDeviceConfigWizard::deviceConfiguration() doTest = true; } const LinuxDeviceConfiguration::Ptr devConf = LinuxDeviceConfiguration::create(d->wizardData.configName, - d->wizardData.osType, LinuxDeviceConfiguration::Physical, freePortsSpec, sshParams); + d->wizardData.osType, LinuxDeviceConfiguration::Physical, + PortList::fromString(freePortsSpec), sshParams); if (doTest) { MaemoConfigTestDialog dlg(devConf, this); dlg.exec(); diff --git a/src/plugins/remotelinux/maemoqemuruntime.h b/src/plugins/remotelinux/maemoqemuruntime.h index 4fd30394df..ce9088af03 100644 --- a/src/plugins/remotelinux/maemoqemuruntime.h +++ b/src/plugins/remotelinux/maemoqemuruntime.h @@ -32,9 +32,10 @@ #ifndef MAEMOQEMURUNTIME_H #define MAEMOQEMURUNTIME_H -#include "linuxdeviceconfiguration.h" #include "maemoqemusettings.h" +#include <remotelinux/portlist.h> + #include <QtCore/QHash> #include <QtCore/QList> #include <QtCore/QPair> diff --git a/src/plugins/remotelinux/maemoqtversion.h b/src/plugins/remotelinux/maemoqtversion.h index 88ef6723f3..2711a658db 100644 --- a/src/plugins/remotelinux/maemoqtversion.h +++ b/src/plugins/remotelinux/maemoqtversion.h @@ -32,7 +32,6 @@ #ifndef MAEMOQTVERSION_H #define MAEMOQTVERSION_H -#include "linuxdeviceconfiguration.h" #include <qtsupport/baseqtversion.h> namespace RemoteLinux { diff --git a/src/plugins/remotelinux/maemoremotemounter.h b/src/plugins/remotelinux/maemoremotemounter.h index bb9e33cdc6..df53037c53 100644 --- a/src/plugins/remotelinux/maemoremotemounter.h +++ b/src/plugins/remotelinux/maemoremotemounter.h @@ -33,7 +33,6 @@ #ifndef MAEMOREMOTEMOUNTER_H #define MAEMOREMOTEMOUNTER_H -#include "linuxdeviceconfiguration.h" #include "maemomountspecification.h" #include <QtCore/QList> @@ -54,6 +53,7 @@ namespace Qt4ProjectManager { class Qt4BuildConfiguration; } namespace RemoteLinux { class LinuxDeviceConfiguration; +class PortList; namespace Internal { class MaemoUsedPortsGatherer; diff --git a/src/plugins/remotelinux/maemousedportsgatherer.h b/src/plugins/remotelinux/maemousedportsgatherer.h index 6850317cf1..d9d68488ea 100644 --- a/src/plugins/remotelinux/maemousedportsgatherer.h +++ b/src/plugins/remotelinux/maemousedportsgatherer.h @@ -32,8 +32,6 @@ #ifndef MAEMOUSEDPORTSGATHERER_H #define MAEMOUSEDPORTSGATHERER_H -#include "linuxdeviceconfiguration.h" - #include <QtCore/QList> #include <QtCore/QObject> #include <QtCore/QSharedPointer> @@ -46,6 +44,7 @@ class SshRemoteProcessRunner; namespace RemoteLinux { class LinuxDeviceConfiguration; +class PortList; namespace Internal { diff --git a/src/plugins/remotelinux/portlist.cpp b/src/plugins/remotelinux/portlist.cpp new file mode 100644 index 0000000000..ee4c816637 --- /dev/null +++ b/src/plugins/remotelinux/portlist.cpp @@ -0,0 +1,175 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ +#include "portlist.h" + +namespace RemoteLinux { +namespace { + +class PortsSpecParser +{ + struct ParseException { + ParseException(const char *error) : error(error) {} + const char * const error; + }; + +public: + PortsSpecParser(const QString &portsSpec) + : m_pos(0), m_portsSpec(portsSpec) { } + + /* + * Grammar: Spec -> [ ElemList ] + * ElemList -> Elem [ ',' ElemList ] + * Elem -> Port [ '-' Port ] + */ + PortList parse() + { + try { + if (!atEnd()) + parseElemList(); + } catch (ParseException &e) { + qWarning("Malformed ports specification: %s", e.error); + } + return m_portList; + } + +private: + void parseElemList() + { + if (atEnd()) + throw ParseException("Element list empty."); + parseElem(); + if (atEnd()) + return; + if (nextChar() != ',') { + throw ParseException("Element followed by something else " + "than a comma."); + } + ++m_pos; + parseElemList(); + } + + void parseElem() + { + const int startPort = parsePort(); + if (atEnd() || nextChar() != '-') { + m_portList.addPort(startPort); + return; + } + ++m_pos; + const int endPort = parsePort(); + if (endPort < startPort) + throw ParseException("Invalid range (end < start)."); + m_portList.addRange(startPort, endPort); + } + + int parsePort() + { + if (atEnd()) + throw ParseException("Empty port string."); + int port = 0; + do { + const char next = nextChar(); + if (!std::isdigit(next)) + break; + port = 10*port + next - '0'; + ++m_pos; + } while (!atEnd()); + if (port == 0 || port >= 2 << 16) + throw ParseException("Invalid port value."); + return port; + } + + bool atEnd() const { return m_pos == m_portsSpec.length(); } + char nextChar() const { return m_portsSpec.at(m_pos).toAscii(); } + + PortList m_portList; + int m_pos; + const QString &m_portsSpec; +}; + +} // anonymous namespace + + +PortList PortList::fromString(const QString &portsSpec) +{ + return PortsSpecParser(portsSpec).parse(); +} + +void PortList::addPort(int port) { addRange(port, port); } + +void PortList::addRange(int startPort, int endPort) +{ + m_ranges << Range(startPort, endPort); +} + +bool PortList::hasMore() const { return !m_ranges.isEmpty(); } + +int PortList::count() const +{ + int n = 0; + foreach (const Range &r, m_ranges) + n += r.second - r.first + 1; + return n; +} + +int PortList::getNext() +{ + Q_ASSERT(!m_ranges.isEmpty()); + Range &firstRange = m_ranges.first(); + const int next = firstRange.first++; + if (firstRange.first > firstRange.second) + m_ranges.removeFirst(); + return next; +} + +QString PortList::toString() const +{ + QString stringRep; + foreach (const Range &range, m_ranges) { + stringRep += QString::number(range.first); + if (range.second != range.first) + stringRep += QLatin1Char('-') + QString::number(range.second); + stringRep += QLatin1Char(','); + } + if (!stringRep.isEmpty()) + stringRep.remove(stringRep.length() - 1, 1); // Trailing comma. + return stringRep; +} + +QString PortList::regularExpression() +{ + const QLatin1String portExpr("(\\d)+"); + const QString listElemExpr = QString::fromLatin1("%1(-%1)?").arg(portExpr); + return QString::fromLatin1("((%1)(,%1)*)?").arg(listElemExpr); +} + +} // namespace RemoteLinux diff --git a/src/plugins/remotelinux/portlist.h b/src/plugins/remotelinux/portlist.h new file mode 100644 index 0000000000..60f71b82f9 --- /dev/null +++ b/src/plugins/remotelinux/portlist.h @@ -0,0 +1,62 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ +#ifndef PORTLIST_H +#define PORTLIST_H + +#include "remotelinux_export.h" + +#include <QtCore/QPair> +#include <QtCore/QString> + +namespace RemoteLinux { + +class REMOTELINUX_EXPORT PortList +{ +public: + void addPort(int port); + void addRange(int startPort, int endPort); + bool hasMore() const; + int count() const; + int getNext(); + QString toString() const; + + static PortList fromString(const QString &portsSpec); + static QString regularExpression(); + +private: + typedef QPair<int, int> Range; + QList<Range> m_ranges; +}; + +} // namespace RemoteLinux + +#endif // PORTLIST_H diff --git a/src/plugins/remotelinux/remotelinux.pro b/src/plugins/remotelinux/remotelinux.pro index 6b0a7b6a28..268bf3503d 100644 --- a/src/plugins/remotelinux/remotelinux.pro +++ b/src/plugins/remotelinux/remotelinux.pro @@ -84,7 +84,8 @@ HEADERS += \ remotelinuxruncontrol.h \ remotelinuxruncontrolfactory.h \ remotelinuxdebugsupport.h \ - genericlinuxdeviceconfigurationwizardpages.h + genericlinuxdeviceconfigurationwizardpages.h \ + portlist.h SOURCES += \ remotelinuxplugin.cpp \ @@ -160,7 +161,8 @@ SOURCES += \ remotelinuxruncontrol.cpp \ remotelinuxruncontrolfactory.cpp \ remotelinuxdebugsupport.cpp \ - genericlinuxdeviceconfigurationwizardpages.cpp + genericlinuxdeviceconfigurationwizardpages.cpp \ + portlist.cpp FORMS += \ maemoconfigtestdialog.ui \ diff --git a/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp b/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp index 02cb92e9bc..57ecf01e0a 100644 --- a/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp +++ b/src/plugins/remotelinux/remotelinuxapplicationrunner.cpp @@ -31,6 +31,7 @@ #include "remotelinuxapplicationrunner.h" +#include "linuxdeviceconfiguration.h" #include "maemoglobal.h" #include "remotelinuxrunconfiguration.h" #include "maemousedportsgatherer.h" @@ -71,6 +72,16 @@ RemoteLinuxApplicationRunner::RemoteLinuxApplicationRunner(QObject *parent, RemoteLinuxApplicationRunner::~RemoteLinuxApplicationRunner() {} +SshConnection::Ptr RemoteLinuxApplicationRunner::connection() const +{ + return m_connection; +} + +LinuxDeviceConfiguration::ConstPtr RemoteLinuxApplicationRunner::devConfig() const +{ + return m_devConfig; +} + void RemoteLinuxApplicationRunner::start() { QTC_ASSERT(!m_stopRequested, return); diff --git a/src/plugins/remotelinux/remotelinuxapplicationrunner.h b/src/plugins/remotelinux/remotelinuxapplicationrunner.h index 12a1bd599d..124b4dc7e9 100644 --- a/src/plugins/remotelinux/remotelinuxapplicationrunner.h +++ b/src/plugins/remotelinux/remotelinuxapplicationrunner.h @@ -32,7 +32,7 @@ #ifndef REMOTELINUXAPPLICATIONRUNNER_H #define REMOTELINUXAPPLICATIONRUNNER_H -#include "linuxdeviceconfiguration.h" +#include "portlist.h" #include "remotelinux_export.h" #include <QtCore/QObject> @@ -45,6 +45,7 @@ class SshRemoteProcess; } namespace RemoteLinux { +class LinuxDeviceConfiguration; class RemoteLinuxRunConfiguration; namespace Internal { class MaemoUsedPortsGatherer; } @@ -61,13 +62,13 @@ public: void startExecution(const QByteArray &remoteCall); - QSharedPointer<Utils::SshConnection> connection() const { return m_connection; } + QSharedPointer<Utils::SshConnection> connection() const; const Internal::MaemoUsedPortsGatherer *usedPortsGatherer() const { return m_portsGatherer; } PortList *freePorts() { return &m_freePorts; } QString remoteExecutable() const { return m_remoteExecutable; } QString arguments() const { return m_appArguments; } QString commandPrefix() const { return m_commandPrefix; } - const QSharedPointer<const LinuxDeviceConfiguration> devConfig() const { return m_devConfig; } + QSharedPointer<const LinuxDeviceConfiguration> devConfig() const; static const qint64 InvalidExitCode; diff --git a/src/plugins/remotelinux/remotelinuxrunconfiguration.h b/src/plugins/remotelinux/remotelinuxrunconfiguration.h index eaac5bfe84..b478e66b0b 100644 --- a/src/plugins/remotelinux/remotelinuxrunconfiguration.h +++ b/src/plugins/remotelinux/remotelinuxrunconfiguration.h @@ -33,9 +33,9 @@ #ifndef REMOTELINUXRUNCONFIGURATION_H #define REMOTELINUXRUNCONFIGURATION_H -#include "linuxdeviceconfiguration.h" #include "maemoconstants.h" #include "maemodeployable.h" +#include "portlist.h" #include "remotelinux_export.h" #include <utils/environment.h> @@ -55,6 +55,7 @@ class Qt4ProFileNode; } // namespace Qt4ProjectManager namespace RemoteLinux { +class LinuxDeviceConfiguration; class RemoteLinuxRunConfigurationWidget; namespace Internal { |