summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/ios/iosconstants.h6
-rw-r--r--src/plugins/ios/iosdevice.cpp27
-rw-r--r--src/plugins/ios/iosdevice.h3
-rw-r--r--src/plugins/ios/iossimulator.cpp38
-rw-r--r--src/plugins/ios/iossimulator.h3
5 files changed, 71 insertions, 6 deletions
diff --git a/src/plugins/ios/iosconstants.h b/src/plugins/ios/iosconstants.h
index 3bdab989eb..ebba0b0b59 100644
--- a/src/plugins/ios/iosconstants.h
+++ b/src/plugins/ios/iosconstants.h
@@ -55,6 +55,12 @@ const char IOS_DEVICE_TYPE[] = "Ios.Device.Type";
const char IOS_SIMULATOR_TYPE[] = "Ios.Simulator.Type";
const char IOS_DEVICE_ID[] = "iOS Device ";
const char IOS_SIMULATOR_DEVICE_ID[] = "iOS Simulator Device ";
+
+const quint16 IOS_DEVICE_PORT_START = 30000;
+const quint16 IOS_DEVICE_PORT_END = 31000;
+const quint16 IOS_SIMULATOR_PORT_START = 30000;
+const quint16 IOS_SIMULATOR_PORT_END = 31000;
+
} // namespace Constants;
} // namespace Ios
diff --git a/src/plugins/ios/iosdevice.cpp b/src/plugins/ios/iosdevice.cpp
index 9dda6e05d2..7a79bcbb27 100644
--- a/src/plugins/ios/iosdevice.cpp
+++ b/src/plugins/ios/iosdevice.cpp
@@ -34,6 +34,7 @@
#include <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/kitinformation.h>
#include <coreplugin/helpmanager.h>
+#include <utils/portlist.h>
#include <QCoreApplication>
#include <QVariant>
@@ -84,21 +85,28 @@ IosDevice::IosDevice()
: IDevice(Core::Id(Constants::IOS_DEVICE_TYPE),
IDevice::AutoDetected,
IDevice::Hardware,
- Constants::IOS_DEVICE_ID)
+ Constants::IOS_DEVICE_ID),
+ m_lastPort(Constants::IOS_DEVICE_PORT_START)
{
setDisplayName(IosDevice::name());
setDeviceState(DeviceDisconnected);
+ Utils::PortList ports;
+ ports.addRange(Constants::IOS_DEVICE_PORT_START,
+ Constants::IOS_DEVICE_PORT_END);
+ setFreePorts(ports);
}
IosDevice::IosDevice(const IosDevice &other)
- : IDevice(other), m_extraInfo(other.m_extraInfo), m_ignoreDevice(other.m_ignoreDevice)
+ : IDevice(other), m_extraInfo(other.m_extraInfo), m_ignoreDevice(other.m_ignoreDevice),
+ m_lastPort(other.m_lastPort)
{ }
IosDevice::IosDevice(const QString &uid)
: IDevice(Core::Id(Constants::IOS_DEVICE_TYPE),
IDevice::AutoDetected,
IDevice::Hardware,
- Core::Id(Constants::IOS_DEVICE_ID).withSuffix(uid))
+ Core::Id(Constants::IOS_DEVICE_ID).withSuffix(uid)),
+ m_lastPort(Constants::IOS_DEVICE_PORT_START)
{
setDisplayName(IosDevice::name());
setDeviceState(DeviceDisconnected);
@@ -195,6 +203,19 @@ QString IosDevice::osVersion() const
return m_extraInfo.value(QLatin1String("osVersion"));
}
+quint16 IosDevice::nextPort() const
+{
+ // use qrand instead?
+ if (++m_lastPort >= Constants::IOS_DEVICE_PORT_END)
+ m_lastPort = Constants::IOS_DEVICE_PORT_START;
+ return m_lastPort;
+}
+
+bool IosDevice::canAutoDetectPorts() const
+{
+ return true;
+}
+
// IosDeviceManager
diff --git a/src/plugins/ios/iosdevice.h b/src/plugins/ios/iosdevice.h
index 12d11b0c37..10ff7cc97f 100644
--- a/src/plugins/ios/iosdevice.h
+++ b/src/plugins/ios/iosdevice.h
@@ -71,6 +71,8 @@ public:
QString uniqueDeviceID() const;
IosDevice(const QString &uid);
QString osVersion() const;
+ quint16 nextPort() const;
+ bool canAutoDetectPorts() const QTC_OVERRIDE;
static QString name();
@@ -81,6 +83,7 @@ protected:
IosDevice(const IosDevice &other);
Dict m_extraInfo;
bool m_ignoreDevice;
+ mutable quint16 m_lastPort;
};
class IosDeviceManager : public QObject {
diff --git a/src/plugins/ios/iossimulator.cpp b/src/plugins/ios/iossimulator.cpp
index 792acc871d..f647438d67 100644
--- a/src/plugins/ios/iossimulator.cpp
+++ b/src/plugins/ios/iossimulator.cpp
@@ -33,6 +33,7 @@
#include <projectexplorer/kitinformation.h>
#include <QCoreApplication>
+#include <QProcess>
using namespace ProjectExplorer;
@@ -46,7 +47,8 @@ IosSimulator::IosSimulator(Core::Id id, Utils::FileName simulatorPath)
IDevice::AutoDetected,
IDevice::Emulator,
id),
- m_simulatorPath(simulatorPath)
+ m_simulatorPath(simulatorPath),
+ m_lastPort(Constants::IOS_SIMULATOR_PORT_START)
{
setDisplayName(QCoreApplication::translate("Ios::Internal::IosSimulator", "iOS Simulator"));
setDeviceState(DeviceReadyToUse);
@@ -56,14 +58,15 @@ IosSimulator::IosSimulator()
: IDevice(Core::Id(Constants::IOS_SIMULATOR_TYPE),
IDevice::AutoDetected,
IDevice::Emulator,
- Core::Id(Constants::IOS_SIMULATOR_DEVICE_ID))
+ Core::Id(Constants::IOS_SIMULATOR_DEVICE_ID)),
+ m_lastPort(Constants::IOS_SIMULATOR_PORT_START)
{
setDisplayName(QCoreApplication::translate("Ios::Internal::IosSimulator", "iOS Simulator"));
setDeviceState(DeviceReadyToUse);
}
IosSimulator::IosSimulator(const IosSimulator &other)
- : IDevice(other)
+ : IDevice(other), m_lastPort(other.m_lastPort)
{
setDisplayName(QCoreApplication::translate("Ios::Internal::IosSimulator", "iOS Simulator"));
setDeviceState(DeviceReadyToUse);
@@ -131,6 +134,35 @@ QVariantMap IosSimulator::toMap() const
return res;
}
+quint16 IosSimulator::nextPort() const
+{
+ for (int i = 0; i < 100; ++i) {
+ // use qrand instead?
+ if (++m_lastPort >= Constants::IOS_SIMULATOR_PORT_END)
+ m_lastPort = Constants::IOS_SIMULATOR_PORT_START;
+ QProcess portVerifier;
+ // this is a bit too broad (it does not check just listening sockets, but also connections
+ // to that port from this computer)
+ portVerifier.start(QLatin1String("lsof"), QStringList() << QLatin1String("-n")
+ << QLatin1String("-P") << QLatin1String("-i")
+ << QString::fromLatin1(":%1").arg(m_lastPort));
+ if (!portVerifier.waitForStarted())
+ break;
+ portVerifier.closeWriteChannel();
+ if (!portVerifier.waitForFinished())
+ break;
+ if (portVerifier.exitStatus() != QProcess::NormalExit
+ || portVerifier.exitCode() != 0)
+ break;
+ }
+ return m_lastPort;
+}
+
+bool IosSimulator::canAutoDetectPorts() const
+{
+ return true;
+}
+
IosSimulator::ConstPtr IosKitInformation::simulator(Kit *kit)
{
if (!kit)
diff --git a/src/plugins/ios/iossimulator.h b/src/plugins/ios/iossimulator.h
index e34125461b..0fee860250 100644
--- a/src/plugins/ios/iossimulator.h
+++ b/src/plugins/ios/iossimulator.h
@@ -57,6 +57,8 @@ public:
Utils::FileName simulatorPath() const;
void fromMap(const QVariantMap &map) QTC_OVERRIDE;
QVariantMap toMap() const QTC_OVERRIDE;
+ quint16 nextPort() const;
+ bool canAutoDetectPorts() const QTC_OVERRIDE;
ProjectExplorer::IDevice::Ptr clone() const QTC_OVERRIDE;
@@ -68,6 +70,7 @@ protected:
IosSimulator(const IosSimulator &other);
private:
Utils::FileName m_simulatorPath;
+ mutable quint16 m_lastPort;
};
namespace IosKitInformation {