forked from qt-creator/qt-creator
DeviceUsedPortsGatherer: Move getNextFreePort() into PortList
Seems more natural place for this function. Change-Id: I09f6776ce946f623e3a512411bb922841c06a47d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -168,6 +168,16 @@ Port PortList::getNext()
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Port PortList::getNextFreePort(const QList<Port> &usedPorts)
|
||||||
|
{
|
||||||
|
while (hasMore()) {
|
||||||
|
const Port port = getNext();
|
||||||
|
if (!usedPorts.contains(port))
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
QString PortList::toString() const
|
QString PortList::toString() const
|
||||||
{
|
{
|
||||||
QString stringRep;
|
QString stringRep;
|
||||||
|
@@ -28,6 +28,7 @@ public:
|
|||||||
bool contains(Port port) const;
|
bool contains(Port port) const;
|
||||||
int count() const;
|
int count() const;
|
||||||
Port getNext();
|
Port getNext();
|
||||||
|
Port getNextFreePort(const QList<Port> &usedPorts);
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
static PortList fromString(const QString &portsSpec);
|
static PortList fromString(const QString &portsSpec);
|
||||||
|
@@ -77,16 +77,6 @@ void DeviceUsedPortsGatherer::stop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Port DeviceUsedPortsGatherer::getNextFreePort(PortList *freePorts) const
|
|
||||||
{
|
|
||||||
while (freePorts->hasMore()) {
|
|
||||||
const Port port = freePorts->getNext();
|
|
||||||
if (!d->usedPorts.contains(port))
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
return Port();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Port> DeviceUsedPortsGatherer::usedPorts() const
|
QList<Port> DeviceUsedPortsGatherer::usedPorts() const
|
||||||
{
|
{
|
||||||
return d->usedPorts;
|
return d->usedPorts;
|
||||||
@@ -165,7 +155,7 @@ QUrl PortsGatherer::findEndPoint()
|
|||||||
QUrl result;
|
QUrl result;
|
||||||
result.setScheme(urlTcpScheme());
|
result.setScheme(urlTcpScheme());
|
||||||
result.setHost(device()->sshParameters().host());
|
result.setHost(device()->sshParameters().host());
|
||||||
result.setPort(m_portsGatherer.getNextFreePort(&m_portList).number());
|
result.setPort(m_portList.getNextFreePort(m_portsGatherer.usedPorts()).number());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,6 @@ public:
|
|||||||
|
|
||||||
void start(const IDeviceConstPtr &device);
|
void start(const IDeviceConstPtr &device);
|
||||||
void stop();
|
void stop();
|
||||||
Utils::Port getNextFreePort(Utils::PortList *freePorts) const; // returns -1 if no more are left
|
|
||||||
QList<Utils::Port> usedPorts() const;
|
QList<Utils::Port> usedPorts() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Reference in New Issue
Block a user