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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "qqmldebugserver_p.h"
|
|
|
|
#include "qqmldebugservice_p.h"
|
|
|
|
#include "qqmldebugservice_p_p.h"
|
2014-02-05 14:38:51 +00:00
|
|
|
#include "qqmlenginedebugservice_p.h"
|
|
|
|
#include "qv4debugservice_p.h"
|
|
|
|
#include "qdebugmessageservice_p.h"
|
|
|
|
#include "qqmlprofilerservice_p.h"
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <private/qqmlengine_p.h>
|
|
|
|
#include <private/qqmlglobal_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
|
|
|
|
2014-12-17 10:00:41 +00:00
|
|
|
#if defined(QT_STATIC) && ! defined(QT_NO_QML_DEBUGGER)
|
2014-02-24 15:37:44 +00:00
|
|
|
#include "../../plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h"
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
// We can't friend the Q_GLOBAL_STATIC to have the constructor available so we need a little
|
|
|
|
// workaround here. Using this wrapper we can also make QQmlEnginePrivate's cleanup() available to
|
|
|
|
// qAddPostRoutine(). We can't do the cleanup in the destructor because we need a QApplication to
|
|
|
|
// be available when stopping the plugins.
|
|
|
|
struct QQmlDebugServerInstanceWrapper {
|
|
|
|
QQmlDebugServer m_instance;
|
|
|
|
void cleanup();
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_GLOBAL_STATIC(QQmlDebugServerInstanceWrapper, debugServerInstance)
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*
|
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
|
2011-04-27 10:05:43 +00:00
|
|
|
server plugin advertisement
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
const int protocolVersion = 1;
|
2012-04-23 07:23:23 +00:00
|
|
|
int QQmlDebugServer::s_dataStreamVersion = QDataStream::Qt_4_7;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-31 13:40:37 +00:00
|
|
|
// print detailed information about loading of plugins
|
|
|
|
DEFINE_BOOL_CONFIG_OPTION(qmlDebugVerbose, QML_DEBUGGER_VERBOSE)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQmlDebugServerThread;
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQmlDebugServerPrivate : public QObjectPrivate
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_DECLARE_PUBLIC(QQmlDebugServer)
|
2011-04-27 10:05:43 +00:00
|
|
|
public:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerPrivate();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
bool start(int portFrom, int portTo, bool block, const QString &hostAddress,
|
|
|
|
const QString &pluginName);
|
2011-04-27 10:05:43 +00:00
|
|
|
void advertisePlugins();
|
2014-01-30 11:19:13 +00:00
|
|
|
void cleanup();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerConnection *loadConnectionPlugin(const QString &pluginName);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerConnection *connection;
|
|
|
|
QHash<QString, QQmlDebugService *> plugins;
|
2011-08-24 11:51:07 +00:00
|
|
|
mutable QReadWriteLock pluginsLock;
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList clientPlugins;
|
|
|
|
bool gotHello;
|
2012-04-24 12:39:38 +00:00
|
|
|
bool blockingMode;
|
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) {}
|
|
|
|
|
|
|
|
bool waitForServices(QReadWriteLock *locked, int numEngines);
|
|
|
|
|
|
|
|
void wake();
|
|
|
|
private:
|
|
|
|
int numServices;
|
|
|
|
|
|
|
|
// shared pointer to allow for QHash-inflicted copying.
|
|
|
|
QSharedPointer<QWaitCondition> condition;
|
|
|
|
};
|
|
|
|
|
|
|
|
QHash<QQmlEngine *, EngineCondition> engineConditions;
|
|
|
|
|
2013-04-23 09:49:36 +00:00
|
|
|
QMutex helloMutex;
|
|
|
|
QWaitCondition helloCondition;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerThread *thread;
|
2011-08-24 11:51:07 +00:00
|
|
|
QPluginLoader loader;
|
2012-03-16 15:44:24 +00:00
|
|
|
QAtomicInt changeServiceStateCalls;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
private:
|
2012-03-16 15:44:24 +00:00
|
|
|
// private slots
|
|
|
|
void _q_changeServiceState(const QString &serviceName,
|
|
|
|
QQmlDebugService::State newState);
|
2011-12-20 15:54:50 +00:00
|
|
|
void _q_sendMessages(const QList<QByteArray> &messages);
|
2014-10-10 11:32:38 +00:00
|
|
|
void _q_removeThread();
|
2011-08-24 11:51:07 +00:00
|
|
|
};
|
2011-11-17 11:19:45 +00:00
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
void QQmlDebugServerInstanceWrapper::cleanup()
|
|
|
|
{ m_instance.d_func()->cleanup(); }
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class QQmlDebugServerThread : public QThread
|
2011-08-24 11:51:07 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
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;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerPrivate::QQmlDebugServerPrivate() :
|
2011-04-27 10:05:43 +00:00
|
|
|
connection(0),
|
2013-10-07 14:18:23 +00:00
|
|
|
pluginsLock(QReadWriteLock::Recursive),
|
2011-08-24 10:13:39 +00:00
|
|
|
gotHello(false),
|
2012-04-24 12:39:38 +00:00
|
|
|
blockingMode(false),
|
2011-08-24 11:51:07 +00:00
|
|
|
thread(0)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-12-20 15:54:50 +00:00
|
|
|
// used in _q_sendMessages
|
|
|
|
qRegisterMetaType<QList<QByteArray> >("QList<QByteArray>");
|
2012-03-16 15:44:24 +00:00
|
|
|
// used in _q_changeServiceState
|
|
|
|
qRegisterMetaType<QQmlDebugService::State>("QQmlDebugService::State");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServerPrivate::advertisePlugins()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_Q(QQmlDebugServer);
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!gotHello)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QByteArray message;
|
|
|
|
{
|
2012-04-23 07:23:23 +00:00
|
|
|
QQmlDebugStream out(&message, QIODevice::WriteOnly);
|
2011-12-15 16:52:22 +00:00
|
|
|
QStringList pluginNames;
|
|
|
|
QList<float> pluginVersions;
|
2015-06-06 15:57:33 +00:00
|
|
|
const QList<QQmlDebugService *> debugServices = plugins.values();
|
|
|
|
const int count = debugServices.count();
|
|
|
|
pluginNames.reserve(count);
|
|
|
|
pluginVersions.reserve(count);
|
|
|
|
foreach (QQmlDebugService *service, debugServices) {
|
2011-12-15 16:52:22 +00:00
|
|
|
pluginNames << service->name();
|
|
|
|
pluginVersions << service->version();
|
|
|
|
}
|
2012-03-08 14:01:53 +00:00
|
|
|
out << QString(QStringLiteral("QDeclarativeDebugClient")) << 1 << pluginNames << pluginVersions;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2011-12-20 15:54:50 +00:00
|
|
|
QMetaObject::invokeMethod(q, "_q_sendMessages", Qt::QueuedConnection, Q_ARG(QList<QByteArray>, QList<QByteArray>() << message));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
void QQmlDebugServerPrivate::cleanup()
|
|
|
|
{
|
|
|
|
Q_Q(QQmlDebugServer);
|
|
|
|
{
|
|
|
|
QReadLocker lock(&pluginsLock);
|
|
|
|
foreach (QQmlDebugService *service, plugins.values()) {
|
|
|
|
changeServiceStateCalls.ref();
|
|
|
|
QMetaObject::invokeMethod(q, "_q_changeServiceState", Qt::QueuedConnection,
|
|
|
|
Q_ARG(QString, service->name()),
|
|
|
|
Q_ARG(QQmlDebugService::State, QQmlDebugService::NotConnected));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
while (!changeServiceStateCalls.testAndSetOrdered(0, 0))
|
|
|
|
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.
|
|
|
|
QThread *threadCopy = thread;
|
|
|
|
if (threadCopy) {
|
|
|
|
threadCopy->exit();
|
|
|
|
threadCopy->wait();
|
2014-01-30 11:19:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerConnection *QQmlDebugServerPrivate::loadConnectionPlugin(
|
2011-08-24 11:51:07 +00:00
|
|
|
const QString &pluginName)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-02 09:23:47 +00:00
|
|
|
#ifndef QT_NO_LIBRARY
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList pluginCandidates;
|
|
|
|
const QStringList paths = QCoreApplication::libraryPaths();
|
|
|
|
foreach (const QString &libPath, paths) {
|
|
|
|
const QDir dir(libPath + QLatin1String("/qmltooling"));
|
|
|
|
if (dir.exists()) {
|
|
|
|
QStringList plugins(dir.entryList(QDir::Files));
|
|
|
|
foreach (const QString &pluginPath, plugins) {
|
|
|
|
if (QFileInfo(pluginPath).fileName().contains(pluginName))
|
|
|
|
pluginCandidates << dir.absoluteFilePath(pluginPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
QQmlDebugServerConnection *loadedConnection = 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
foreach (const QString &pluginPath, pluginCandidates) {
|
2011-10-31 13:40:37 +00:00
|
|
|
if (qmlDebugVerbose())
|
2012-03-07 13:53:24 +00:00
|
|
|
qDebug() << "QML Debugger: Trying to load plugin " << pluginPath << "...";
|
2011-10-31 13:40:37 +00:00
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
loader.setFileName(pluginPath);
|
|
|
|
if (!loader.load()) {
|
2011-10-31 13:40:37 +00:00
|
|
|
if (qmlDebugVerbose())
|
2012-03-07 13:53:24 +00:00
|
|
|
qDebug() << "QML Debugger: Error while loading: " << loader.errorString();
|
2011-04-27 10:05:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-08-24 11:51:07 +00:00
|
|
|
if (QObject *instance = loader.instance())
|
2014-10-10 11:32:38 +00:00
|
|
|
loadedConnection = qobject_cast<QQmlDebugServerConnection*>(instance);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
if (loadedConnection) {
|
2011-10-31 13:40:37 +00:00
|
|
|
if (qmlDebugVerbose())
|
2012-03-07 13:53:24 +00:00
|
|
|
qDebug() << "QML Debugger: Plugin successfully loaded.";
|
2011-10-31 13:40:37 +00:00
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
return loadedConnection;
|
2011-10-31 13:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qmlDebugVerbose())
|
2012-03-07 13:53:24 +00:00
|
|
|
qDebug() << "QML Debugger: Plugin does not implement interface QQmlDebugServerConnection.";
|
2011-10-31 13:40:37 +00:00
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
loader.unload();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-05-02 09:23:47 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServerThread::run()
|
2011-08-24 11:51:07 +00:00
|
|
|
{
|
2014-01-30 11:19:13 +00:00
|
|
|
QQmlDebugServerInstanceWrapper *wrapper = debugServerInstance();
|
|
|
|
Q_ASSERT_X(wrapper != 0, Q_FUNC_INFO, "There should always be a debug server available here.");
|
|
|
|
QQmlDebugServer *server = &wrapper->m_instance;
|
2014-12-17 10:00:41 +00:00
|
|
|
#if defined(QT_STATIC) && ! defined(QT_NO_QML_DEBUGGER)
|
2014-02-24 15:37:44 +00:00
|
|
|
QQmlDebugServerConnection *connection
|
|
|
|
= new QTcpServerConnection;
|
|
|
|
#else
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerConnection *connection
|
2011-08-24 11:51:07 +00:00
|
|
|
= server->d_func()->loadConnectionPlugin(m_pluginName);
|
2014-02-24 15:37:44 +00:00
|
|
|
#endif
|
2011-08-24 11:51:07 +00:00
|
|
|
if (connection) {
|
2014-01-30 11:19:13 +00:00
|
|
|
connection->setServer(server);
|
2014-10-10 11:32:38 +00:00
|
|
|
if (!connection->setPortRange(m_portFrom, m_portTo, m_block, m_hostAddress)) {
|
|
|
|
delete connection;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
server->d_func()->connection = connection;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQmlDebugServer::hasDebuggingClient() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQmlDebugServer);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->connection
|
|
|
|
&& d->connection->isConnected()
|
|
|
|
&& d->gotHello;
|
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
bool QQmlDebugServer::hasThread() const
|
|
|
|
{
|
|
|
|
Q_D(const QQmlDebugServer);
|
|
|
|
return d->thread != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlDebugServer::hasConnection() const
|
|
|
|
{
|
|
|
|
Q_D(const QQmlDebugServer);
|
|
|
|
return d->connection != 0;
|
|
|
|
}
|
|
|
|
|
2012-04-24 12:39:38 +00:00
|
|
|
bool QQmlDebugServer::blockingMode() const
|
|
|
|
{
|
|
|
|
Q_D(const QQmlDebugServer);
|
|
|
|
return d->blockingMode;
|
|
|
|
}
|
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
QQmlDebugServer *QQmlDebugServer::instance()
|
2011-12-20 12:41:50 +00:00
|
|
|
{
|
2014-01-30 11:19:13 +00:00
|
|
|
QQmlDebugServerInstanceWrapper *wrapper = debugServerInstance();
|
|
|
|
if (wrapper && wrapper->m_instance.d_func()->thread) {
|
|
|
|
QQmlDebugServer *ret = &(wrapper->m_instance);
|
|
|
|
QQmlDebugServerPrivate *d = ret->d_func();
|
|
|
|
QMutexLocker locker(&d->helloMutex);
|
|
|
|
if (d->blockingMode && !d->gotHello)
|
|
|
|
d->helloCondition.wait(&d->helloMutex);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-20 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
static void cleanupOnShutdown()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2014-01-30 11:19:13 +00:00
|
|
|
QQmlDebugServerInstanceWrapper *wrapper = debugServerInstance();
|
|
|
|
if (wrapper)
|
|
|
|
wrapper->cleanup();
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
bool QQmlDebugServerPrivate::start(int portFrom, int portTo, bool block, const QString &hostAddress,
|
|
|
|
const QString &pluginName)
|
|
|
|
{
|
|
|
|
if (!QQmlEnginePrivate::qml_debugging_enabled)
|
|
|
|
return false;
|
|
|
|
if (thread)
|
|
|
|
return false;
|
|
|
|
static bool postRoutineAdded = false;
|
|
|
|
if (!postRoutineAdded) {
|
|
|
|
qAddPostRoutine(cleanupOnShutdown);
|
|
|
|
postRoutineAdded = true;
|
|
|
|
}
|
|
|
|
Q_Q(QQmlDebugServer);
|
|
|
|
thread = new QQmlDebugServerThread;
|
|
|
|
q->moveToThread(thread);
|
|
|
|
|
|
|
|
// Remove the thread immmediately when it finishes, so that we don't have to wait for the event
|
|
|
|
// loop to signal that.
|
|
|
|
QObject::connect(thread, SIGNAL(finished()), q, SLOT(_q_removeThread()), Qt::DirectConnection);
|
|
|
|
|
|
|
|
thread->setObjectName(QStringLiteral("QQmlDebugServerThread"));
|
|
|
|
thread->setPluginName(pluginName);
|
|
|
|
thread->setPortRange(portFrom, portTo == -1 ? portFrom : portTo, block, hostAddress);
|
|
|
|
blockingMode = block;
|
|
|
|
thread->start();
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
QQmlDebugServer::QQmlDebugServer()
|
|
|
|
: QObject(*(new QQmlDebugServerPrivate))
|
|
|
|
{
|
2014-10-10 11:32:38 +00:00
|
|
|
if (qApp == 0)
|
|
|
|
return;
|
2014-01-30 11:19:13 +00:00
|
|
|
QCoreApplicationPrivate *appD = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp));
|
2014-12-17 10:00:41 +00:00
|
|
|
#ifndef QT_NO_QML_DEBUGGER
|
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;
|
|
|
|
|
|
|
|
// format: qmljsdebugger=port:<port_from>[,port_to],host:<ip address>][,block]
|
|
|
|
if (!appD->qmljsDebugArgumentsString().isEmpty()) {
|
|
|
|
if (!QQmlEnginePrivate::qml_debugging_enabled) {
|
|
|
|
qWarning() << QString(QLatin1String(
|
|
|
|
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
|
|
|
"Debugging has not been enabled.")).arg(
|
|
|
|
appD->qmljsDebugArgumentsString());
|
|
|
|
return;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
QString pluginName;
|
|
|
|
QStringList lstjsDebugArguments = appD->qmljsDebugArgumentsString()
|
|
|
|
.split(QLatin1Char(','));
|
2015-05-14 12:31:52 +00:00
|
|
|
QStringList::const_iterator argsItEnd = lstjsDebugArguments.cend();
|
|
|
|
QStringList::const_iterator argsIt = lstjsDebugArguments.cbegin();
|
2014-01-30 11:19:13 +00:00
|
|
|
for (; argsIt != argsItEnd; ++argsIt) {
|
|
|
|
const QString strArgument = *argsIt;
|
|
|
|
if (strArgument.startsWith(QLatin1String("port:"))) {
|
|
|
|
pluginName = QLatin1String("qmldbg_tcp");
|
|
|
|
portFrom = strArgument.mid(5).toInt(&ok);
|
|
|
|
portTo = portFrom;
|
|
|
|
QStringList::const_iterator argsNext = argsIt + 1;
|
|
|
|
if (argsNext == argsItEnd)
|
|
|
|
break;
|
|
|
|
const QString nextArgument = *argsNext;
|
|
|
|
if (ok && nextArgument.contains(QRegExp(QStringLiteral("^\\s*\\d+\\s*$")))) {
|
|
|
|
portTo = nextArgument.toInt(&ok);
|
|
|
|
++argsIt;
|
2012-03-14 12:35:17 +00:00
|
|
|
}
|
2014-01-30 11:19:13 +00:00
|
|
|
} else if (strArgument.startsWith(QLatin1String("host:"))) {
|
|
|
|
hostAddress = strArgument.mid(5);
|
|
|
|
} else if (strArgument == QLatin1String("block")) {
|
|
|
|
block = true;
|
|
|
|
} else {
|
|
|
|
qWarning() << QString::fromLatin1("QML Debugger: Invalid argument '%1' "
|
|
|
|
"detected. Ignoring the same.")
|
|
|
|
.arg(strArgument);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2014-01-30 11:19:13 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
if (ok) {
|
|
|
|
Q_D(QQmlDebugServer);
|
2014-10-10 11:32:38 +00:00
|
|
|
d->start(portFrom, portTo, block, hostAddress, pluginName);
|
2014-01-30 11:19:13 +00:00
|
|
|
} else {
|
2012-03-08 14:01:53 +00:00
|
|
|
qWarning() << QString(QLatin1String(
|
2014-01-30 11:19:13 +00:00
|
|
|
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
|
|
|
"Format is qmljsdebugger=port:<port_from>[,port_to],host:"
|
|
|
|
"<ip address>][,block]")).arg(appD->qmljsDebugArgumentsString());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 11:19:13 +00:00
|
|
|
#else
|
|
|
|
if (!appD->qmljsDebugArgumentsString().isEmpty()) {
|
|
|
|
qWarning() << QString(QLatin1String(
|
|
|
|
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
|
|
|
"QtQml is not configured for debugging.")).arg(
|
|
|
|
appD->qmljsDebugArgumentsString());
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-20 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServer::receiveMessage(const QByteArray &message)
|
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());
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQmlDebugServer);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-04-23 07:23:23 +00:00
|
|
|
QQmlDebugStream in(message);
|
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) {
|
2014-02-06 12:01:05 +00:00
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
2011-09-19 10:29:10 +00:00
|
|
|
int version;
|
|
|
|
in >> version >> d->clientPlugins;
|
|
|
|
|
2012-04-23 07:23:23 +00:00
|
|
|
//Get the supported QDataStream version
|
|
|
|
if (!in.atEnd()) {
|
|
|
|
in >> s_dataStreamVersion;
|
|
|
|
if (s_dataStreamVersion > QDataStream().version())
|
|
|
|
s_dataStreamVersion = QDataStream().version();
|
|
|
|
}
|
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-06-06 15:57:33 +00:00
|
|
|
const QList<QQmlDebugService*> debugServices = d->plugins.values();
|
|
|
|
const int count = debugServices.count();
|
|
|
|
pluginNames.reserve(count);
|
|
|
|
pluginVersions.reserve(count);
|
|
|
|
foreach (QQmlDebugService *service, debugServices) {
|
2014-02-06 12:01:05 +00:00
|
|
|
pluginNames << service->name();
|
|
|
|
pluginVersions << service->version();
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
2014-02-06 12:01:05 +00:00
|
|
|
|
|
|
|
out << QString(QStringLiteral("QDeclarativeDebugClient")) << 0 << protocolVersion
|
|
|
|
<< pluginNames << pluginVersions << s_dataStreamVersion;
|
|
|
|
|
2011-12-20 15:54:50 +00:00
|
|
|
d->connection->send(QList<QByteArray>() << helloAnswer);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-01-30 11:19:13 +00:00
|
|
|
QMutexLocker helloLock(&d->helloMutex);
|
2011-09-19 10:29:10 +00:00
|
|
|
d->gotHello = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-02-23 12:44:12 +00:00
|
|
|
for (DebugServiceConstIt iter = d->plugins.constBegin(), cend = d->plugins.constEnd(); iter != cend; ++iter) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
|
2011-09-19 10:29:10 +00:00
|
|
|
if (d->clientPlugins.contains(iter.key()))
|
2012-02-16 04:43:03 +00:00
|
|
|
newState = QQmlDebugService::Enabled;
|
2012-03-16 15:44:24 +00:00
|
|
|
d->changeServiceStateCalls.ref();
|
|
|
|
d->_q_changeServiceState(iter.value()->name(), newState);
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-04-23 09:49:36 +00:00
|
|
|
d->helloCondition.wakeAll();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
} else if (op == 1) {
|
2014-02-06 12:01:05 +00:00
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
// Service Discovery
|
|
|
|
QStringList oldClientPlugins = d->clientPlugins;
|
|
|
|
in >> d->clientPlugins;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-02-23 12:44:12 +00:00
|
|
|
for (DebugServiceConstIt iter = d->plugins.constBegin(), cend = d->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;
|
2011-09-19 10:29:10 +00:00
|
|
|
if (d->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)
|
|
|
|
!= d->clientPlugins.contains(pluginName)) {
|
2012-03-16 15:44:24 +00:00
|
|
|
d->changeServiceStateCalls.ref();
|
|
|
|
d->_q_changeServiceState(iter.value()->name(), 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);
|
2011-09-19 10:29:10 +00:00
|
|
|
d->connection->disconnect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (d->gotHello) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray message;
|
|
|
|
in >> message;
|
|
|
|
|
2012-04-11 14:26:15 +00:00
|
|
|
QReadLocker lock(&d->pluginsLock);
|
2012-02-16 04:43:03 +00:00
|
|
|
QHash<QString, QQmlDebugService *>::Iterator iter = d->plugins.find(name);
|
2011-08-24 11:51:07 +00:00
|
|
|
if (iter == d->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-16 15:44:24 +00:00
|
|
|
void QQmlDebugServerPrivate::_q_changeServiceState(const QString &serviceName,
|
|
|
|
QQmlDebugService::State newState)
|
|
|
|
{
|
|
|
|
// to be executed in debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() == q_func()->thread());
|
|
|
|
|
|
|
|
QQmlDebugService *service = 0;
|
|
|
|
{
|
2014-02-06 12:01:05 +00:00
|
|
|
// Write lock here, because this can be called from receiveMessage which already has a write
|
|
|
|
// lock. We cannot downgrade it. We also don't want to give up the write lock and later get
|
|
|
|
// a read lock as that technique has great potential for deadlocks.
|
|
|
|
QWriteLocker lock(&pluginsLock);
|
2012-03-16 15:44:24 +00:00
|
|
|
service = plugins.value(serviceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (service && (service->d_func()->state != newState)) {
|
|
|
|
service->stateAboutToBeChanged(newState);
|
|
|
|
service->d_func()->state = newState;
|
|
|
|
service->stateChanged(newState);
|
|
|
|
}
|
|
|
|
|
|
|
|
changeServiceStateCalls.deref();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServerPrivate::_q_sendMessages(const QList<QByteArray> &messages)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-03-16 15:44:24 +00:00
|
|
|
// to be executed in debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() == q_func()->thread());
|
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
if (connection)
|
2011-12-20 15:54:50 +00:00
|
|
|
connection->send(messages);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
void QQmlDebugServerPrivate::_q_removeThread()
|
|
|
|
{
|
|
|
|
Q_ASSERT(thread->isFinished());
|
|
|
|
Q_ASSERT(QThread::currentThread() == thread);
|
|
|
|
|
|
|
|
QThread *parentThread = thread->thread();
|
|
|
|
|
|
|
|
// We cannot delete it right away as it will access its data after the finished() signal.
|
|
|
|
thread->deleteLater();
|
|
|
|
thread = 0;
|
|
|
|
|
|
|
|
delete connection;
|
|
|
|
connection = 0;
|
|
|
|
|
|
|
|
// Move it back to the parent thread so that we can potentially restart it on a new thread.
|
|
|
|
q_func()->moveToThread(parentThread);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QQmlDebugService*> QQmlDebugServer::services() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-10 15:36:31 +00:00
|
|
|
Q_D(const QQmlDebugServer);
|
2012-04-11 14:26:15 +00:00
|
|
|
QReadLocker lock(&d->pluginsLock);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->plugins.values();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QStringList QQmlDebugServer::serviceNames() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-04-10 15:36:31 +00:00
|
|
|
Q_D(const QQmlDebugServer);
|
2012-04-11 14:26:15 +00:00
|
|
|
QReadLocker lock(&d->pluginsLock);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->plugins.keys();
|
|
|
|
}
|
|
|
|
|
2014-02-05 14:38:51 +00:00
|
|
|
void QQmlDebugServer::addEngine(QQmlEngine *engine)
|
|
|
|
{
|
|
|
|
Q_D(QQmlDebugServer);
|
2014-02-06 13:43:26 +00:00
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
2014-02-05 14:38:51 +00:00
|
|
|
|
|
|
|
foreach (QQmlDebugService *service, d->plugins)
|
|
|
|
service->engineAboutToBeAdded(engine);
|
|
|
|
|
2014-02-06 13:43:26 +00:00
|
|
|
d->engineConditions[engine].waitForServices(&d->pluginsLock, d->plugins.count());
|
2014-02-05 14:38:51 +00:00
|
|
|
|
|
|
|
foreach (QQmlDebugService *service, d->plugins)
|
|
|
|
service->engineAdded(engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QQmlDebugServer::removeEngine(QQmlEngine *engine)
|
|
|
|
{
|
|
|
|
Q_D(QQmlDebugServer);
|
2014-02-06 13:43:26 +00:00
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
2014-02-05 14:38:51 +00:00
|
|
|
|
|
|
|
foreach (QQmlDebugService *service, d->plugins)
|
|
|
|
service->engineAboutToBeRemoved(engine);
|
|
|
|
|
2014-02-06 13:43:26 +00:00
|
|
|
d->engineConditions[engine].waitForServices(&d->pluginsLock, d->plugins.count());
|
2014-02-05 14:38:51 +00:00
|
|
|
|
|
|
|
foreach (QQmlDebugService *service, d->plugins)
|
|
|
|
service->engineRemoved(engine);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQmlDebugServer::addService(QQmlDebugService *service)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQmlDebugServer);
|
2012-04-11 14:27:14 +00:00
|
|
|
|
2014-01-29 16:30:14 +00:00
|
|
|
// to be executed outside of debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() != thread());
|
2012-04-11 14:27:14 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
2014-02-06 12:01:05 +00:00
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
|
|
|
if (!service || d->plugins.contains(service->name()))
|
|
|
|
return false;
|
|
|
|
d->plugins.insert(service->name(), service);
|
|
|
|
d->advertisePlugins();
|
|
|
|
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
|
|
|
|
if (d->clientPlugins.contains(service->name()))
|
|
|
|
newState = QQmlDebugService::Enabled;
|
|
|
|
service->d_func()->state = newState;
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQmlDebugServer::removeService(QQmlDebugService *service)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQmlDebugServer);
|
2012-04-11 14:27:14 +00:00
|
|
|
|
2014-01-29 16:30:14 +00:00
|
|
|
// to be executed outside of debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() != thread());
|
2012-04-11 14:27:14 +00:00
|
|
|
|
2014-02-06 12:01:05 +00:00
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
|
|
|
QQmlDebugService::State newState = QQmlDebugService::NotConnected;
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2014-02-06 12:01:05 +00:00
|
|
|
d->changeServiceStateCalls.ref();
|
|
|
|
QMetaObject::invokeMethod(this, "_q_changeServiceState", Qt::QueuedConnection,
|
|
|
|
Q_ARG(QString, service->name()),
|
|
|
|
Q_ARG(QQmlDebugService::State, newState));
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2014-02-06 12:01:05 +00:00
|
|
|
if (!service || !d->plugins.contains(service->name()))
|
|
|
|
return false;
|
|
|
|
d->plugins.remove(service->name());
|
2012-03-16 15:44:24 +00:00
|
|
|
|
2014-02-06 12:01:05 +00:00
|
|
|
d->advertisePlugins();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServer::sendMessages(QQmlDebugService *service,
|
2011-12-20 15:54:50 +00:00
|
|
|
const QList<QByteArray> &messages)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-12-20 15:54:50 +00:00
|
|
|
QList<QByteArray> prefixedMessages;
|
2015-06-06 15:57:33 +00:00
|
|
|
prefixedMessages.reserve(messages.count());
|
2011-12-20 15:54:50 +00:00
|
|
|
foreach (const QByteArray &message, messages) {
|
|
|
|
QByteArray prefixed;
|
2012-04-23 07:23:23 +00:00
|
|
|
QQmlDebugStream out(&prefixed, QIODevice::WriteOnly);
|
2011-04-27 10:05:43 +00:00
|
|
|
out << service->name() << message;
|
2011-12-20 15:54:50 +00:00
|
|
|
prefixedMessages << prefixed;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2012-03-16 15:44:24 +00:00
|
|
|
QMetaObject::invokeMethod(this, "_q_sendMessages", Qt::QueuedConnection,
|
|
|
|
Q_ARG(QList<QByteArray>, prefixedMessages));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 11:32:38 +00:00
|
|
|
bool QQmlDebugServer::enable(int portFrom, int portTo, bool block, const QString &hostAddress)
|
|
|
|
{
|
2014-12-17 10:00:41 +00:00
|
|
|
#ifndef QT_NO_QML_DEBUGGER
|
2014-10-10 11:32:38 +00:00
|
|
|
QQmlDebugServerInstanceWrapper *wrapper = debugServerInstance();
|
|
|
|
if (!wrapper)
|
|
|
|
return false;
|
|
|
|
QQmlDebugServerPrivate *d = wrapper->m_instance.d_func();
|
|
|
|
if (d->thread)
|
|
|
|
return false;
|
|
|
|
if (!d->start(portFrom, portTo, block, hostAddress, QLatin1String("qmldbg_tcp")))
|
|
|
|
return false;
|
|
|
|
while (!wrapper->m_instance.hasConnection()) {
|
|
|
|
if (!wrapper->m_instance.hasThread())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-12-12 13:53:09 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(portFrom);
|
|
|
|
Q_UNUSED(portTo);
|
|
|
|
Q_UNUSED(block);
|
|
|
|
Q_UNUSED(hostAddress);
|
|
|
|
return false;
|
|
|
|
#endif
|
2014-10-10 11:32:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-06 13:43:26 +00:00
|
|
|
void QQmlDebugServer::wakeEngine(QQmlEngine *engine)
|
|
|
|
{
|
|
|
|
// to be executed in debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() == thread());
|
|
|
|
|
|
|
|
Q_D(QQmlDebugServer);
|
|
|
|
QWriteLocker lock(&d->pluginsLock);
|
|
|
|
d->engineConditions[engine].wake();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlDebugServerPrivate::EngineCondition::waitForServices(QReadWriteLock *locked, int num)
|
|
|
|
{
|
|
|
|
// to be executed outside of debugger thread
|
|
|
|
Q_ASSERT(QThread::currentThread() != QQmlDebugServer::instance()->thread());
|
|
|
|
|
|
|
|
Q_ASSERT_X(numServices == 0, Q_FUNC_INFO, "Request to wait again before previous wait finished");
|
|
|
|
numServices = num;
|
|
|
|
return condition->wait(locked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QQmlDebugServerPrivate::EngineCondition::wake()
|
|
|
|
{
|
|
|
|
if (--numServices == 0)
|
|
|
|
condition->wakeAll();
|
|
|
|
Q_ASSERT_X(numServices >=0, Q_FUNC_INFO, "Woken more often than #services.");
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "moc_qqmldebugserver_p.cpp"
|