From c4bd6beca3e7c3e8cf31af2f3fdd08a1f7aeabcb Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 16 Nov 2015 15:55:33 +0100 Subject: QmlDebug: Add some useful methods to QQmlDebugConnection Change-Id: Iee2c09278f31ea93da9c02be6b2fc909b5f154d0 Reviewed-by: Simon Hausmann --- src/qmldebug/qqmldebugclient.cpp | 2 +- src/qmldebug/qqmldebugclient_p.h | 2 +- src/qmldebug/qqmldebugconnection.cpp | 48 +++++++++++++++++++++++++++++++++++- src/qmldebug/qqmldebugconnection_p.h | 6 +++++ 4 files changed, 55 insertions(+), 3 deletions(-) (limited to 'src/qmldebug') diff --git a/src/qmldebug/qqmldebugclient.cpp b/src/qmldebug/qqmldebugclient.cpp index b5d1130f88..dfa14d6667 100644 --- a/src/qmldebug/qqmldebugclient.cpp +++ b/src/qmldebug/qqmldebugclient.cpp @@ -105,7 +105,7 @@ void QQmlDebugClient::sendMessage(const QByteArray &message) d->connection->sendMessage(d->name, message); } -const QQmlDebugConnection *QQmlDebugClient::connection() const +QQmlDebugConnection *QQmlDebugClient::connection() const { Q_D(const QQmlDebugClient); return d->connection; diff --git a/src/qmldebug/qqmldebugclient_p.h b/src/qmldebug/qqmldebugclient_p.h index 8e8330f317..6d391617a9 100644 --- a/src/qmldebug/qqmldebugclient_p.h +++ b/src/qmldebug/qqmldebugclient_p.h @@ -68,7 +68,7 @@ public: State state() const; void sendMessage(const QByteArray &message); - const QQmlDebugConnection *connection() const; + QQmlDebugConnection *connection() const; protected: QQmlDebugClient(QQmlDebugClientPrivate &dd); diff --git a/src/qmldebug/qqmldebugconnection.cpp b/src/qmldebug/qqmldebugconnection.cpp index e8650ebbff..3c207b7cc8 100644 --- a/src/qmldebug/qqmldebugconnection.cpp +++ b/src/qmldebug/qqmldebugconnection.cpp @@ -109,6 +109,7 @@ void QQmlDebugConnection::socketDisconnected() { Q_D(QQmlDebugConnection); d->gotHello = false; + emit disconnected(); } void QQmlDebugConnection::protocolReadyRead() @@ -273,6 +274,12 @@ bool QQmlDebugConnection::isConnected() const return d->gotHello; } +bool QQmlDebugConnection::isConnecting() const +{ + Q_D(const QQmlDebugConnection); + return !d->gotHello && d->device; +} + void QQmlDebugConnection::close() { Q_D(QQmlDebugConnection); @@ -372,7 +379,10 @@ void QQmlDebugConnection::connectToHost(const QString &hostName, quint16 port) d->device = socket; d->connectDeviceSignals(); connect(socket, SIGNAL(connected()), this, SLOT(socketConnected())); - connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); + connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), + this, SIGNAL(socketError(QAbstractSocket::SocketError))); + connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), + this, SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); socket->connectToHost(hostName, port); } @@ -389,6 +399,34 @@ void QQmlDebugConnection::startLocalServer(const QString &fileName) d->server->listen(fileName); } +class LocalSocketSignalTranslator : public QObject +{ + Q_OBJECT +public: + LocalSocketSignalTranslator(QLocalSocket *parent) : QObject(parent) + { + connect(parent, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)), + this, SLOT(onStateChanged(QLocalSocket::LocalSocketState))); + connect(parent, SIGNAL(error(QLocalSocket::LocalSocketError)), + this, SLOT(onError(QLocalSocket::LocalSocketError))); + } + +signals: + void socketError(QAbstractSocket::SocketError error); + void socketStateChanged(QAbstractSocket::SocketState state); + +public slots: + void onError(QLocalSocket::LocalSocketError error) + { + emit socketError(static_cast(error)); + } + + void onStateChanged(QLocalSocket::LocalSocketState state) + { + emit socketStateChanged(static_cast(state)); + } +}; + void QQmlDebugConnection::newConnection() { Q_D(QQmlDebugConnection); @@ -397,6 +435,12 @@ void QQmlDebugConnection::newConnection() d->server->close(); d->device = socket; d->connectDeviceSignals(); + LocalSocketSignalTranslator *translator = new LocalSocketSignalTranslator(socket); + + QObject::connect(translator, SIGNAL(socketError(QAbstractSocket::SocketError)), + this, SIGNAL(socketError(QAbstractSocket::SocketError))); + QObject::connect(translator, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)), + this, SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); socketConnected(); } @@ -410,3 +454,5 @@ void QQmlDebugConnectionPrivate::connectDeviceSignals() } QT_END_NAMESPACE + +#include diff --git a/src/qmldebug/qqmldebugconnection_p.h b/src/qmldebug/qqmldebugconnection_p.h index 31a4d7167a..190ca25db2 100644 --- a/src/qmldebug/qqmldebugconnection_p.h +++ b/src/qmldebug/qqmldebugconnection_p.h @@ -35,6 +35,7 @@ #define QQMLDEBUGCONNECTION_P_H #include +#include // // W A R N I N G @@ -67,6 +68,8 @@ public: void setMaximumDataStreamVersion(int maximumVersion); bool isConnected() const; + bool isConnecting() const; + void close(); bool waitForConnected(int msecs = 30000); @@ -79,6 +82,9 @@ public: signals: void connected(); + void disconnected(); + void socketError(QAbstractSocket::SocketError socketError); + void socketStateChanged(QAbstractSocket::SocketState socketState); private Q_SLOTS: void newConnection(); -- cgit v1.2.3