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