QmlDebugging: Query available port

Use QTcpServer instead of TcpPortsGatherer.

Change-Id: I85133c5ae192b407009c5b21df332c9d3d94acda
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Reviewed-by: Aurindam Jana <aurindam.jana@digia.com>
This commit is contained in:
Aurindam Jana
2013-04-17 17:45:53 +02:00
parent 49f1cd5334
commit f9d2b6498f
2 changed files with 13 additions and 20 deletions

View File

@@ -56,11 +56,10 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/portlist.h>
#include <utils/tcpportsgatherer.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QErrorMessage> #include <QErrorMessage>
#include <QTcpServer>
using namespace Debugger::Internal; using namespace Debugger::Internal;
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -385,18 +384,14 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
DeviceKitInformation::device(runConfiguration->target()->kit()); DeviceKitInformation::device(runConfiguration->target()->kit());
sp.qmlServerAddress = _("127.0.0.1"); sp.qmlServerAddress = _("127.0.0.1");
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return sp); QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return sp);
TcpPortsGatherer portsGatherer; QTcpServer server;
portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol); const bool canListen = server.listen(QHostAddress(sp.qmlServerAddress));
Utils::PortList portList = device->freePorts(); if (!canListen) {
int freePort = portsGatherer.getNextFreePort(&portList);
if (freePort == -1) {
if (errorMessage) if (errorMessage)
*errorMessage = DebuggerPlugin::tr("Not enough free ports for QML debugging. " *errorMessage = DebuggerPlugin::tr("Not enough free ports for QML debugging. ");
"Increase the port range for Desktop device in "
"Device settings.");
return sp; return sp;
} }
sp.qmlServerPort = freePort; sp.qmlServerPort = server.serverPort();
sp.languages |= QmlLanguage; sp.languages |= QmlLanguage;
// Makes sure that all bindings go through the JavaScript engine, so that // Makes sure that all bindings go through the JavaScript engine, so that

View File

@@ -37,7 +37,6 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/tcpportsgatherer.h>
#include <debugger/debuggerrunner.h> #include <debugger/debuggerrunner.h>
#include <debugger/debuggerplugin.h> #include <debugger/debuggerplugin.h>
@@ -47,6 +46,8 @@
#include <qmlprojectmanager/qmlprojectplugin.h> #include <qmlprojectmanager/qmlprojectplugin.h>
#include <QTcpServer>
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace QmlProjectManager { namespace QmlProjectManager {
@@ -219,17 +220,14 @@ RunControl *QmlProjectRunControlFactory::createDebugRunControl(QmlProjectRunConf
DeviceKitInformation::device(runConfig->target()->kit()); DeviceKitInformation::device(runConfig->target()->kit());
params.qmlServerAddress = QLatin1String("127.0.0.1"); params.qmlServerAddress = QLatin1String("127.0.0.1");
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0); QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);
Utils::TcpPortsGatherer portsGatherer; QTcpServer server;
portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol); const bool canListen = server.listen(QHostAddress(params.qmlServerAddress));
Utils::PortList portList = device->freePorts(); if (!canListen) {
int freePort = portsGatherer.getNextFreePort(&portList);
if (freePort == -1) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("Not enough free ports for QML debugging. Increase the " *errorMessage = tr("Not enough free ports for QML debugging. ");
"port range for Desktop device in Device settings.");
return 0; return 0;
} }
params.qmlServerPort = freePort; params.qmlServerPort = server.serverPort();
params.languages |= Debugger::QmlLanguage; params.languages |= Debugger::QmlLanguage;
// Makes sure that all bindings go through the JavaScript engine, so that // Makes sure that all bindings go through the JavaScript engine, so that