aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2014-12-02 15:57:06 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-26 14:13:46 +0000
commitf23d4fafbff44bcb6fb1e259ca1021a4c4326084 (patch)
tree8fd6c26460d3dd9f268e64a92ad6e6ec4b375c56 /src/plugins
parent49d3cbfa171902ae2dc61bcdadfdac1305c50a2a (diff)
Add option to use a local socket for QML debugging
Using a TCP debug server comes with a number of drawbacks. It has a larger overhead than other connection types, the application has to be able to access the network and there has to be an open port we can find somehow. Change-Id: Ia7fb24006b89419988c6504797303d84c3aa1bbc Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp188
-rw-r--r--src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h78
-rw-r--r--src/plugins/qmltooling/qmldbg_local/qmldbg_local.pri14
-rw-r--r--src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro8
-rw-r--r--src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp7
-rw-r--r--src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h1
-rw-r--r--src/plugins/qmltooling/qmltooling.pro2
7 files changed, 297 insertions, 1 deletions
diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp
new file mode 100644
index 0000000000..344700b8fd
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlocalclientconnection.h"
+#include "qpacketprotocol.h"
+
+#include <QtCore/qplugin.h>
+#include <QtNetwork/qlocalsocket.h>
+
+#include <private/qqmldebugserver_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QLocalClientConnectionPrivate {
+public:
+ QLocalClientConnectionPrivate();
+
+ bool block;
+ QString filename;
+ QLocalSocket *socket;
+ QPacketProtocol *protocol;
+ QQmlDebugServer *debugServer;
+};
+
+QLocalClientConnectionPrivate::QLocalClientConnectionPrivate() :
+ block(false),
+ socket(0),
+ protocol(0),
+ debugServer(0)
+{
+}
+
+QLocalClientConnection::QLocalClientConnection() :
+ d_ptr(new QLocalClientConnectionPrivate)
+{
+}
+
+QLocalClientConnection::~QLocalClientConnection()
+{
+ if (isConnected())
+ disconnect();
+ delete d_ptr;
+}
+
+void QLocalClientConnection::setServer(QQmlDebugServer *server)
+{
+ Q_D(QLocalClientConnection);
+ d->debugServer = server;
+}
+
+bool QLocalClientConnection::isConnected() const
+{
+ Q_D(const QLocalClientConnection);
+ return d->socket && d->socket->state() == QLocalSocket::ConnectedState;
+}
+
+void QLocalClientConnection::send(const QList<QByteArray> &messages)
+{
+ Q_D(QLocalClientConnection);
+
+ if (!isConnected() || !d->protocol || !d->socket)
+ return;
+
+ foreach (const QByteArray &message, messages) {
+ QPacket pack;
+ pack.writeRawData(message.data(), message.length());
+ d->protocol->send(pack);
+ }
+ d->socket->flush();
+}
+
+void QLocalClientConnection::disconnect()
+{
+ Q_D(QLocalClientConnection);
+
+ while (d->socket && d->socket->bytesToWrite() > 0)
+ d->socket->waitForBytesWritten();
+
+ // protocol might still be processing packages at this point
+ d->protocol->deleteLater();
+ d->protocol = 0;
+ d->socket->deleteLater();
+ d->socket = 0;
+}
+
+bool QLocalClientConnection::waitForMessage()
+{
+ Q_D(QLocalClientConnection);
+ return d->protocol->waitForReadyRead(-1);
+}
+
+bool QLocalClientConnection::setPortRange(int portFrom, int portTo, bool block,
+ const QString &hostaddress)
+{
+ Q_UNUSED(portFrom);
+ Q_UNUSED(portTo);
+ Q_UNUSED(block);
+ Q_UNUSED(hostaddress);
+ return false;
+}
+
+bool QLocalClientConnection::setFileName(const QString &filename, bool block)
+{
+ Q_D(QLocalClientConnection);
+ d->filename = filename;
+ d->block = block;
+ return connect();
+}
+
+void QLocalClientConnection::waitForConnection()
+{
+ Q_D(QLocalClientConnection);
+ d->socket->waitForConnected(-1);
+}
+
+bool QLocalClientConnection::connect()
+{
+ Q_D(QLocalClientConnection);
+
+ d->socket = new QLocalSocket;
+ d->socket->setParent(this);
+ QObject::connect(d->socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
+ d->socket->connectToServer(d->filename);
+ qDebug("QML Debugger: Connecting to socket %s...",
+ d->filename.toLatin1().constData());
+ return true;
+}
+
+void QLocalClientConnection::readyRead()
+{
+ Q_D(QLocalClientConnection);
+ if (!d->protocol)
+ return;
+
+ QPacket packet = d->protocol->read();
+
+ QByteArray content = packet.data();
+ d->debugServer->receiveMessage(content);
+}
+
+void QLocalClientConnection::connectionEstablished()
+{
+ Q_D(QLocalClientConnection);
+
+ d->protocol = new QPacketProtocol(d->socket, this);
+ QObject::connect(d->protocol, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ QObject::connect(d->protocol, SIGNAL(invalidPacket()), this, SLOT(invalidPacket()));
+
+ if (d->block)
+ d->protocol->waitForReadyRead(-1);
+}
+
+void QLocalClientConnection::invalidPacket()
+{
+ qWarning("QML Debugger: Received a corrupted packet! Giving up ...");
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h
new file mode 100644
index 0000000000..424337900b
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLOCALCLIENTCONNECTION_H
+#define QLOCALCLIENTCONNECTION_H
+
+#include <private/qqmldebugserverconnection_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQmlDebugServer;
+class QLocalClientConnectionPrivate;
+class QLocalClientConnection : public QObject, public QQmlDebugServerConnection
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QLocalClientConnection)
+ Q_DISABLE_COPY(QLocalClientConnection)
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlDebugServerConnection")
+ Q_INTERFACES(QQmlDebugServerConnection)
+
+public:
+ QLocalClientConnection();
+ ~QLocalClientConnection();
+
+ void setServer(QQmlDebugServer *server);
+ bool setPortRange(int portFrom, int portTo, bool bock, const QString &hostaddress);
+ bool setFileName(const QString &filename, bool block);
+
+ bool isConnected() const;
+ void send(const QList<QByteArray> &messages);
+ void disconnect();
+ bool waitForMessage();
+
+ void waitForConnection();
+ bool connect();
+
+private Q_SLOTS:
+ void readyRead();
+ void connectionEstablished();
+ void invalidPacket();
+
+private:
+ QLocalClientConnectionPrivate *d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QLOCALCLIENTCONNECTION_H
diff --git a/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pri b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pri
new file mode 100644
index 0000000000..7635523e9b
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pri
@@ -0,0 +1,14 @@
+QT += core-private
+
+SOURCES += \
+ $$PWD/qlocalclientconnection.cpp \
+ $$PWD/../shared/qpacketprotocol.cpp
+
+HEADERS += \
+ $$PWD/qlocalclientconnection.h \
+ $$PWD/../shared/qpacketprotocol.h
+
+INCLUDEPATH += $$PWD \
+ $$PWD/../shared
+
+OTHER_FILES += $$PWD/qlocalclientconnection.json
diff --git a/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro
new file mode 100644
index 0000000000..b060154933
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro
@@ -0,0 +1,8 @@
+TARGET = qmldbg_local
+QT = qml-private core-private
+
+PLUGIN_TYPE = qmltooling
+PLUGIN_CLASS_NAME = QLocalClientConnection
+load(qt_plugin)
+
+include(qmldbg_local.pri)
diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
index 2ae4edfce4..f7c0673c19 100644
--- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
+++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
@@ -146,6 +146,13 @@ bool QTcpServerConnection::setPortRange(int portFrom, int portTo, bool block,
return listen();
}
+bool QTcpServerConnection::setFileName(const QString &fileName, bool block)
+{
+ Q_UNUSED(fileName);
+ Q_UNUSED(block);
+ return false;
+}
+
void QTcpServerConnection::waitForConnection()
{
Q_D(QTcpServerConnection);
diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h
index 942fb6e12c..496d328a11 100644
--- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h
+++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h
@@ -54,6 +54,7 @@ public:
void setServer(QQmlDebugServer *server);
bool setPortRange(int portFrom, int portTo, bool bock, const QString &hostaddress);
+ bool setFileName(const QString &fileName, bool block);
bool isConnected() const;
void send(const QList<QByteArray> &messages);
diff --git a/src/plugins/qmltooling/qmltooling.pro b/src/plugins/qmltooling/qmltooling.pro
index 3bc48a6b33..585f80138b 100644
--- a/src/plugins/qmltooling/qmltooling.pro
+++ b/src/plugins/qmltooling/qmltooling.pro
@@ -1,4 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS = qmldbg_tcp
+SUBDIRS = qmldbg_tcp qmldbg_local
qtHaveModule(quick): SUBDIRS += qmldbg_qtquick2