From 81eea72d44531107ace4ae4a3c525ff6b9cd23cc Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 16 Nov 2015 17:29:17 +0100 Subject: [PATCH] QmlDebug: Simplify error and state signaling There is no point in sending two signals for every state change and error. Also, the signals only reflect events in the socket, not in the logical connection. Change-Id: I617a925c69164aa1a02a7781b9da7dca55daa304 Reviewed-by: Joerg Bornemann --- src/libs/qmldebug/qmldebugclient.cpp | 78 ++++++++----------- src/libs/qmldebug/qmldebugclient.h | 15 ++-- src/plugins/debugger/qml/qmlengine.cpp | 22 +++--- src/plugins/debugger/qml/qmlengine.h | 6 +- .../qmlprofiler/qmlprofilerclientmanager.cpp | 18 +++-- .../qmlprofiler/qmlprofilerclientmanager.h | 5 +- 6 files changed, 64 insertions(+), 80 deletions(-) diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp index a0af7a6518..6bbe091c5b 100644 --- a/src/libs/qmldebug/qmldebugclient.cpp +++ b/src/libs/qmldebug/qmldebugclient.cpp @@ -75,11 +75,40 @@ public: public slots: void connected(); void disconnected(); - void error(QAbstractSocket::SocketError error); void readyRead(); - void stateChanged(QAbstractSocket::SocketState state); }; +QString QmlDebugConnection::socketStateToString(QAbstractSocket::SocketState state) +{ + switch (state) { + case QAbstractSocket::UnconnectedState: + return tr("Network connection dropped"); + case QAbstractSocket::HostLookupState: + return tr("Resolving host"); + case QAbstractSocket::ConnectingState: + return tr("Establishing network connection ..."); + case QAbstractSocket::ConnectedState: + return tr("Network connection established"); + case QAbstractSocket::ClosingState: + return tr("Network connection closing"); + case QAbstractSocket::BoundState: + return tr("Socket state changed to BoundState. This should not happen!"); + case QAbstractSocket::ListeningState: + return tr("Socket state changed to ListeningState. This should not happen!"); + default: + return tr("Unknown state %1").arg(state); + } +} + +QString QmlDebugConnection::socketErrorToString(QAbstractSocket::SocketError error) +{ + if (error == QAbstractSocket::RemoteHostClosedError) { + return tr("Error: Remote host closed the connection"); + } else { + return tr("Error: Unknown socket error %1").arg(error); + } +} + QmlDebugConnectionPrivate::QmlDebugConnectionPrivate(QmlDebugConnection *c) : QObject(c), q(c), protocol(0), device(0), gotHello(false), currentDataStreamVersion(QDataStream::Qt_4_7), @@ -124,17 +153,6 @@ void QmlDebugConnectionPrivate::disconnected() } } -void QmlDebugConnectionPrivate::error(QAbstractSocket::SocketError socketError) -{ - //: %1=error code, %2=error message - emit q->errorMessage(tr("Error: (%1) %2").arg(socketError) - .arg(device ? device->errorString() : tr(""))); - if (socketError == QAbstractSocket::RemoteHostClosedError) - emit q->error(QDebugSupport::RemoteClosedConnectionError); - else - emit q->error(QDebugSupport::UnknownError); -} - void QmlDebugConnectionPrivate::readyRead() { if (!gotHello) { @@ -252,33 +270,6 @@ void QmlDebugConnectionPrivate::readyRead() } } -void QmlDebugConnectionPrivate::stateChanged(QAbstractSocket::SocketState state) -{ - switch (state) { - case QAbstractSocket::UnconnectedState: - emit q->stateMessage(tr("Network connection dropped")); - break; - case QAbstractSocket::HostLookupState: - emit q->stateMessage(tr("Resolving host")); - break; - case QAbstractSocket::ConnectingState: - emit q->stateMessage(tr("Establishing network connection ...")); - break; - case QAbstractSocket::ConnectedState: - emit q->stateMessage(tr("Network connection established")); - break; - case QAbstractSocket::ClosingState: - emit q->stateMessage(tr("Network connection closing")); - break; - case QAbstractSocket::BoundState: - emit q->errorMessage(tr("Socket state changed to BoundState. This should not happen!")); - break; - case QAbstractSocket::ListeningState: - emit q->errorMessage(tr("Socket state changed to ListeningState. This should not happen!")); - break; - } -} - QmlDebugConnection::QmlDebugConnection(QObject *parent) : QObject(parent), d(new QmlDebugConnectionPrivate(this)) { @@ -326,17 +317,14 @@ void QmlDebugConnectionPrivate::flush() void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) { d->disconnected(); - emit stateMessage(tr("Connecting to debug server at %1:%2 ...") - .arg(hostName).arg(QString::number(port))); QTcpSocket *socket = new QTcpSocket(d); socket->setProxy(QNetworkProxy::NoProxy); d->device = socket; d->protocol = new QPacketProtocol(d->device, this); connect(d->protocol, &QPacketProtocol::readyRead, d, &QmlDebugConnectionPrivate::readyRead); - connect(socket, &QAbstractSocket::stateChanged, - d, &QmlDebugConnectionPrivate::stateChanged); + connect(socket, &QAbstractSocket::stateChanged, this, &QmlDebugConnection::socketStateChanged); connect(socket, static_cast - (&QAbstractSocket::error), d, &QmlDebugConnectionPrivate::error); + (&QAbstractSocket::error), this, &QmlDebugConnection::socketError); connect(socket, &QAbstractSocket::connected, d, &QmlDebugConnectionPrivate::connected); connect(socket, &QAbstractSocket::disconnected, d, &QmlDebugConnectionPrivate::disconnected); socket->connectToHost(hostName, port); diff --git a/src/libs/qmldebug/qmldebugclient.h b/src/libs/qmldebug/qmldebugclient.h index 13d4d79ce1..b87cc08b53 100644 --- a/src/libs/qmldebug/qmldebugclient.h +++ b/src/libs/qmldebug/qmldebugclient.h @@ -36,13 +36,6 @@ #include -namespace QDebugSupport { -enum Error { - RemoteClosedConnectionError, - UnknownError -}; -} - namespace QmlDebug { class QmlDebugConnectionPrivate; @@ -64,12 +57,14 @@ public: void close(); float serviceVersion(const QString &serviceName) const; + static QString socketStateToString(QAbstractSocket::SocketState state); + static QString socketErrorToString(QAbstractSocket::SocketError error); + signals: void connected(); void disconnected(); - void error(QDebugSupport::Error); - void stateMessage(const QString &message); - void errorMessage(const QString &message); + void socketError(QAbstractSocket::SocketError error); + void socketStateChanged(QAbstractSocket::SocketState state); private: friend class QmlDebugConnectionPrivate; diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index a8ac02e147..9d290e8c2c 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -291,11 +291,9 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin connect(&d->connectionTimer, &QTimer::timeout, this, &QmlEngine::checkConnectionState); - connect(d->connection, &QmlDebugConnection::stateMessage, - this, &QmlEngine::showConnectionStateMessage); - connect(d->connection, &QmlDebugConnection::errorMessage, - this, &QmlEngine::showConnectionErrorMessage); - connect(d->connection, &QmlDebugConnection::error, + connect(d->connection, &QmlDebugConnection::socketStateChanged, + this, &QmlEngine::connectionStateChanged); + connect(d->connection, &QmlDebugConnection::socketError, this, &QmlEngine::connectionErrorOccurred); connect(d->connection, &QmlDebugConnection::connected, &d->connectionTimer, &QTimer::stop); @@ -1213,11 +1211,11 @@ bool QmlEnginePrivate::canEvaluateScript(const QString &script) return interpreter.canEvaluate(); } -void QmlEngine::connectionErrorOccurred(QDebugSupport::Error error) +void QmlEngine::connectionErrorOccurred(QAbstractSocket::SocketError error) { // this is only an error if we are already connected and something goes wrong. if (isConnected()) { - if (error == QDebugSupport::RemoteClosedConnectionError) + if (error == QAbstractSocket::RemoteHostClosedError) showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar); if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits @@ -1230,6 +1228,11 @@ void QmlEngine::connectionErrorOccurred(QDebugSupport::Error error) } } +void QmlEngine::connectionStateChanged(QAbstractSocket::SocketState socketState) +{ + showConnectionStateMessage(QmlDebugConnection::socketStateToString(socketState)); +} + void QmlEngine::clientStateChanged(QmlDebugClient::State state) { QString serviceName; @@ -1260,11 +1263,6 @@ void QmlEngine::showConnectionStateMessage(const QString &message) showMessage(_("QML Debugger: ") + message, LogStatus); } -void QmlEngine::showConnectionErrorMessage(const QString &message) -{ - showMessage(_("QML Debugger: ") + message, LogError); -} - void QmlEngine::logServiceStateChange(const QString &service, float version, QmlDebugClient::State newState) { diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h index 479dddb746..24942b8feb 100644 --- a/src/plugins/debugger/qml/qmlengine.h +++ b/src/plugins/debugger/qml/qmlengine.h @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -142,11 +141,12 @@ private: void startApplicationLauncher(); void stopApplicationLauncher(); - void connectionErrorOccurred(QDebugSupport::Error socketError); + void connectionErrorOccurred(QAbstractSocket::SocketError socketError); + void connectionStateChanged(QAbstractSocket::SocketState socketState); + void clientStateChanged(QmlDebug::QmlDebugClient::State state); void checkConnectionState(); void showConnectionStateMessage(const QString &message); - void showConnectionErrorMessage(const QString &message); bool isConnected() const; private: diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp index f104dda4e4..887ba0f3b7 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp @@ -32,7 +32,6 @@ #include "qmlprofilertool.h" #include "qmlprofilerplugin.h" -#include #include #include @@ -132,16 +131,14 @@ void QmlProfilerClientManager::connectClient(quint16 port) d->connection = new QmlDebugConnection; enableServices(); - connect(d->connection, &QmlDebugConnection::stateMessage, - this, &QmlProfilerClientManager::logState); - connect(d->connection, &QmlDebugConnection::errorMessage, - this, &QmlProfilerClientManager::logState); connect(d->connection, &QmlDebugConnection::connected, this, &QmlProfilerClientManager::qmlDebugConnectionOpened); connect(d->connection, &QmlDebugConnection::disconnected, this, &QmlProfilerClientManager::qmlDebugConnectionClosed); - connect(d->connection, &QmlDebugConnection::error, + connect(d->connection, &QmlDebugConnection::socketError, this, &QmlProfilerClientManager::qmlDebugConnectionError); + connect(d->connection, &QmlDebugConnection::socketStateChanged, + this, &QmlProfilerClientManager::qmlDebugConnectionStateChanged); d->connectionTimer.start(); d->tcpPort = port; } @@ -273,9 +270,9 @@ void QmlProfilerClientManager::qmlDebugConnectionClosed() emit connectionClosed(); } -void QmlProfilerClientManager::qmlDebugConnectionError(QDebugSupport::Error error) +void QmlProfilerClientManager::qmlDebugConnectionError(QAbstractSocket::SocketError error) { - logState(tr("Debug connection error %1").arg(error)); + logState(QmlDebugConnection::socketErrorToString(error)); if (d->connection->isConnected()) { disconnectClient(); emit connectionClosed(); @@ -284,6 +281,11 @@ void QmlProfilerClientManager::qmlDebugConnectionError(QDebugSupport::Error erro } } +void QmlProfilerClientManager::qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state) +{ + logState(QmlDebugConnection::socketStateToString(state)); +} + void QmlProfilerClientManager::logState(const QString &msg) { QString state = QLatin1String("QML Profiler: ") + msg; diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.h b/src/plugins/qmlprofiler/qmlprofilerclientmanager.h index 0cbf88dc56..9eae3e0cad 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.h @@ -33,10 +33,10 @@ #include "qmlprofilerstatemanager.h" #include -#include #include #include +#include namespace QmlProfiler { class QmlProfilerModelManager; @@ -72,7 +72,8 @@ private slots: void tryToConnect(); void qmlDebugConnectionOpened(); void qmlDebugConnectionClosed(); - void qmlDebugConnectionError(QDebugSupport::Error error); + void qmlDebugConnectionError(QAbstractSocket::SocketError error); + void qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state); void logState(const QString &); void retryMessageBoxFinished(int result); -- GitLab