forked from qt-creator/qt-creator
Use Utils::Port where possible
This solves the ambiguity between 0 and -1 being the "invalid" port. Change-Id: I3bac11dd4117bb1820fbd58186699925b73df1c5 Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -51,16 +51,16 @@ QString LocalQmlProfilerRunner::findFreeSocket()
|
||||
}
|
||||
}
|
||||
|
||||
quint16 LocalQmlProfilerRunner::findFreePort(QString &host)
|
||||
Utils::Port LocalQmlProfilerRunner::findFreePort(QString &host)
|
||||
{
|
||||
QTcpServer server;
|
||||
if (!server.listen(QHostAddress::LocalHost)
|
||||
&& !server.listen(QHostAddress::LocalHostIPv6)) {
|
||||
qWarning() << "Cannot open port on host for QML profiling.";
|
||||
return 0;
|
||||
return Utils::Port();
|
||||
}
|
||||
host = server.serverAddress().toString();
|
||||
return server.serverPort();
|
||||
return Utils::Port(server.serverPort());
|
||||
}
|
||||
|
||||
LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration,
|
||||
@@ -102,9 +102,12 @@ void LocalQmlProfilerRunner::start()
|
||||
runnable.runMode = ApplicationLauncher::Gui;
|
||||
|
||||
if (QmlProfilerPlugin::debugOutput) {
|
||||
QString portOrSocket = m_configuration.socket.isEmpty() ?
|
||||
QString::number(m_configuration.port.isValid() ?
|
||||
m_configuration.port.number() : -1) :
|
||||
m_configuration.socket;
|
||||
qWarning("QmlProfiler: Launching %s:%s", qPrintable(m_configuration.debuggee.executable),
|
||||
qPrintable(m_configuration.socket.isEmpty() ?
|
||||
QString::number(m_configuration.port) : m_configuration.socket));
|
||||
qPrintable(portOrSocket));
|
||||
}
|
||||
|
||||
connect(&m_launcher, &ApplicationLauncher::processExited,
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "qmlprofiler_global.h"
|
||||
#include <utils/environment.h>
|
||||
#include <utils/port.h>
|
||||
#include <projectexplorer/applicationlauncher.h>
|
||||
#include <projectexplorer/runnables.h>
|
||||
|
||||
@@ -40,14 +41,14 @@ class QMLPROFILER_EXPORT LocalQmlProfilerRunner : public QObject
|
||||
public:
|
||||
struct Configuration {
|
||||
ProjectExplorer::StandardRunnable debuggee;
|
||||
quint16 port;
|
||||
Utils::Port port;
|
||||
QString socket;
|
||||
};
|
||||
|
||||
LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerRunControl *engine);
|
||||
~LocalQmlProfilerRunner();
|
||||
|
||||
static quint16 findFreePort(QString &host);
|
||||
static Utils::Port findFreePort(QString &host);
|
||||
static QString findFreeSocket();
|
||||
|
||||
signals:
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
QString localSocket;
|
||||
QString tcpHost;
|
||||
quint64 tcpPort;
|
||||
Utils::Port tcpPort;
|
||||
QString sysroot;
|
||||
quint32 flushInterval;
|
||||
bool aggregateTraces;
|
||||
@@ -108,7 +108,7 @@ void QmlProfilerClientManager::setAggregateTraces(bool aggregateTraces)
|
||||
d->aggregateTraces = aggregateTraces;
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::setTcpConnection(QString host, quint64 port)
|
||||
void QmlProfilerClientManager::setTcpConnection(QString host, Utils::Port port)
|
||||
{
|
||||
d->tcpHost = host;
|
||||
d->tcpPort = port;
|
||||
@@ -118,7 +118,7 @@ void QmlProfilerClientManager::setTcpConnection(QString host, quint64 port)
|
||||
void QmlProfilerClientManager::setLocalSocket(QString file)
|
||||
{
|
||||
d->localSocket = file;
|
||||
d->tcpPort = 0;
|
||||
d->tcpPort = Utils::Port();
|
||||
connectLocalClient(file);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ void QmlProfilerClientManager::discardPendingData()
|
||||
clearBufferedData();
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::connectTcpClient(quint16 port)
|
||||
void QmlProfilerClientManager::connectTcpClient(Utils::Port port)
|
||||
{
|
||||
if (d->connection) {
|
||||
if (port == d->tcpPort) {
|
||||
@@ -147,7 +147,7 @@ void QmlProfilerClientManager::connectTcpClient(quint16 port)
|
||||
createConnection();
|
||||
d->connectionTimer.start();
|
||||
d->tcpPort = port;
|
||||
d->connection->connectToHost(d->tcpHost, d->tcpPort);
|
||||
d->connection->connectToHost(d->tcpHost, d->tcpPort.number());
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::connectLocalClient(const QString &file)
|
||||
@@ -269,7 +269,7 @@ void QmlProfilerClientManager::tryToConnect()
|
||||
d->connection = 0;
|
||||
connectTcpClient(d->tcpPort);
|
||||
} else if (!d->connection->isConnecting()) {
|
||||
d->connection->connectToHost(d->tcpHost, d->tcpPort);
|
||||
d->connection->connectToHost(d->tcpHost, d->tcpPort.number());
|
||||
}
|
||||
} else if (d->connectionAttempts == 50) {
|
||||
d->connectionTimer.stop();
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "qmlprofilerstatemanager.h"
|
||||
#include <qmldebug/qmlprofilereventlocation.h>
|
||||
#include <utils/port.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
@@ -45,7 +46,7 @@ public:
|
||||
~QmlProfilerClientManager();
|
||||
|
||||
void registerProfilerStateManager(QmlProfilerStateManager *profilerState);
|
||||
void setTcpConnection(QString host, quint64 port);
|
||||
void setTcpConnection(QString host, Utils::Port port);
|
||||
void setLocalSocket(QString file);
|
||||
|
||||
void clearBufferedData();
|
||||
@@ -63,7 +64,7 @@ signals:
|
||||
void connectionClosed();
|
||||
|
||||
public slots:
|
||||
void connectTcpClient(quint16 port);
|
||||
void connectTcpClient(Utils::Port port);
|
||||
void connectLocalClient(const QString &file);
|
||||
void disconnectClient();
|
||||
|
||||
|
||||
@@ -86,15 +86,15 @@ QmlProfilerRunControl::QmlProfilerRunControl(RunConfiguration *runConfiguration,
|
||||
d->m_noDebugOutputTimer.setSingleShot(true);
|
||||
d->m_noDebugOutputTimer.setInterval(4000);
|
||||
connect(&d->m_noDebugOutputTimer, &QTimer::timeout,
|
||||
this, [this](){processIsRunning(0);});
|
||||
this, [this](){processIsRunning(Utils::Port());});
|
||||
|
||||
d->m_outputParser.setNoOutputText(ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput());
|
||||
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort,
|
||||
this, &QmlProfilerRunControl::processIsRunning);
|
||||
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::noOutputMessage,
|
||||
this, [this](){processIsRunning(0);});
|
||||
this, [this](){processIsRunning(Utils::Port());});
|
||||
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::connectingToSocketMessage,
|
||||
this, [this](){processIsRunning(0);});
|
||||
this, [this](){processIsRunning(Utils::Port());});
|
||||
connect(&d->m_outputParser, &QmlDebug::QmlOutputParser::errorMessage,
|
||||
this, &QmlProfilerRunControl::wrongSetupMessageBox);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ void QmlProfilerRunControl::start()
|
||||
QTC_ASSERT(connection().is<AnalyzerConnection>(), finished(); return);
|
||||
auto conn = connection().as<AnalyzerConnection>();
|
||||
|
||||
if (conn.analyzerPort != 0)
|
||||
if (conn.analyzerPort.isValid())
|
||||
emit processRunning(conn.analyzerPort);
|
||||
else if (conn.analyzerSocket.isEmpty())
|
||||
d->m_noDebugOutputTimer.start();
|
||||
@@ -236,19 +236,19 @@ void QmlProfilerRunControl::wrongSetupMessageBoxFinished(int button)
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerRunControl::notifyRemoteSetupDone(quint16 port)
|
||||
void QmlProfilerRunControl::notifyRemoteSetupDone(Utils::Port port)
|
||||
{
|
||||
d->m_noDebugOutputTimer.stop();
|
||||
emit processRunning(port);
|
||||
}
|
||||
|
||||
void QmlProfilerRunControl::processIsRunning(quint16 port)
|
||||
void QmlProfilerRunControl::processIsRunning(Utils::Port port)
|
||||
{
|
||||
d->m_noDebugOutputTimer.stop();
|
||||
|
||||
if (port == 0)
|
||||
if (!port.isValid())
|
||||
port = connection().as<AnalyzerConnection>().analyzerPort;
|
||||
if (port != 0)
|
||||
if (port.isValid())
|
||||
emit processRunning(port);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
void registerProfilerStateManager( QmlProfilerStateManager *profilerState );
|
||||
|
||||
void notifyRemoteSetupDone(quint16 port) override;
|
||||
void notifyRemoteSetupDone(Utils::Port port) override;
|
||||
void start() override;
|
||||
StopResult stop() override;
|
||||
bool isRunning() const override;
|
||||
@@ -54,12 +54,12 @@ public:
|
||||
void logApplicationMessage(const QString &msg, Utils::OutputFormat format) override;
|
||||
|
||||
signals:
|
||||
void processRunning(quint16 port);
|
||||
void processRunning(Utils::Port port);
|
||||
|
||||
private:
|
||||
void wrongSetupMessageBox(const QString &errorMessage);
|
||||
void wrongSetupMessageBoxFinished(int);
|
||||
void processIsRunning(quint16 port);
|
||||
void processIsRunning(Utils::Port port);
|
||||
void profilerStateChanged();
|
||||
|
||||
class QmlProfilerRunControlPrivate;
|
||||
|
||||
@@ -564,7 +564,7 @@ void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc)
|
||||
connection.connParams = device->sshParameters();
|
||||
connection.analyzerHost = device->qmlProfilerHost();
|
||||
}
|
||||
connection.analyzerPort = port;
|
||||
connection.analyzerPort = Utils::Port(port);
|
||||
|
||||
auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc));
|
||||
runControl->setConnection(connection);
|
||||
|
||||
Reference in New Issue
Block a user