forked from qt-creator/qt-creator
QmlDebugClient: hide all the socket details from clients
Like this no one will get the idea that the socket state represents the connection state and we can safely replace the underlying implementation with something not derived from QAbstractSocket. All the logging is retained but the connection creates the messages now. Change-Id: If84ff42f1fa9785254fbd49c75be867b9f663c83 Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
@@ -59,10 +59,13 @@ QmlAdapter::QmlAdapter(DebuggerEngine *engine, QObject *parent)
|
||||
connect(&m_connectionTimer, SIGNAL(timeout()), SLOT(checkConnectionState()));
|
||||
|
||||
m_conn = new QmlDebugConnection(this);
|
||||
connect(m_conn, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)),
|
||||
SLOT(connectionStateChanged()));
|
||||
connect(m_conn, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
SLOT(connectionErrorOccurred(QAbstractSocket::SocketError)));
|
||||
connect(m_conn, SIGNAL(stateMessage(QString)), SLOT(showConnectionStateMessage(QString)));
|
||||
connect(m_conn, SIGNAL(errorMessage(QString)), SLOT(showConnectionErrorMessage(QString)));
|
||||
connect(m_conn, SIGNAL(error(QDebugSupport::Error)),
|
||||
SLOT(connectionErrorOccurred(QDebugSupport::Error)));
|
||||
connect(m_conn, SIGNAL(opened()), &m_connectionTimer, SLOT(stop()));
|
||||
connect(m_conn, SIGNAL(opened()), SIGNAL(connected()));
|
||||
connect(m_conn, SIGNAL(closed()), SIGNAL(disconnected()));
|
||||
|
||||
createDebuggerClients();
|
||||
m_msgClient = new QDebugMessageClient(m_conn);
|
||||
@@ -77,12 +80,9 @@ QmlAdapter::~QmlAdapter()
|
||||
|
||||
void QmlAdapter::beginConnectionTcp(const QString &address, quint16 port)
|
||||
{
|
||||
if (m_engine.isNull()
|
||||
|| (m_conn && m_conn->socketState() != QAbstractSocket::UnconnectedState))
|
||||
if (m_engine.isNull() || (m_conn && m_conn->isOpen()))
|
||||
return;
|
||||
|
||||
showConnectionStateMessage(tr("Connecting to debug server %1:%2").arg(address).arg(
|
||||
QString::number(port)));
|
||||
m_conn->connectToHost(address, port);
|
||||
|
||||
//A timeout to check the connection state
|
||||
@@ -99,14 +99,11 @@ void QmlAdapter::closeConnection()
|
||||
}
|
||||
}
|
||||
|
||||
void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketError)
|
||||
void QmlAdapter::connectionErrorOccurred(QDebugSupport::Error error)
|
||||
{
|
||||
showConnectionStateMessage(tr("Error: (%1) %2", "%1=error code, %2=error message")
|
||||
.arg(socketError).arg(m_conn->errorString()));
|
||||
|
||||
// this is only an error if we are already connected and something goes wrong.
|
||||
if (isConnected()) {
|
||||
emit connectionError(socketError);
|
||||
emit connectionError(error);
|
||||
} else {
|
||||
m_connectionTimer.stop();
|
||||
emit connectionStartupFailed();
|
||||
@@ -136,41 +133,6 @@ void QmlAdapter::debugClientStateChanged(QmlDebugClient::State state)
|
||||
m_qmlClient->startSession();
|
||||
}
|
||||
|
||||
void QmlAdapter::connectionStateChanged()
|
||||
{
|
||||
switch (m_conn->socketState()) {
|
||||
case QAbstractSocket::UnconnectedState:
|
||||
{
|
||||
showConnectionStateMessage(tr("Disconnected.") + QLatin1String("\n\n"));
|
||||
emit disconnected();
|
||||
|
||||
break;
|
||||
}
|
||||
case QAbstractSocket::HostLookupState:
|
||||
showConnectionStateMessage(tr("Resolving host."));
|
||||
break;
|
||||
case QAbstractSocket::ConnectingState:
|
||||
showConnectionStateMessage(tr("Connecting to debug server."));
|
||||
break;
|
||||
case QAbstractSocket::ConnectedState:
|
||||
{
|
||||
showConnectionStateMessage(tr("Connected.") + QLatin1Char('\n'));
|
||||
|
||||
m_connectionTimer.stop();
|
||||
|
||||
//reloadEngines();
|
||||
emit connected();
|
||||
break;
|
||||
}
|
||||
case QAbstractSocket::ClosingState:
|
||||
showConnectionStateMessage(tr("Closing."));
|
||||
break;
|
||||
case QAbstractSocket::BoundState:
|
||||
case QAbstractSocket::ListeningState:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QmlAdapter::checkConnectionState()
|
||||
{
|
||||
if (!isConnected()) {
|
||||
@@ -181,7 +143,7 @@ void QmlAdapter::checkConnectionState()
|
||||
|
||||
bool QmlAdapter::isConnected() const
|
||||
{
|
||||
return m_conn && m_qmlClient && m_conn->socketState() == QAbstractSocket::ConnectedState;
|
||||
return m_conn && m_qmlClient && m_conn->isOpen();
|
||||
}
|
||||
|
||||
void QmlAdapter::createDebuggerClients()
|
||||
|
||||
@@ -77,21 +77,20 @@ signals:
|
||||
void connected();
|
||||
void disconnected();
|
||||
void connectionStartupFailed();
|
||||
void connectionError(QAbstractSocket::SocketError socketError);
|
||||
void connectionError(QDebugSupport::Error error);
|
||||
void serviceConnectionError(const QString serviceName);
|
||||
|
||||
private slots:
|
||||
void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
|
||||
void connectionErrorOccurred(QDebugSupport::Error socketError);
|
||||
void clientStateChanged(QmlDebug::QmlDebugClient::State state);
|
||||
void debugClientStateChanged(QmlDebug::QmlDebugClient::State state);
|
||||
void connectionStateChanged();
|
||||
void checkConnectionState();
|
||||
void showConnectionStateMessage(const QString &message);
|
||||
void showConnectionErrorMessage(const QString &message);
|
||||
|
||||
private:
|
||||
bool isConnected() const;
|
||||
void createDebuggerClients();
|
||||
void showConnectionStateMessage(const QString &message);
|
||||
void showConnectionErrorMessage(const QString &message);
|
||||
|
||||
private:
|
||||
QPointer<DebuggerEngine> m_engine;
|
||||
|
||||
@@ -266,8 +266,8 @@ QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters, DebuggerEng
|
||||
if (masterEngine)
|
||||
setMasterEngine(masterEngine);
|
||||
|
||||
connect(&m_adapter, SIGNAL(connectionError(QAbstractSocket::SocketError)),
|
||||
SLOT(connectionError(QAbstractSocket::SocketError)));
|
||||
connect(&m_adapter, SIGNAL(connectionError(QDebugSupport::Error)),
|
||||
SLOT(connectionError(QDebugSupport::Error)));
|
||||
connect(&m_adapter, SIGNAL(serviceConnectionError(QString)),
|
||||
SLOT(serviceConnectionError(QString)));
|
||||
connect(&m_adapter, SIGNAL(connected()),
|
||||
@@ -499,9 +499,9 @@ void QmlEngine::errorMessageBoxFinished(int result)
|
||||
}
|
||||
}
|
||||
|
||||
void QmlEngine::connectionError(QAbstractSocket::SocketError socketError)
|
||||
void QmlEngine::connectionError(QDebugSupport::Error error)
|
||||
{
|
||||
if (socketError == QAbstractSocket::RemoteHostClosedError)
|
||||
if (error == QDebugSupport::RemoteClosedConnectionError)
|
||||
showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar);
|
||||
|
||||
if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits
|
||||
|
||||
@@ -107,7 +107,7 @@ private slots:
|
||||
void connectionEstablished();
|
||||
void connectionStartupFailed();
|
||||
void appStartupFailed(const QString &errorMessage);
|
||||
void connectionError(QAbstractSocket::SocketError error);
|
||||
void connectionError(QDebugSupport::Error error);
|
||||
void serviceConnectionError(const QString &service);
|
||||
void appendMessage(const QString &msg, Utils::OutputFormat);
|
||||
|
||||
|
||||
@@ -147,8 +147,10 @@ void QmlProfilerClientManager::connectClient(quint16 port)
|
||||
delete d->connection;
|
||||
d->connection = new QmlDebugConnection;
|
||||
enableServices();
|
||||
connect(d->connection, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)),
|
||||
this, SLOT(connectionStateChanged()));
|
||||
connect(d->connection, SIGNAL(stateMessage(QString)), this, SLOT(logState(QString)));
|
||||
connect(d->connection, SIGNAL(errorMessage(QString)), this, SLOT(logState(QString)));
|
||||
connect(d->connection, SIGNAL(opened()), this, SLOT(qmlDebugConnectionOpened()));
|
||||
connect(d->connection, SIGNAL(closed()), this, SLOT(qmlDebugConnectionClosed()));
|
||||
d->connectionTimer.start();
|
||||
d->tcpPort = port;
|
||||
}
|
||||
@@ -235,7 +237,7 @@ void QmlProfilerClientManager::disconnectClientSignals()
|
||||
|
||||
void QmlProfilerClientManager::connectToClient()
|
||||
{
|
||||
if (!d->connection || d->connection->socketState() != QAbstractSocket::UnconnectedState)
|
||||
if (!d->connection || d->connection->isOpen())
|
||||
return;
|
||||
|
||||
d->connection->connectToHost(d->tcpHost, d->tcpPort);
|
||||
@@ -287,45 +289,25 @@ void QmlProfilerClientManager::tryToConnect()
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::connectionStateChanged()
|
||||
void QmlProfilerClientManager::qmlDebugConnectionOpened()
|
||||
{
|
||||
if (!d->connection)
|
||||
return;
|
||||
switch (d->connection->socketState()) {
|
||||
case QAbstractSocket::UnconnectedState:
|
||||
{
|
||||
if (QmlProfilerPlugin::debugOutput)
|
||||
qWarning("QML Profiler: disconnected");
|
||||
disconnectClient();
|
||||
emit connectionClosed();
|
||||
break;
|
||||
}
|
||||
case QAbstractSocket::HostLookupState:
|
||||
break;
|
||||
case QAbstractSocket::ConnectingState: {
|
||||
if (QmlProfilerPlugin::debugOutput)
|
||||
qWarning("QML Profiler: Connecting to debug server ...");
|
||||
QmlProfilerTool::logState(tr("QML Profiler: Connecting to %1:%2 ...")
|
||||
.arg(d->tcpHost, QString::number(d->tcpPort)));
|
||||
break;
|
||||
}
|
||||
case QAbstractSocket::ConnectedState:
|
||||
{
|
||||
if (QmlProfilerPlugin::debugOutput)
|
||||
qWarning("QML Profiler: connected and running");
|
||||
// notify the client recording status
|
||||
clientRecordingChanged();
|
||||
QmlProfilerTool::logState(tr("QML Profiler: connected and running"));
|
||||
break;
|
||||
}
|
||||
case QAbstractSocket::ClosingState:
|
||||
if (QmlProfilerPlugin::debugOutput)
|
||||
qWarning("QML Profiler: closing ...");
|
||||
break;
|
||||
case QAbstractSocket::BoundState:
|
||||
case QAbstractSocket::ListeningState:
|
||||
break;
|
||||
}
|
||||
logState(tr("Debug connection opened"));
|
||||
clientRecordingChanged();
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::qmlDebugConnectionClosed()
|
||||
{
|
||||
logState(tr("Debug connection closed"));
|
||||
disconnectClient();
|
||||
emit connectionClosed();
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::logState(const QString &msg)
|
||||
{
|
||||
QString state = QLatin1String("QML Profiler: ") + msg;
|
||||
if (QmlProfilerPlugin::debugOutput)
|
||||
qWarning() << state;
|
||||
QmlProfilerTool::logState(state);
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::retryMessageBoxFinished(int result)
|
||||
@@ -341,11 +323,8 @@ void QmlProfilerClientManager::retryMessageBoxFinished(int result)
|
||||
// fall through
|
||||
}
|
||||
default: {
|
||||
if (d->connection)
|
||||
QmlProfilerTool::logState(QLatin1String("QML Profiler: Failed to connect! ") + d->connection->errorString());
|
||||
else
|
||||
QmlProfilerTool::logState(QLatin1String("QML Profiler: Failed to connect!"));
|
||||
|
||||
// The actual error message has already been logged.
|
||||
logState(tr("Failed to connect!"));
|
||||
emit connectionFailed();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,10 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void tryToConnect();
|
||||
void connectionStateChanged();
|
||||
void qmlDebugConnectionOpened();
|
||||
void qmlDebugConnectionClosed();
|
||||
void logState(const QString &);
|
||||
|
||||
void retryMessageBoxFinished(int result);
|
||||
|
||||
void qmlComplete(qint64 maximumTime);
|
||||
|
||||
Reference in New Issue
Block a user