2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-02-16 04:43:03 +00:00
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-20 05:21:40 +00:00
|
|
|
** 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
|
2015-01-28 11:55:39 +00:00
|
|
|
** 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.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-22 06:13:59 +00:00
|
|
|
** 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.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-07-14 16:35:02 +00:00
|
|
|
#include "qqmldebugserver.h"
|
|
|
|
#include "qqmldebugserverfactory.h"
|
2015-06-16 11:40:08 +00:00
|
|
|
#include "qpacketprotocol.h"
|
2015-07-14 16:35:02 +00:00
|
|
|
#include "qqmldebugserverconnection.h"
|
2014-02-05 14:38:51 +00:00
|
|
|
|
2015-07-14 16:35:02 +00:00
|
|
|
#include <private/qqmldebugservice_p.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <private/qqmlengine_p.h>
|
|
|
|
#include <private/qqmlglobal_p.h>
|
2015-07-15 13:19:50 +00:00
|
|
|
#include <private/qqmldebugpluginmanager_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-16 15:44:24 +00:00
|
|
|
#include <QtCore/QAtomicInt>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtCore/QPluginLoader>
|
|
|
|
#include <QtCore/QStringList>
|
2011-08-24 11:51:07 +00:00
|
|
|
#include <QtCore/qwaitcondition.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include <private/qobject_p.h>
|
2011-09-30 12:44:53 +00:00
|
|
|
#include <private/qcoreapplication_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
/*
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebug Protocol (Version 1):
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
handshake:
|
|
|
|
1. Client sends
|
2012-04-23 07:23:23 +00:00
|
|
|
"QDeclarativeDebugServer" 0 version pluginNames [QDataStream version]
|
2011-04-27 10:05:43 +00:00
|
|
|
version: an int representing the highest protocol version the client knows
|
|
|
|
pluginNames: plugins available on client side
|
|
|
|
2. Server sends
|
2012-04-23 07:23:23 +00:00
|
|
|
"QDeclarativeDebugClient" 0 version pluginNames pluginVersions [QDataStream version]
|
2011-04-27 10:05:43 +00:00
|
|
|
version: an int representing the highest protocol version the client & server know
|
|
|
|
pluginNames: plugins available on server side. plugins both in the client and server message are enabled.
|
|
|
|
client plugin advertisement
|
|
|
|
1. Client sends
|
2012-03-07 08:34:12 +00:00
|
|
|
"QDeclarativeDebugServer" 1 pluginNames
|
2015-07-15 12:08:48 +00:00
|
|
|
server plugin advertisement (not implemented: all services are required to register before open())
|
2011-04-27 10:05:43 +00:00
|
|
|
1. Server sends
|
2012-03-07 13:53:24 +00:00
|
|
|
"QDeclarativeDebugClient" 1 pluginNames pluginVersions
|
2011-04-27 10:05:43 +00:00
|
|
|
plugin communication:
|
2012-03-07 08:34:12 +00:00
|
|
|
Everything send with a header different to "QDeclarativeDebugServer" is sent to the appropriate plugin.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2015-07-15 13:19:50 +00:00
|
|
|
Q_QML_DEBUG_PLUGIN_LOADER(QQmlDebugServerConnection)
|
|
|
|
Q_QML_IMPORT_DEBUG_PLUGIN(QTcpServerConnectionFactory)
|
|
|
|
Q_QML_IMPORT_DEBUG_PLUGIN(QLocalClientConnectionFactory)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-15 13:19:50 +00:00
|
|
|
const int protocolVersion = 1;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQmlDebugServerThread;
|
2015-07-14 14:36:32 +00:00
|
|
|
class QQmlDebugServerImpl : public QQmlDebugServer
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-14 14:36:32 +00:00
|
|
|
Q_OBJECT
|
2011-04-27 10:05:43 +00:00
|
|
|
public:
|
2015-07-15 09:43:37 +00:00
|
|
|
QQmlDebugServerImpl();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
bool blockingMode() const;
|
|
|
|
|
|
|
|
QQmlDebugService *service(const QString &name) const;
|
|
|
|
|
|
|
|
void addEngine(QQmlEngine *engine);
|
|
|
|
void removeEngine(QQmlEngine *engine);
|
|
|
|
|
|
|
|
bool addService(QQmlDebugService *service);
|
|
|
|
bool removeService(QQmlDebugService *service);
|
|
|
|
|
2015-07-29 10:28:10 +00:00
|
|
|
bool open(const QVariantHash &configuration);
|
2015-06-16 11:40:08 +00:00
|
|
|
void setDevice(QIODevice *socket);
|
2014-12-02 14:57:06 +00:00
|
|
|
|
|
|
|
template<class Action>
|
2015-07-29 10:28:10 +00:00
|
|
|
bool enable(Action action);
|
|
|
|
bool enableFromArguments();
|
2014-12-02 14:57:06 +00:00
|
|
|
|
2015-07-15 09:43:37 +00:00
|
|
|
static void cleanup();
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
private slots:
|
|
|
|
void wakeEngine(QQmlEngine *engine);
|
2015-07-13 13:56:25 +00:00
|
|
|
void sendMessage(const QString &name, const QByteArray &message);
|
|
|
|
void sendMessages(const QString &name, const QList<QByteArray> &messages);
|
2015-07-14 14:36:32 +00:00
|
|
|
void changeServiceState(const QString &serviceName, QQmlDebugService::State state);
|
|
|
|
void removeThread();
|
2015-06-16 11:40:08 +00:00
|
|
|
void receiveMessage();
|
|
|
|
void invalidPacket();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
private:
|
|
|
|
friend struct StartTcpServerAction;
|
|
|
|
friend struct ConnectToLocalAction;
|
|
|
|
friend class QQmlDebugServerThread;
|
2015-07-14 16:35:02 +00:00
|
|
|
friend class QQmlDebugServerFactory;
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2014-02-06 13:43:26 +00:00
|
|
|
class EngineCondition {
|
|
|
|
public:
|
|
|
|
EngineCondition() : numServices(0), condition(new QWaitCondition) {}
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
bool waitForServices(QMutex *locked, int numEngines);
|
2014-02-06 13:43:26 +00:00
|
|
|
|
|
|
|
void wake();
|
|
|
|
private:
|
|
|
|
int numServices;
|
|
|
|
|
|
|
|
// shared pointer to allow for QHash-inflicted copying.
|
|
|
|
QSharedPointer<QWaitCondition> condition;
|
|
|
|
};
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
bool init(const QString &pluginName, bool block);
|
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
bool canSendMessage(const QString &name);
|
|
|
|
void doSendMessage(const QString &name, const QByteArray &message);
|
2014-02-06 13:43:26 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
QQmlDebugServerConnection *m_connection;
|
|
|
|
QHash<QString, QQmlDebugService *> m_plugins;
|
|
|
|
QStringList m_clientPlugins;
|
|
|
|
bool m_gotHello;
|
|
|
|
bool m_blockingMode;
|
|
|
|
|
|
|
|
QHash<QQmlEngine *, EngineCondition> m_engineConditions;
|
|
|
|
|
|
|
|
QMutex m_helloMutex;
|
|
|
|
QWaitCondition m_helloCondition;
|
|
|
|
QQmlDebugServerThread *m_thread;
|
2015-06-16 11:40:08 +00:00
|
|
|
QPacketProtocol *m_protocol;
|
2015-07-14 14:36:32 +00:00
|
|
|
QAtomicInt m_changeServiceStateCalls;
|
|
|
|
};
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQmlDebugServerThread : public QThread
|
2011-08-24 11:51:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-07-15 09:43:37 +00:00
|
|
|
QQmlDebugServerThread(QQmlDebugServerImpl *server) :
|
|
|
|
m_server(server), m_portFrom(-1), m_portTo(-1), m_block(false) {}
|
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
void setPluginName(const QString &pluginName) {
|
|
|
|
m_pluginName = pluginName;
|
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
void setPortRange(int portFrom, int portTo, bool block, const QString &hostAddress) {
|
2013-03-18 16:17:52 +00:00
|
|
|
m_portFrom = portFrom;
|
|
|
|
m_portTo = portTo;
|
2011-08-24 11:51:07 +00:00
|
|
|
m_block = block;
|
2012-03-14 12:35:17 +00:00
|
|
|
m_hostAddress = hostAddress;
|
2011-08-24 11:51:07 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 14:57:06 +00:00
|
|
|
void setFileName(const QString &fileName, bool block)
|
|
|
|
{
|
|
|
|
m_fileName = fileName;
|
|
|
|
m_block = block;
|
|
|
|
}
|
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
void run();
|
|
|
|
|
|
|
|
private:
|
2015-07-15 09:43:37 +00:00
|
|
|
QQmlDebugServerImpl *m_server;
|
2011-08-24 11:51:07 +00:00
|
|
|
QString m_pluginName;
|
2013-03-18 16:17:52 +00:00
|
|
|
int m_portFrom;
|
|
|
|
int m_portTo;
|
2011-08-24 11:51:07 +00:00
|
|
|
bool m_block;
|
2012-03-14 12:35:17 +00:00
|
|
|
QString m_hostAddress;
|
2014-12-02 14:57:06 +00:00
|
|
|
QString m_fileName;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2015-07-29 10:28:10 +00:00
|
|
|
struct StartTcpServerAction {
|
|
|
|
int portFrom;
|
|
|
|
int portTo;
|
|
|
|
bool block;
|
|
|
|
QString hostAddress;
|
|
|
|
|
|
|
|
StartTcpServerAction(int portFrom, int portTo, bool block, const QString &hostAddress) :
|
|
|
|
portFrom(portFrom), portTo(portTo), block(block), hostAddress(hostAddress) {}
|
|
|
|
|
|
|
|
bool operator()(QQmlDebugServerImpl *d)
|
|
|
|
{
|
2015-07-15 13:19:50 +00:00
|
|
|
if (!d->init(QLatin1String("QTcpServerConnection"), block))
|
2015-07-29 10:28:10 +00:00
|
|
|
return false;
|
|
|
|
d->m_thread->setPortRange(portFrom, portTo == -1 ? portFrom : portTo, block, hostAddress);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConnectToLocalAction {
|
|
|
|
QString fileName;
|
|
|
|
bool block;
|
|
|
|
|
|
|
|
ConnectToLocalAction(const QString &fileName, bool block) :
|
|
|
|
fileName(fileName), block(block) {}
|
|
|
|
|
|
|
|
bool operator()(QQmlDebugServerImpl *d)
|
|
|
|
{
|
2015-07-15 13:19:50 +00:00
|
|
|
if (!d->init(QLatin1String("QLocalClientConnection"), block))
|
2015-07-29 10:28:10 +00:00
|
|
|
return false;
|
|
|
|
d->m_thread->setFileName(fileName, block);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::cleanup()
|
2014-01-30 11:19:13 +00:00
|
|
|
{
|
2015-07-15 09:43:37 +00:00
|
|
|
QQmlDebugServerImpl *server = static_cast<QQmlDebugServerImpl *>(
|
|
|
|
QQmlDebugConnector::instance());
|
|
|
|
if (!server)
|
|
|
|
return;
|
|
|
|
|
2015-07-16 09:04:39 +00:00
|
|
|
for (QHash<QString, QQmlDebugService *>::ConstIterator i = server->m_plugins.constBegin();
|
|
|
|
i != server->m_plugins.constEnd(); ++i) {
|
2015-07-15 09:43:37 +00:00
|
|
|
server->m_changeServiceStateCalls.ref();
|
|
|
|
QMetaObject::invokeMethod(server, "changeServiceState", Qt::QueuedConnection,
|
2015-07-16 09:04:39 +00:00
|
|
|
Q_ARG(QString, i.key()),
|
|
|
|
Q_ARG(QQmlDebugService::State,
|
|
|
|
QQmlDebugService::NotConnected));
|
2014-01-30 11:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for changeServiceState calls to finish
|
|
|
|
// (while running an event loop because some services
|
|
|
|
// might again use slots to execute stuff in the GUI thread)
|
|
|
|
QEventLoop loop;
|
2015-07-15 09:43:37 +00:00
|
|
|
while (!server->m_changeServiceStateCalls.testAndSetOrdered(0, 0))
|
2014-01-30 11:19:13 +00:00
|
|
|
loop.processEvents();
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
// Stop the thread while the application is still there. Copy here as the thread will set itself
|
|
|
|
// to 0 when it stops. It will also do deleteLater, but as long as we don't allow the GUI
|
|
|
|
// thread's event loop to run we're safe from that.
|
2015-07-15 09:43:37 +00:00
|
|
|
QThread *threadCopy = server->m_thread;
|
2014-10-10 11:32:38 +00:00
|
|
|
if (threadCopy) {
|
|
|
|
threadCopy->exit();
|
|
|
|
threadCopy->wait();
|
2014-01-30 11:19:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServerThread::run()
|
2011-08-24 11:51:07 +00:00
|
|
|
{
|
2015-07-15 09:43:37 +00:00
|
|
|
Q_ASSERT_X(m_server != 0, Q_FUNC_INFO, "There should always be a debug server available here.");
|
2015-07-15 13:19:50 +00:00
|
|
|
QQmlDebugServerConnection *connection = loadQQmlDebugServerConnection(m_pluginName);
|
2011-08-24 11:51:07 +00:00
|
|
|
if (connection) {
|
2015-07-15 09:43:37 +00:00
|
|
|
connection->setServer(m_server);
|
2014-12-02 14:57:06 +00:00
|
|
|
|
|
|
|
if (m_fileName.isEmpty()) {
|
|
|
|
if (!connection->setPortRange(m_portFrom, m_portTo, m_block, m_hostAddress)) {
|
|
|
|
delete connection;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!connection->setFileName(m_fileName, m_block)) {
|
|
|
|
delete connection;
|
|
|
|
return;
|
|
|
|
}
|
2014-10-10 11:32:38 +00:00
|
|
|
}
|
2014-12-02 14:57:06 +00:00
|
|
|
|
2015-07-29 10:51:23 +00:00
|
|
|
{
|
2015-07-15 09:43:37 +00:00
|
|
|
QMutexLocker connectionLocker(&m_server->m_helloMutex);
|
|
|
|
m_server->m_connection = connection;
|
|
|
|
m_server->m_helloCondition.wakeAll();
|
2015-07-29 10:51:23 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
if (m_block)
|
|
|
|
connection->waitForConnection();
|
2011-08-24 11:51:07 +00:00
|
|
|
} else {
|
2014-10-10 11:32:38 +00:00
|
|
|
qWarning() << "QML Debugger: Couldn't load plugin" << m_pluginName;
|
|
|
|
return;
|
2011-08-24 11:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exec();
|
2011-12-20 13:26:39 +00:00
|
|
|
|
|
|
|
// make sure events still waiting are processed
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
eventLoop.processEvents(QEventLoop::AllEvents);
|
2011-08-24 11:51:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
bool QQmlDebugServerImpl::blockingMode() const
|
2012-04-24 12:39:38 +00:00
|
|
|
{
|
2015-07-14 14:36:32 +00:00
|
|
|
return m_blockingMode;
|
2012-04-24 12:39:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
static void cleanupOnShutdown()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-14 16:35:02 +00:00
|
|
|
// We cannot do this in the destructor as the connection plugin will get unloaded before the
|
|
|
|
// server plugin and we need the connection to send any remaining data. This function is
|
|
|
|
// triggered before any plugins are unloaded.
|
2015-07-15 09:43:37 +00:00
|
|
|
QQmlDebugServerImpl::cleanup();
|
2014-01-30 11:19:13 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
bool QQmlDebugServerImpl::init(const QString &pluginName, bool block)
|
2014-10-10 11:32:38 +00:00
|
|
|
{
|
2015-07-14 14:36:32 +00:00
|
|
|
if (m_thread)
|
2014-10-10 11:32:38 +00:00
|
|
|
return false;
|
|
|
|
static bool postRoutineAdded = false;
|
|
|
|
if (!postRoutineAdded) {
|
|
|
|
qAddPostRoutine(cleanupOnShutdown);
|
|
|
|
postRoutineAdded = true;
|
|
|
|
}
|
2015-07-15 09:43:37 +00:00
|
|
|
m_thread = new QQmlDebugServerThread(this);
|
2015-07-14 14:36:32 +00:00
|
|
|
moveToThread(m_thread);
|
2014-10-10 11:32:38 +00:00
|
|
|
|
|
|
|
// Remove the thread immmediately when it finishes, so that we don't have to wait for the event
|
|
|
|
// loop to signal that.
|
2015-07-14 14:36:32 +00:00
|
|
|
QObject::connect(m_thread, SIGNAL(finished()), this, SLOT(removeThread()), Qt::DirectConnection);
|
2014-10-10 11:32:38 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
m_thread->setObjectName(QStringLiteral("QQmlDebugServerThread"));
|
|
|
|
m_thread->setPluginName(pluginName);
|
|
|
|
m_blockingMode = block;
|
2014-10-10 11:32:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
|
|
|
|
QQmlDebugServerImpl::QQmlDebugServerImpl() :
|
|
|
|
m_connection(0),
|
|
|
|
m_gotHello(false),
|
|
|
|
m_blockingMode(false),
|
|
|
|
m_thread(0)
|
2014-01-30 11:19:13 +00:00
|
|
|
{
|
2015-07-14 14:36:32 +00:00
|
|
|
// used in sendMessages
|
|
|
|
qRegisterMetaType<QList<QByteArray> >("QList<QByteArray>");
|
|
|
|
// used in changeServiceState
|
|
|
|
qRegisterMetaType<QQmlDebugService::State>("QQmlDebugService::State");
|
2015-07-29 10:28:10 +00:00
|
|
|
}
|
2015-07-14 14:36:32 +00:00
|
|
|
|
2015-07-29 10:28:10 +00:00
|
|
|
bool QQmlDebugServerImpl::open(const QVariantHash &configuration = QVariantHash())
|
|
|
|
{
|
|
|
|
if (configuration.isEmpty()) {
|
|
|
|
return enableFromArguments();
|
|
|
|
} if (configuration.contains(QLatin1String("portFrom"))) {
|
|
|
|
return enable(StartTcpServerAction(
|
|
|
|
configuration[QLatin1String("portFrom")].toInt(),
|
|
|
|
configuration[QLatin1String("portTo")].toInt(),
|
|
|
|
configuration[QLatin1String("block")].toBool(),
|
|
|
|
configuration[QLatin1String("hostAddress")].toString()));
|
|
|
|
} else if (configuration.contains(QLatin1String("fileName"))) {
|
|
|
|
return enable(ConnectToLocalAction(configuration[QLatin1String("fileName")].toString(),
|
|
|
|
configuration[QLatin1String("block")].toBool()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlDebugServerImpl::enableFromArguments()
|
|
|
|
{
|
2015-07-15 10:01:05 +00:00
|
|
|
// format: qmljsdebugger=port:<port_from>[,port_to],host:<ip address>][,block]
|
|
|
|
const QString args = commandLineArguments();
|
|
|
|
if (args.isEmpty())
|
|
|
|
return false; // Manual initialization, through QQmlDebugServer::open()
|
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
// ### remove port definition when protocol is changed
|
|
|
|
int portFrom = 0;
|
|
|
|
int portTo = 0;
|
|
|
|
bool block = false;
|
|
|
|
bool ok = false;
|
|
|
|
QString hostAddress;
|
2014-12-02 14:57:06 +00:00
|
|
|
QString fileName;
|
2014-01-30 11:19:13 +00:00
|
|
|
|
2015-07-15 10:01:05 +00:00
|
|
|
const QStringList lstjsDebugArguments = args.split(QLatin1Char(','));
|
|
|
|
QStringList::const_iterator argsItEnd = lstjsDebugArguments.cend();
|
|
|
|
QStringList::const_iterator argsIt = lstjsDebugArguments.cbegin();
|
|
|
|
for (; argsIt != argsItEnd; ++argsIt) {
|
|
|
|
const QString strArgument = *argsIt;
|
|
|
|
if (strArgument.startsWith(QLatin1String("port:"))) {
|
|
|
|
portFrom = strArgument.mid(5).toInt(&ok);
|
|
|
|
portTo = portFrom;
|
|
|
|
QStringList::const_iterator argsNext = argsIt + 1;
|
|
|
|
if (argsNext == argsItEnd)
|
|
|
|
break;
|
|
|
|
const QString nextArgument = *argsNext;
|
|
|
|
|
|
|
|
// Don't use QStringLiteral here. QRegExp has a global cache and will save an implicitly
|
|
|
|
// shared copy of the passed string. That copy isn't properly detached when the library
|
|
|
|
// is unloaded if the original string lives in the library's .rodata
|
|
|
|
if (ok && nextArgument.contains(QRegExp(QLatin1String("^\\s*\\d+\\s*$")))) {
|
|
|
|
portTo = nextArgument.toInt(&ok);
|
|
|
|
++argsIt;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2015-07-15 10:01:05 +00:00
|
|
|
} else if (strArgument.startsWith(QLatin1String("host:"))) {
|
|
|
|
hostAddress = strArgument.mid(5);
|
|
|
|
} else if (strArgument == QLatin1String("block")) {
|
|
|
|
block = true;
|
|
|
|
} else if (strArgument.startsWith(QLatin1String("file:"))) {
|
|
|
|
fileName = strArgument.mid(5);
|
|
|
|
ok = !fileName.isEmpty();
|
2014-01-30 11:19:13 +00:00
|
|
|
} else {
|
2015-07-15 10:01:05 +00:00
|
|
|
qWarning() << QString::fromLatin1("QML Debugger: Invalid argument '%1' "
|
|
|
|
"detected. Ignoring the same.")
|
|
|
|
.arg(strArgument);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-15 10:01:05 +00:00
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
if (!fileName.isEmpty())
|
|
|
|
return enable(ConnectToLocalAction(fileName, block));
|
|
|
|
else
|
|
|
|
return enable(StartTcpServerAction(portFrom, portTo, block, hostAddress));
|
|
|
|
} else {
|
|
|
|
qWarning() << QString::fromLatin1("QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
|
|
|
"Format is qmljsdebugger=port:<port_from>[,port_to],host:"
|
|
|
|
"<ip address>][,block]").arg(args);
|
|
|
|
}
|
2015-07-29 10:28:10 +00:00
|
|
|
return false;
|
2011-12-20 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
void QQmlDebugServerImpl::receiveMessage()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-02-23 12:44:12 +00:00
|
|
|
typedef QHash<QString, QQmlDebugService*>::const_iterator DebugServiceConstIt;
|
|
|
|
|
2012-04-11 14:27:14 +00:00
|
|
|
// to be executed in debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() == thread());
|
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
if (!m_protocol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QQmlDebugStream in(m_protocol->read().data());
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
QString name;
|
|
|
|
|
|
|
|
in >> name;
|
2012-03-07 08:34:12 +00:00
|
|
|
if (name == QLatin1String("QDeclarativeDebugServer")) {
|
2011-09-19 10:29:10 +00:00
|
|
|
int op = -1;
|
|
|
|
in >> op;
|
|
|
|
if (op == 0) {
|
|
|
|
int version;
|
2015-07-14 14:36:32 +00:00
|
|
|
in >> version >> m_clientPlugins;
|
2011-09-19 10:29:10 +00:00
|
|
|
|
2012-04-23 07:23:23 +00:00
|
|
|
//Get the supported QDataStream version
|
|
|
|
if (!in.atEnd()) {
|
2015-07-13 10:45:35 +00:00
|
|
|
in >> QQmlDebugStream::s_dataStreamVersion;
|
|
|
|
if (QQmlDebugStream::s_dataStreamVersion > QDataStream().version())
|
|
|
|
QQmlDebugStream::s_dataStreamVersion = QDataStream().version();
|
2012-04-23 07:23:23 +00:00
|
|
|
}
|
2013-05-17 13:15:31 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
// Send the hello answer immediately, since it needs to arrive before
|
|
|
|
// the plugins below start sending messages.
|
2013-05-17 13:15:31 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
QByteArray helloAnswer;
|
2014-02-06 12:01:05 +00:00
|
|
|
QQmlDebugStream out(&helloAnswer, QIODevice::WriteOnly);
|
|
|
|
QStringList pluginNames;
|
|
|
|
QList<float> pluginVersions;
|
2015-07-16 09:04:39 +00:00
|
|
|
const int count = m_plugins.count();
|
2015-06-06 15:57:33 +00:00
|
|
|
pluginNames.reserve(count);
|
|
|
|
pluginVersions.reserve(count);
|
2015-07-16 09:04:39 +00:00
|
|
|
for (QHash<QString, QQmlDebugService *>::ConstIterator i = m_plugins.constBegin();
|
|
|
|
i != m_plugins.constEnd(); ++i) {
|
|
|
|
pluginNames << i.key();
|
|
|
|
pluginVersions << i.value()->version();
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
2014-02-06 12:01:05 +00:00
|
|
|
|
|
|
|
out << QString(QStringLiteral("QDeclarativeDebugClient")) << 0 << protocolVersion
|
2015-07-13 10:45:35 +00:00
|
|
|
<< pluginNames << pluginVersions << QQmlDebugStream::s_dataStreamVersion;
|
2014-02-06 12:01:05 +00:00
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
QPacket pack;
|
|
|
|
pack.writeRawData(helloAnswer.data(), helloAnswer.length());
|
|
|
|
m_protocol->send(pack);
|
|
|
|
m_connection->flush();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
QMutexLocker helloLock(&m_helloMutex);
|
|
|
|
m_gotHello = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
for (DebugServiceConstIt iter = m_plugins.constBegin(), cend = m_plugins.constEnd(); iter != cend; ++iter) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
|
2015-07-14 14:36:32 +00:00
|
|
|
if (m_clientPlugins.contains(iter.key()))
|
2012-02-16 04:43:03 +00:00
|
|
|
newState = QQmlDebugService::Enabled;
|
2015-07-14 14:36:32 +00:00
|
|
|
m_changeServiceStateCalls.ref();
|
2015-07-16 09:04:39 +00:00
|
|
|
changeServiceState(iter.key(), newState);
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
m_helloCondition.wakeAll();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
} else if (op == 1) {
|
|
|
|
// Service Discovery
|
2015-07-14 14:36:32 +00:00
|
|
|
QStringList oldClientPlugins = m_clientPlugins;
|
|
|
|
in >> m_clientPlugins;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
for (DebugServiceConstIt iter = m_plugins.constBegin(), cend = m_plugins.constEnd(); iter != cend; ++iter) {
|
2011-09-19 10:29:10 +00:00
|
|
|
const QString pluginName = iter.key();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
|
2015-07-14 14:36:32 +00:00
|
|
|
if (m_clientPlugins.contains(pluginName))
|
2012-02-16 04:43:03 +00:00
|
|
|
newState = QQmlDebugService::Enabled;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
if (oldClientPlugins.contains(pluginName)
|
2015-07-14 14:36:32 +00:00
|
|
|
!= m_clientPlugins.contains(pluginName)) {
|
|
|
|
m_changeServiceStateCalls.ref();
|
2015-07-16 09:04:39 +00:00
|
|
|
changeServiceState(iter.key(), newState);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-19 10:29:10 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2012-03-07 13:53:24 +00:00
|
|
|
qWarning("QML Debugger: Invalid control message %d.", op);
|
2015-06-16 11:40:08 +00:00
|
|
|
invalidPacket();
|
2011-09-19 10:29:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2015-07-14 14:36:32 +00:00
|
|
|
if (m_gotHello) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray message;
|
|
|
|
in >> message;
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
QHash<QString, QQmlDebugService *>::Iterator iter = m_plugins.find(name);
|
|
|
|
if (iter == m_plugins.end()) {
|
2012-05-14 11:50:46 +00:00
|
|
|
qWarning() << "QML Debugger: Message received for missing plugin" << name << '.';
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2011-08-24 11:51:07 +00:00
|
|
|
(*iter)->messageReceived(message);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-09-19 10:29:10 +00:00
|
|
|
} else {
|
2012-03-07 13:53:24 +00:00
|
|
|
qWarning("QML Debugger: Invalid hello message.");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-09-19 10:29:10 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::changeServiceState(const QString &serviceName,
|
|
|
|
QQmlDebugService::State newState)
|
2012-03-16 15:44:24 +00:00
|
|
|
{
|
|
|
|
// to be executed in debugger thread
|
2015-07-14 14:36:32 +00:00
|
|
|
Q_ASSERT(QThread::currentThread() == thread());
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
QQmlDebugService *service = m_plugins.value(serviceName);
|
2015-07-13 14:20:12 +00:00
|
|
|
if (service && service->state() != newState) {
|
2012-03-16 15:44:24 +00:00
|
|
|
service->stateAboutToBeChanged(newState);
|
2015-07-13 14:20:12 +00:00
|
|
|
service->setState(newState);
|
2012-03-16 15:44:24 +00:00
|
|
|
service->stateChanged(newState);
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
m_changeServiceStateCalls.deref();
|
2012-03-16 15:44:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::removeThread()
|
2014-10-10 11:32:38 +00:00
|
|
|
{
|
2015-07-14 14:36:32 +00:00
|
|
|
Q_ASSERT(m_thread->isFinished());
|
|
|
|
Q_ASSERT(QThread::currentThread() == thread());
|
2014-10-10 11:32:38 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
QThread *parentThread = m_thread->thread();
|
2014-10-10 11:32:38 +00:00
|
|
|
|
|
|
|
// We cannot delete it right away as it will access its data after the finished() signal.
|
2015-07-14 14:36:32 +00:00
|
|
|
m_thread->deleteLater();
|
|
|
|
m_thread = 0;
|
2014-10-10 11:32:38 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
delete m_connection;
|
|
|
|
m_connection = 0;
|
2014-10-10 11:32:38 +00:00
|
|
|
|
|
|
|
// Move it back to the parent thread so that we can potentially restart it on a new thread.
|
2015-07-14 14:36:32 +00:00
|
|
|
moveToThread(parentThread);
|
2014-10-10 11:32:38 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
QQmlDebugService *QQmlDebugServerImpl::service(const QString &name) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-14 14:36:32 +00:00
|
|
|
return m_plugins.value(name);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::addEngine(QQmlEngine *engine)
|
2014-02-05 14:38:51 +00:00
|
|
|
{
|
2015-07-13 14:38:25 +00:00
|
|
|
// to be executed outside of debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() != m_thread);
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
QMutexLocker locker(&m_helloMutex);
|
2015-07-14 14:36:32 +00:00
|
|
|
foreach (QQmlDebugService *service, m_plugins)
|
2014-02-05 14:38:51 +00:00
|
|
|
service->engineAboutToBeAdded(engine);
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
m_engineConditions[engine].waitForServices(&m_helloMutex, m_plugins.count());
|
2014-02-05 14:38:51 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
foreach (QQmlDebugService *service, m_plugins)
|
2014-02-05 14:38:51 +00:00
|
|
|
service->engineAdded(engine);
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::removeEngine(QQmlEngine *engine)
|
2014-02-05 14:38:51 +00:00
|
|
|
{
|
2015-07-13 14:38:25 +00:00
|
|
|
// to be executed outside of debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() != m_thread);
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
QMutexLocker locker(&m_helloMutex);
|
2015-07-14 14:36:32 +00:00
|
|
|
foreach (QQmlDebugService *service, m_plugins)
|
2014-02-05 14:38:51 +00:00
|
|
|
service->engineAboutToBeRemoved(engine);
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
m_engineConditions[engine].waitForServices(&m_helloMutex, m_plugins.count());
|
2014-02-05 14:38:51 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
foreach (QQmlDebugService *service, m_plugins)
|
2014-02-05 14:38:51 +00:00
|
|
|
service->engineRemoved(engine);
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
bool QQmlDebugServerImpl::addService(QQmlDebugService *service)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-13 14:38:25 +00:00
|
|
|
// to be executed before thread starts
|
|
|
|
Q_ASSERT(!m_thread);
|
2012-04-11 14:27:14 +00:00
|
|
|
|
2015-07-13 13:56:25 +00:00
|
|
|
connect(service, SIGNAL(messageToClient(QString,QByteArray)),
|
|
|
|
this, SLOT(sendMessage(QString,QByteArray)));
|
|
|
|
connect(service, SIGNAL(messagesToClient(QString,QList<QByteArray>)),
|
|
|
|
this, SLOT(sendMessages(QString,QList<QByteArray>)));
|
|
|
|
|
2014-02-06 13:43:26 +00:00
|
|
|
connect(service, SIGNAL(attachedToEngine(QQmlEngine*)),
|
|
|
|
this, SLOT(wakeEngine(QQmlEngine*)), Qt::QueuedConnection);
|
|
|
|
connect(service, SIGNAL(detachedFromEngine(QQmlEngine*)),
|
|
|
|
this, SLOT(wakeEngine(QQmlEngine*)), Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
if (!service || m_plugins.contains(service->name()))
|
2014-02-06 12:01:05 +00:00
|
|
|
return false;
|
2015-07-14 14:36:32 +00:00
|
|
|
m_plugins.insert(service->name(), service);
|
2014-02-06 12:01:05 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
|
2015-07-14 14:36:32 +00:00
|
|
|
if (m_clientPlugins.contains(service->name()))
|
2014-02-06 12:01:05 +00:00
|
|
|
newState = QQmlDebugService::Enabled;
|
2015-07-13 14:20:12 +00:00
|
|
|
service->setState(newState);
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
bool QQmlDebugServerImpl::removeService(QQmlDebugService *service)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-13 14:38:25 +00:00
|
|
|
// to be executed after thread ends
|
|
|
|
Q_ASSERT(!m_thread);
|
2012-04-11 14:27:14 +00:00
|
|
|
|
2014-02-06 12:01:05 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::NotConnected;
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
m_changeServiceStateCalls.ref();
|
|
|
|
QMetaObject::invokeMethod(this, "changeServiceState", Qt::QueuedConnection,
|
2014-02-06 12:01:05 +00:00
|
|
|
Q_ARG(QString, service->name()),
|
|
|
|
Q_ARG(QQmlDebugService::State, newState));
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
if (!service || !m_plugins.contains(service->name()))
|
2014-02-06 12:01:05 +00:00
|
|
|
return false;
|
2015-07-13 13:56:25 +00:00
|
|
|
|
|
|
|
disconnect(service, SIGNAL(messagesToClient(QString,QList<QByteArray>)),
|
|
|
|
this, SLOT(sendMessages(QString,QList<QByteArray>)));
|
|
|
|
disconnect(service, SIGNAL(messageToClient(QString,QByteArray)),
|
|
|
|
this, SLOT(sendMessage(QString,QByteArray)));
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
m_plugins.remove(service->name());
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
bool QQmlDebugServerImpl::canSendMessage(const QString &name)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-06-16 11:40:08 +00:00
|
|
|
// to be executed in debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() == thread());
|
|
|
|
return m_connection && m_connection->isConnected() && m_protocol &&
|
|
|
|
m_clientPlugins.contains(name);
|
2015-07-13 13:56:25 +00:00
|
|
|
}
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
void QQmlDebugServerImpl::doSendMessage(const QString &name, const QByteArray &message)
|
2015-07-13 13:56:25 +00:00
|
|
|
{
|
2015-06-16 11:40:08 +00:00
|
|
|
QByteArray prefixed;
|
|
|
|
QQmlDebugStream out(&prefixed, QIODevice::WriteOnly);
|
|
|
|
out << name << message;
|
2015-07-13 13:56:25 +00:00
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
QPacket pack;
|
|
|
|
pack.writeRawData(prefixed.data(), prefixed.length());
|
|
|
|
m_protocol->send(pack);
|
|
|
|
}
|
2015-07-13 13:56:25 +00:00
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
void QQmlDebugServerImpl::sendMessage(const QString &name, const QByteArray &message)
|
|
|
|
{
|
|
|
|
if (canSendMessage(name)) {
|
|
|
|
doSendMessage(name, message);
|
|
|
|
m_connection->flush();
|
|
|
|
}
|
|
|
|
}
|
2015-07-13 13:56:25 +00:00
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
void QQmlDebugServerImpl::sendMessages(const QString &name, const QList<QByteArray> &messages)
|
|
|
|
{
|
|
|
|
if (canSendMessage(name)) {
|
|
|
|
foreach (const QByteArray &message, messages)
|
|
|
|
doSendMessage(name, message);
|
|
|
|
m_connection->flush();
|
2015-07-13 13:56:25 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 14:57:06 +00:00
|
|
|
template<class Action>
|
2015-07-14 14:36:32 +00:00
|
|
|
bool QQmlDebugServerImpl::enable(Action action)
|
2014-10-10 11:32:38 +00:00
|
|
|
{
|
2015-07-29 10:28:10 +00:00
|
|
|
if (m_thread)
|
2014-10-10 11:32:38 +00:00
|
|
|
return false;
|
2015-07-29 10:28:10 +00:00
|
|
|
if (!action(this))
|
2014-10-10 11:32:38 +00:00
|
|
|
return false;
|
2015-07-29 10:28:10 +00:00
|
|
|
QMutexLocker locker(&m_helloMutex);
|
2015-07-29 10:51:23 +00:00
|
|
|
m_thread->start();
|
|
|
|
m_helloCondition.wait(&m_helloMutex); // wait for connection
|
2015-07-29 10:28:10 +00:00
|
|
|
if (m_blockingMode && !m_gotHello)
|
2015-07-29 10:51:23 +00:00
|
|
|
m_helloCondition.wait(&m_helloMutex); // wait for hello
|
2014-10-10 11:32:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::wakeEngine(QQmlEngine *engine)
|
2014-02-06 13:43:26 +00:00
|
|
|
{
|
|
|
|
// to be executed in debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() == thread());
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
QMutexLocker locker(&m_helloMutex);
|
2015-07-14 14:36:32 +00:00
|
|
|
m_engineConditions[engine].wake();
|
2014-02-06 13:43:26 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 14:02:35 +00:00
|
|
|
bool QQmlDebugServerImpl::EngineCondition::waitForServices(QMutex *locked, int num)
|
2014-02-06 13:43:26 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT_X(numServices == 0, Q_FUNC_INFO, "Request to wait again before previous wait finished");
|
|
|
|
numServices = num;
|
2015-07-27 11:54:12 +00:00
|
|
|
return numServices > 0 ? condition->wait(locked) : true;
|
2014-02-06 13:43:26 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
void QQmlDebugServerImpl::EngineCondition::wake()
|
2014-02-06 13:43:26 +00:00
|
|
|
{
|
|
|
|
if (--numServices == 0)
|
|
|
|
condition->wakeAll();
|
|
|
|
Q_ASSERT_X(numServices >=0, Q_FUNC_INFO, "Woken more often than #services.");
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:40:08 +00:00
|
|
|
void QQmlDebugServerImpl::setDevice(QIODevice *socket)
|
|
|
|
{
|
|
|
|
m_protocol = new QPacketProtocol(socket, this);
|
|
|
|
QObject::connect(m_protocol, SIGNAL(readyRead()), this, SLOT(receiveMessage()));
|
|
|
|
QObject::connect(m_protocol, SIGNAL(invalidPacket()), this, SLOT(invalidPacket()));
|
|
|
|
|
|
|
|
if (blockingMode())
|
|
|
|
m_protocol->waitForReadyRead(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QQmlDebugServerImpl::invalidPacket()
|
|
|
|
{
|
|
|
|
qWarning("QML Debugger: Received a corrupted packet! Giving up ...");
|
|
|
|
m_connection->disconnect();
|
|
|
|
// protocol might still be processing packages at this point
|
|
|
|
m_protocol->deleteLater();
|
|
|
|
m_protocol = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-14 16:35:02 +00:00
|
|
|
QQmlDebugConnector *QQmlDebugServerFactory::create(const QString &key)
|
|
|
|
{
|
|
|
|
// Cannot parent it to this because it gets moved to another thread
|
|
|
|
return (key == QLatin1String("QQmlDebugServer") ? new QQmlDebugServerImpl : 0);
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2015-07-14 14:36:32 +00:00
|
|
|
#include "qqmldebugserver.moc"
|