aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmldebug
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-11-16 15:55:33 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-11-18 09:01:11 +0000
commitc4bd6beca3e7c3e8cf31af2f3fdd08a1f7aeabcb (patch)
tree6edba5d8eae036fbe59b6b952b959a147662e94d /src/qmldebug
parentfee44872dce081b3480f3cb3bb74d12940a92068 (diff)
QmlDebug: Add some useful methods to QQmlDebugConnection
Change-Id: Iee2c09278f31ea93da9c02be6b2fc909b5f154d0 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qmldebug')
-rw-r--r--src/qmldebug/qqmldebugclient.cpp2
-rw-r--r--src/qmldebug/qqmldebugclient_p.h2
-rw-r--r--src/qmldebug/qqmldebugconnection.cpp48
-rw-r--r--src/qmldebug/qqmldebugconnection_p.h6
4 files changed, 55 insertions, 3 deletions
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<QAbstractSocket::SocketError>(error));
+ }
+
+ void onStateChanged(QLocalSocket::LocalSocketState state)
+ {
+ emit socketStateChanged(static_cast<QAbstractSocket::SocketState>(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 <qqmldebugconnection.moc>
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 <QtCore/qobject.h>
+#include <QtNetwork/qabstractsocket.h>
//
// 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();