Commit ba982562 authored by Ulf Hermann's avatar Ulf Hermann
Browse files

QmlDebug: Decouple log messages from connection failures



A socket error is not the only possible reason for a connection failure
and exposing socket error codes to the upper layers is unnecessary.

Change-Id: I27e9f21160ecea5b0d811b83b7ab0ab9071cacff
Reviewed-by: default avatarhjk <hjk@qt.io>
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent 60bc2ccc
......@@ -68,34 +68,36 @@ public:
void flush();
};
QString QmlDebugConnection::socketStateToString(QAbstractSocket::SocketState state)
static QString socketStateToString(QAbstractSocket::SocketState state)
{
switch (state) {
case QAbstractSocket::UnconnectedState:
return tr("Network connection dropped");
return QmlDebugConnection::tr("Network connection dropped");
case QAbstractSocket::HostLookupState:
return tr("Resolving host");
return QmlDebugConnection::tr("Resolving host");
case QAbstractSocket::ConnectingState:
return tr("Establishing network connection ...");
return QmlDebugConnection::tr("Establishing network connection ...");
case QAbstractSocket::ConnectedState:
return tr("Network connection established");
return QmlDebugConnection::tr("Network connection established");
case QAbstractSocket::ClosingState:
return tr("Network connection closing");
return QmlDebugConnection::tr("Network connection closing");
case QAbstractSocket::BoundState:
return tr("Socket state changed to BoundState. This should not happen!");
return QmlDebugConnection::tr("Socket state changed to BoundState. "
"This should not happen!");
case QAbstractSocket::ListeningState:
return tr("Socket state changed to ListeningState. This should not happen!");
return QmlDebugConnection::tr("Socket state changed to ListeningState. "
"This should not happen!");
default:
return tr("Unknown state %1").arg(state);
return QmlDebugConnection::tr("Unknown state %1").arg(state);
}
}
QString QmlDebugConnection::socketErrorToString(QAbstractSocket::SocketError error)
static QString socketErrorToString(QAbstractSocket::SocketError error)
{
if (error == QAbstractSocket::RemoteHostClosedError) {
return tr("Error: Remote host closed the connection");
return QmlDebugConnection::tr("Error: Remote host closed the connection");
} else {
return tr("Error: Unknown socket error %1").arg(error);
return QmlDebugConnection::tr("Error: Unknown socket error %1").arg(error);
}
}
......@@ -136,6 +138,8 @@ void QmlDebugConnection::socketDisconnected()
for (; iter != d->plugins.end(); ++iter)
iter.value()->stateChanged(QmlDebugClient::NotConnected);
emit disconnected();
} else if (d->device) {
emit connectionFailed();
}
delete d->protocol;
d->protocol = 0;
......@@ -365,9 +369,16 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
d->protocol = new QPacketProtocol(socket, this);
QObject::connect(d->protocol, &QPacketProtocol::readyRead,
this, &QmlDebugConnection::protocolReadyRead);
connect(socket, &QAbstractSocket::stateChanged, this, &QmlDebugConnection::socketStateChanged);
connect(socket, &QAbstractSocket::stateChanged,
this, [this](QAbstractSocket::SocketState state) {
emit logStateChange(socketStateToString(state));
});
connect(socket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)>
(&QAbstractSocket::error), this, &QmlDebugConnection::socketError);
(&QAbstractSocket::error), this, [this](QAbstractSocket::SocketError error) {
emit logError(socketErrorToString(error));
socketDisconnected();
});
connect(socket, &QAbstractSocket::connected, this, &QmlDebugConnection::socketConnected);
connect(socket, &QAbstractSocket::disconnected, this, &QmlDebugConnection::socketDisconnected);
socket->connectToHost(hostName, port);
......@@ -385,7 +396,7 @@ void QmlDebugConnection::startLocalServer(const QString &fileName)
connect(d->server, &QLocalServer::newConnection,
this, &QmlDebugConnection::newConnection, Qt::QueuedConnection);
if (!d->server->listen(fileName))
emit socketError(QAbstractSocket::UnknownSocketError);
emit connectionFailed();
}
void QmlDebugConnection::newConnection()
......@@ -403,13 +414,14 @@ void QmlDebugConnection::newConnection()
connect(socket, &QLocalSocket::disconnected, this, &QmlDebugConnection::socketDisconnected);
connect(socket, static_cast<void (QLocalSocket::*)(QLocalSocket::LocalSocketError)>
(&QLocalSocket::error), this, [this](QLocalSocket::LocalSocketError error) {
socketError(static_cast<QAbstractSocket::SocketError>(error));
(&QLocalSocket::error), this, [this, d](QLocalSocket::LocalSocketError error) {
logError(socketErrorToString(static_cast<QAbstractSocket::SocketError>(error)));
socketDisconnected();
});
connect(socket, &QLocalSocket::stateChanged,
this, [this](QLocalSocket::LocalSocketState state) {
socketStateChanged(static_cast<QAbstractSocket::SocketState>(state));
logStateChange(socketStateToString(static_cast<QAbstractSocket::SocketState>(state)));
});
socketConnected();
......
......@@ -61,14 +61,13 @@ public:
float serviceVersion(const QString &serviceName) const;
bool sendMessage(const QString &name, const QByteArray &message);
static QString socketStateToString(QAbstractSocket::SocketState state);
static QString socketErrorToString(QAbstractSocket::SocketError error);
signals:
void connected();
void disconnected();
void socketError(QAbstractSocket::SocketError error);
void socketStateChanged(QAbstractSocket::SocketState state);
void connectionFailed();
void logError(const QString &error);
void logStateChange(const QString &state);
private:
void newConnection();
......
......@@ -289,10 +289,13 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
connect(&d->connectionTimer, &QTimer::timeout,
this, &QmlEngine::checkConnectionState);
connect(d->connection, &QmlDebugConnection::socketStateChanged,
this, &QmlEngine::connectionStateChanged);
connect(d->connection, &QmlDebugConnection::socketError,
this, &QmlEngine::connectionErrorOccurred);
connect(d->connection, &QmlDebugConnection::logStateChange,
this, &QmlEngine::showConnectionStateMessage);
connect(d->connection, &QmlDebugConnection::logError, this,
[this](const QString &error) { showMessage("QML Debugger: " + error, StatusBar); });
connect(d->connection, &QmlDebugConnection::connectionFailed,
this, &QmlEngine::connectionFailed);
connect(d->connection, &QmlDebugConnection::connected,
&d->connectionTimer, &QTimer::stop);
connect(d->connection, &QmlDebugConnection::connected,
......@@ -1200,13 +1203,10 @@ bool QmlEnginePrivate::canEvaluateScript(const QString &script)
return interpreter.canEvaluate();
}
void QmlEngine::connectionErrorOccurred(QAbstractSocket::SocketError error)
void QmlEngine::connectionFailed()
{
// this is only an error if we are already connected and something goes wrong.
if (isConnected()) {
if (error == QAbstractSocket::RemoteHostClosedError)
showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar);
if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits
notifyInferiorSpontaneousStop();
notifyInferiorIll();
......@@ -1217,11 +1217,6 @@ void QmlEngine::connectionErrorOccurred(QAbstractSocket::SocketError error)
}
}
void QmlEngine::connectionStateChanged(QAbstractSocket::SocketState socketState)
{
showConnectionStateMessage(QmlDebugConnection::socketStateToString(socketState));
}
void QmlEngine::checkConnectionState()
{
if (!isConnected()) {
......
......@@ -133,8 +133,7 @@ private:
void startApplicationLauncher();
void stopApplicationLauncher();
void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
void connectionStateChanged(QAbstractSocket::SocketState socketState);
void connectionFailed();
void checkConnectionState();
void showConnectionStateMessage(const QString &message);
......
......@@ -179,10 +179,13 @@ void QmlProfilerClientManager::createConnection()
this, &QmlProfilerClientManager::qmlDebugConnectionOpened);
connect(d->connection, &QmlDebug::QmlDebugConnection::disconnected,
this, &QmlProfilerClientManager::qmlDebugConnectionClosed);
connect(d->connection, &QmlDebug::QmlDebugConnection::socketError,
this, &QmlProfilerClientManager::qmlDebugConnectionError);
connect(d->connection, &QmlDebug::QmlDebugConnection::socketStateChanged,
this, &QmlProfilerClientManager::qmlDebugConnectionStateChanged);
connect(d->connection, &QmlDebug::QmlDebugConnection::connectionFailed,
this, &QmlProfilerClientManager::qmlDebugConnectionFailed);
connect(d->connection, &QmlDebug::QmlDebugConnection::logError,
this, &QmlProfilerClientManager::logState);
connect(d->connection, &QmlDebug::QmlDebugConnection::logStateChange,
this, &QmlProfilerClientManager::logState);
}
void QmlProfilerClientManager::retryConnect()
......@@ -294,9 +297,8 @@ void QmlProfilerClientManager::qmlDebugConnectionClosed()
emit connectionClosed();
}
void QmlProfilerClientManager::qmlDebugConnectionError(QAbstractSocket::SocketError error)
void QmlProfilerClientManager::qmlDebugConnectionFailed()
{
logState(QmlDebug::QmlDebugConnection::socketErrorToString(error));
if (d->connection->isConnected()) {
disconnectClient();
emit connectionClosed();
......@@ -305,11 +307,6 @@ void QmlProfilerClientManager::qmlDebugConnectionError(QAbstractSocket::SocketEr
}
}
void QmlProfilerClientManager::qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state)
{
logState(QmlDebug::QmlDebugConnection::socketStateToString(state));
}
void QmlProfilerClientManager::logState(const QString &msg)
{
QmlProfilerTool::logState(QLatin1String("QML Profiler: ") + msg);
......
......@@ -72,8 +72,8 @@ private slots:
void tryToConnect();
void qmlDebugConnectionOpened();
void qmlDebugConnectionClosed();
void qmlDebugConnectionError(QAbstractSocket::SocketError error);
void qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state);
void qmlDebugConnectionFailed();
void logState(const QString &);
void qmlComplete(qint64 maximumTime);
......
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