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:
Ulf Hermann
2014-05-05 17:18:11 +02:00
parent b63d9c6df0
commit a7012c5a87
8 changed files with 136 additions and 145 deletions

View File

@@ -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()