Commit 0db9d98d authored by Fawzi Mohamed's avatar Fawzi Mohamed

ios: adding port information to ios devices

Change-Id: I0243735159b02ac4afaf3d14ecb20381439a3997
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 01715c61
......@@ -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
......
......@@ -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
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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 {
......
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