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:
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("<device is gone>")));
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<void (QTcpSocket::*)(QAbstractSocket::SocketError)>
(&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);
......
......@@ -36,13 +36,6 @@
#include <QDataStream>
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;
......
......@@ -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)
{
......
......@@ -34,7 +34,6 @@
#include <debugger/debuggerengine.h>
#include <qmldebug/qdebugmessageclient.h>
#include <qmldebug/qmldebugclient.h>
#include <qmldebug/qmloutputparser.h>
#include <qmljs/iscriptevaluator.h>
#include <qmljs/qmljsdocument.h>
......@@ -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:
......
......@@ -32,7 +32,6 @@
#include "qmlprofilertool.h"
#include "qmlprofilerplugin.h"
#include <qmldebug/qmldebugclient.h>
#include <qmldebug/qmlprofilertraceclient.h>
#include <utils/qtcassert.h>
......@@ -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;
......
......@@ -33,10 +33,10 @@
#include "qmlprofilerstatemanager.h"
#include <qmldebug/qmlprofilereventlocation.h>
#include <qmldebug/qmldebugclient.h>
#include <QObject>
#include <QStringList>
#include <QAbstractSocket>
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);
......
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