Commit 81eea72d authored by Ulf Hermann's avatar Ulf Hermann

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: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent 47317eff
...@@ -75,11 +75,40 @@ public: ...@@ -75,11 +75,40 @@ public:
public slots: public slots:
void connected(); void connected();
void disconnected(); void disconnected();
void error(QAbstractSocket::SocketError error);
void readyRead(); 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) QmlDebugConnectionPrivate::QmlDebugConnectionPrivate(QmlDebugConnection *c)
: QObject(c), q(c), protocol(0), device(0), gotHello(false), : QObject(c), q(c), protocol(0), device(0), gotHello(false),
currentDataStreamVersion(QDataStream::Qt_4_7), currentDataStreamVersion(QDataStream::Qt_4_7),
...@@ -124,17 +153,6 @@ void QmlDebugConnectionPrivate::disconnected() ...@@ -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("<device is gone>")));
if (socketError == QAbstractSocket::RemoteHostClosedError)
emit q->error(QDebugSupport::RemoteClosedConnectionError);
else
emit q->error(QDebugSupport::UnknownError);
}
void QmlDebugConnectionPrivate::readyRead() void QmlDebugConnectionPrivate::readyRead()
{ {
if (!gotHello) { if (!gotHello) {
...@@ -252,33 +270,6 @@ void QmlDebugConnectionPrivate::readyRead() ...@@ -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) QmlDebugConnection::QmlDebugConnection(QObject *parent)
: QObject(parent), d(new QmlDebugConnectionPrivate(this)) : QObject(parent), d(new QmlDebugConnectionPrivate(this))
{ {
...@@ -326,17 +317,14 @@ void QmlDebugConnectionPrivate::flush() ...@@ -326,17 +317,14 @@ void QmlDebugConnectionPrivate::flush()
void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
{ {
d->disconnected(); d->disconnected();
emit stateMessage(tr("Connecting to debug server at %1:%2 ...")
.arg(hostName).arg(QString::number(port)));
QTcpSocket *socket = new QTcpSocket(d); QTcpSocket *socket = new QTcpSocket(d);
socket->setProxy(QNetworkProxy::NoProxy); socket->setProxy(QNetworkProxy::NoProxy);
d->device = socket; d->device = socket;
d->protocol = new QPacketProtocol(d->device, this); d->protocol = new QPacketProtocol(d->device, this);
connect(d->protocol, &QPacketProtocol::readyRead, d, &QmlDebugConnectionPrivate::readyRead); connect(d->protocol, &QPacketProtocol::readyRead, d, &QmlDebugConnectionPrivate::readyRead);
connect(socket, &QAbstractSocket::stateChanged, connect(socket, &QAbstractSocket::stateChanged, this, &QmlDebugConnection::socketStateChanged);
d, &QmlDebugConnectionPrivate::stateChanged);
connect(socket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)> connect(socket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)>
(&QAbstractSocket::error), d, &QmlDebugConnectionPrivate::error); (&QAbstractSocket::error), this, &QmlDebugConnection::socketError);
connect(socket, &QAbstractSocket::connected, d, &QmlDebugConnectionPrivate::connected); connect(socket, &QAbstractSocket::connected, d, &QmlDebugConnectionPrivate::connected);
connect(socket, &QAbstractSocket::disconnected, d, &QmlDebugConnectionPrivate::disconnected); connect(socket, &QAbstractSocket::disconnected, d, &QmlDebugConnectionPrivate::disconnected);
socket->connectToHost(hostName, port); socket->connectToHost(hostName, port);
......
...@@ -36,13 +36,6 @@ ...@@ -36,13 +36,6 @@
#include <QDataStream> #include <QDataStream>
namespace QDebugSupport {
enum Error {
RemoteClosedConnectionError,
UnknownError
};
}
namespace QmlDebug { namespace QmlDebug {
class QmlDebugConnectionPrivate; class QmlDebugConnectionPrivate;
...@@ -64,12 +57,14 @@ public: ...@@ -64,12 +57,14 @@ public:
void close(); void close();
float serviceVersion(const QString &serviceName) const; float serviceVersion(const QString &serviceName) const;
static QString socketStateToString(QAbstractSocket::SocketState state);
static QString socketErrorToString(QAbstractSocket::SocketError error);
signals: signals:
void connected(); void connected();
void disconnected(); void disconnected();
void error(QDebugSupport::Error); void socketError(QAbstractSocket::SocketError error);
void stateMessage(const QString &message); void socketStateChanged(QAbstractSocket::SocketState state);
void errorMessage(const QString &message);
private: private:
friend class QmlDebugConnectionPrivate; friend class QmlDebugConnectionPrivate;
......
...@@ -291,11 +291,9 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin ...@@ -291,11 +291,9 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
connect(&d->connectionTimer, &QTimer::timeout, connect(&d->connectionTimer, &QTimer::timeout,
this, &QmlEngine::checkConnectionState); this, &QmlEngine::checkConnectionState);
connect(d->connection, &QmlDebugConnection::stateMessage, connect(d->connection, &QmlDebugConnection::socketStateChanged,
this, &QmlEngine::showConnectionStateMessage); this, &QmlEngine::connectionStateChanged);
connect(d->connection, &QmlDebugConnection::errorMessage, connect(d->connection, &QmlDebugConnection::socketError,
this, &QmlEngine::showConnectionErrorMessage);
connect(d->connection, &QmlDebugConnection::error,
this, &QmlEngine::connectionErrorOccurred); this, &QmlEngine::connectionErrorOccurred);
connect(d->connection, &QmlDebugConnection::connected, connect(d->connection, &QmlDebugConnection::connected,
&d->connectionTimer, &QTimer::stop); &d->connectionTimer, &QTimer::stop);
...@@ -1213,11 +1211,11 @@ bool QmlEnginePrivate::canEvaluateScript(const QString &script) ...@@ -1213,11 +1211,11 @@ bool QmlEnginePrivate::canEvaluateScript(const QString &script)
return interpreter.canEvaluate(); 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. // this is only an error if we are already connected and something goes wrong.
if (isConnected()) { if (isConnected()) {
if (error == QDebugSupport::RemoteClosedConnectionError) if (error == QAbstractSocket::RemoteHostClosedError)
showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar); showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar);
if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits
...@@ -1230,6 +1228,11 @@ void QmlEngine::connectionErrorOccurred(QDebugSupport::Error error) ...@@ -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) void QmlEngine::clientStateChanged(QmlDebugClient::State state)
{ {
QString serviceName; QString serviceName;
...@@ -1260,11 +1263,6 @@ void QmlEngine::showConnectionStateMessage(const QString &message) ...@@ -1260,11 +1263,6 @@ void QmlEngine::showConnectionStateMessage(const QString &message)
showMessage(_("QML Debugger: ") + message, LogStatus); showMessage(_("QML Debugger: ") + message, LogStatus);
} }
void QmlEngine::showConnectionErrorMessage(const QString &message)
{
showMessage(_("QML Debugger: ") + message, LogError);
}
void QmlEngine::logServiceStateChange(const QString &service, float version, void QmlEngine::logServiceStateChange(const QString &service, float version,
QmlDebugClient::State newState) QmlDebugClient::State newState)
{ {
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <debugger/debuggerengine.h> #include <debugger/debuggerengine.h>
#include <qmldebug/qdebugmessageclient.h> #include <qmldebug/qdebugmessageclient.h>
#include <qmldebug/qmldebugclient.h>
#include <qmldebug/qmloutputparser.h> #include <qmldebug/qmloutputparser.h>
#include <qmljs/iscriptevaluator.h> #include <qmljs/iscriptevaluator.h>
#include <qmljs/qmljsdocument.h> #include <qmljs/qmljsdocument.h>
...@@ -142,11 +141,12 @@ private: ...@@ -142,11 +141,12 @@ private:
void startApplicationLauncher(); void startApplicationLauncher();
void stopApplicationLauncher(); void stopApplicationLauncher();
void connectionErrorOccurred(QDebugSupport::Error socketError); void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
void connectionStateChanged(QAbstractSocket::SocketState socketState);
void clientStateChanged(QmlDebug::QmlDebugClient::State state); void clientStateChanged(QmlDebug::QmlDebugClient::State state);
void checkConnectionState(); void checkConnectionState();
void showConnectionStateMessage(const QString &message); void showConnectionStateMessage(const QString &message);
void showConnectionErrorMessage(const QString &message);
bool isConnected() const; bool isConnected() const;
private: private:
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "qmlprofilertool.h" #include "qmlprofilertool.h"
#include "qmlprofilerplugin.h" #include "qmlprofilerplugin.h"
#include <qmldebug/qmldebugclient.h>
#include <qmldebug/qmlprofilertraceclient.h> #include <qmldebug/qmlprofilertraceclient.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
...@@ -132,16 +131,14 @@ void QmlProfilerClientManager::connectClient(quint16 port) ...@@ -132,16 +131,14 @@ void QmlProfilerClientManager::connectClient(quint16 port)
d->connection = new QmlDebugConnection; d->connection = new QmlDebugConnection;
enableServices(); enableServices();
connect(d->connection, &QmlDebugConnection::stateMessage,
this, &QmlProfilerClientManager::logState);
connect(d->connection, &QmlDebugConnection::errorMessage,
this, &QmlProfilerClientManager::logState);
connect(d->connection, &QmlDebugConnection::connected, connect(d->connection, &QmlDebugConnection::connected,
this, &QmlProfilerClientManager::qmlDebugConnectionOpened); this, &QmlProfilerClientManager::qmlDebugConnectionOpened);
connect(d->connection, &QmlDebugConnection::disconnected, connect(d->connection, &QmlDebugConnection::disconnected,
this, &QmlProfilerClientManager::qmlDebugConnectionClosed); this, &QmlProfilerClientManager::qmlDebugConnectionClosed);
connect(d->connection, &QmlDebugConnection::error, connect(d->connection, &QmlDebugConnection::socketError,
this, &QmlProfilerClientManager::qmlDebugConnectionError); this, &QmlProfilerClientManager::qmlDebugConnectionError);
connect(d->connection, &QmlDebugConnection::socketStateChanged,
this, &QmlProfilerClientManager::qmlDebugConnectionStateChanged);
d->connectionTimer.start(); d->connectionTimer.start();
d->tcpPort = port; d->tcpPort = port;
} }
...@@ -273,9 +270,9 @@ void QmlProfilerClientManager::qmlDebugConnectionClosed() ...@@ -273,9 +270,9 @@ void QmlProfilerClientManager::qmlDebugConnectionClosed()
emit connectionClosed(); 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()) { if (d->connection->isConnected()) {
disconnectClient(); disconnectClient();
emit connectionClosed(); emit connectionClosed();
...@@ -284,6 +281,11 @@ void QmlProfilerClientManager::qmlDebugConnectionError(QDebugSupport::Error erro ...@@ -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) void QmlProfilerClientManager::logState(const QString &msg)
{ {
QString state = QLatin1String("QML Profiler: ") + msg; QString state = QLatin1String("QML Profiler: ") + msg;
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
#include "qmlprofilerstatemanager.h" #include "qmlprofilerstatemanager.h"
#include <qmldebug/qmlprofilereventlocation.h> #include <qmldebug/qmlprofilereventlocation.h>
#include <qmldebug/qmldebugclient.h>
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>
#include <QAbstractSocket>
namespace QmlProfiler { namespace QmlProfiler {
class QmlProfilerModelManager; class QmlProfilerModelManager;
...@@ -72,7 +72,8 @@ private slots: ...@@ -72,7 +72,8 @@ private slots:
void tryToConnect(); void tryToConnect();
void qmlDebugConnectionOpened(); void qmlDebugConnectionOpened();
void qmlDebugConnectionClosed(); void qmlDebugConnectionClosed();
void qmlDebugConnectionError(QDebugSupport::Error error); void qmlDebugConnectionError(QAbstractSocket::SocketError error);
void qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state);
void logState(const QString &); void logState(const QString &);
void retryMessageBoxFinished(int result); void retryMessageBoxFinished(int result);
......
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