2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
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
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 11:43:28 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 11:43:28 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "qqmldebugserver_p.h"
|
|
|
|
#include "qqmldebugservice_p.h"
|
|
|
|
#include "qqmldebugservice_p_p.h"
|
|
|
|
#include <private/qqmlengine_p.h>
|
|
|
|
#include <private/qqmlglobal_p.h>
|
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-03-07 08:34:12 +00:00
|
|
|
"QDeclarativeDebugServer" 0 version pluginNames
|
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-03-07 13:53:24 +00:00
|
|
|
"QDeclarativeDebugClient" 0 version pluginNames pluginVersions
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
void advertisePlugins();
|
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;
|
2011-08-24 11:51:07 +00:00
|
|
|
|
|
|
|
QMutex messageArrivedMutex;
|
|
|
|
QWaitCondition messageArrivedCondition;
|
|
|
|
QStringList waitingForMessageNames;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerThread *thread;
|
2011-08-24 11:51:07 +00:00
|
|
|
QPluginLoader loader;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
private:
|
|
|
|
// private slot
|
2011-12-20 15:54:50 +00:00
|
|
|
void _q_sendMessages(const QList<QByteArray> &messages);
|
2011-08-24 11:51:07 +00:00
|
|
|
};
|
2011-11-17 11:19:45 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-14 12:35:17 +00:00
|
|
|
void setPort(int port, bool block, QString &hostAddress) {
|
2011-08-24 11:51:07 +00:00
|
|
|
m_port = port;
|
|
|
|
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;
|
|
|
|
int m_port;
|
|
|
|
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),
|
2011-08-24 10:13:39 +00:00
|
|
|
gotHello(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>");
|
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;
|
|
|
|
{
|
|
|
|
QDataStream out(&message, QIODevice::WriteOnly);
|
2011-12-15 16:52:22 +00:00
|
|
|
QStringList pluginNames;
|
|
|
|
QList<float> pluginVersions;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (QQmlDebugService *service, plugins.values()) {
|
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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
2012-02-16 04:43:03 +00:00
|
|
|
connection = qobject_cast<QQmlDebugServerConnection*>(instance);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-31 13:40:37 +00:00
|
|
|
if (connection) {
|
|
|
|
if (qmlDebugVerbose())
|
2012-03-07 13:53:24 +00:00
|
|
|
qDebug() << "QML Debugger: Plugin successfully loaded.";
|
2011-10-31 13:40:37 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
return connection;
|
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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServer *server = QQmlDebugServer::instance();
|
|
|
|
QQmlDebugServerConnection *connection
|
2011-08-24 11:51:07 +00:00
|
|
|
= server->d_func()->loadConnectionPlugin(m_pluginName);
|
|
|
|
if (connection) {
|
2012-02-16 04:43:03 +00:00
|
|
|
connection->setServer(QQmlDebugServer::instance());
|
2012-03-14 12:35:17 +00:00
|
|
|
connection->setPort(m_port, m_block, m_hostAddress);
|
2011-08-24 11:51:07 +00:00
|
|
|
} else {
|
|
|
|
QCoreApplicationPrivate *appD = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp));
|
2012-03-08 14:01:53 +00:00
|
|
|
qWarning() << QString(QLatin1String("QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
|
|
|
"Remote debugger plugin has not been found.")).arg(appD->qmljsDebugArgumentsString());
|
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;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
static QQmlDebugServer *qQmlDebugServer = 0;
|
2011-08-24 11:51:07 +00:00
|
|
|
|
2011-12-20 12:41:50 +00:00
|
|
|
|
|
|
|
static void cleanup()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
delete qQmlDebugServer;
|
|
|
|
qQmlDebugServer = 0;
|
2011-12-20 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServer *QQmlDebugServer::instance()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
static bool commandLineTested = false;
|
|
|
|
|
|
|
|
if (!commandLineTested) {
|
|
|
|
commandLineTested = true;
|
|
|
|
|
2011-09-30 12:44:53 +00:00
|
|
|
QCoreApplicationPrivate *appD = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp));
|
2012-03-30 11:49:33 +00:00
|
|
|
#ifndef QT_QML_NO_DEBUGGER
|
2011-04-27 10:05:43 +00:00
|
|
|
// ### remove port definition when protocol is changed
|
|
|
|
int port = 0;
|
|
|
|
bool block = false;
|
|
|
|
bool ok = false;
|
2012-03-14 12:35:17 +00:00
|
|
|
QString hostAddress;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-14 12:35:17 +00:00
|
|
|
// format: qmljsdebugger=port:3768[,host:<ip address>][,block] OR qmljsdebugger=ost[,block]
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!appD->qmljsDebugArgumentsString().isEmpty()) {
|
2012-02-16 04:43:03 +00:00
|
|
|
if (!QQmlEnginePrivate::qml_debugging_enabled) {
|
2012-03-08 14:01:53 +00:00
|
|
|
qWarning() << QString(QLatin1String(
|
2012-03-07 13:53:24 +00:00
|
|
|
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
2012-03-08 14:01:53 +00:00
|
|
|
"Debugging has not been enabled.")).arg(
|
2011-09-19 11:20:41 +00:00
|
|
|
appD->qmljsDebugArgumentsString());
|
2011-04-27 10:05:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString pluginName;
|
2012-03-14 12:35:17 +00:00
|
|
|
QStringList lstjsDebugArguments = appD->qmljsDebugArgumentsString()
|
|
|
|
.split(QLatin1Char(','));
|
|
|
|
foreach (const QString &strArgument, lstjsDebugArguments) {
|
|
|
|
if (strArgument.startsWith(QLatin1String("port:"))) {
|
|
|
|
port = strArgument.mid(5).toInt(&ok);
|
|
|
|
pluginName = QLatin1String("qmldbg_tcp");
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
if (ok) {
|
2012-02-16 04:43:03 +00:00
|
|
|
qQmlDebugServer = new QQmlDebugServer();
|
|
|
|
QQmlDebugServerThread *thread = new QQmlDebugServerThread;
|
|
|
|
qQmlDebugServer->d_func()->thread = thread;
|
|
|
|
qQmlDebugServer->moveToThread(thread);
|
2011-08-24 11:51:07 +00:00
|
|
|
thread->setPluginName(pluginName);
|
2012-03-14 12:35:17 +00:00
|
|
|
thread->setPort(port, block, hostAddress);
|
2011-08-24 11:51:07 +00:00
|
|
|
thread->start();
|
|
|
|
|
|
|
|
if (block) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServerPrivate *d = qQmlDebugServer->d_func();
|
2011-08-24 11:51:07 +00:00
|
|
|
d->messageArrivedMutex.lock();
|
|
|
|
d->messageArrivedCondition.wait(&d->messageArrivedMutex);
|
|
|
|
d->messageArrivedMutex.unlock();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2012-03-08 14:01:53 +00:00
|
|
|
qWarning() << QString(QLatin1String(
|
2012-03-07 13:53:24 +00:00
|
|
|
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
2012-03-08 14:01:53 +00:00
|
|
|
"Format is -qmljsdebugger=port:<port>[,block]")).arg(
|
2011-09-19 11:20:41 +00:00
|
|
|
appD->qmljsDebugArgumentsString());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!appD->qmljsDebugArgumentsString().isEmpty()) {
|
2012-03-08 14:01:53 +00:00
|
|
|
qWarning() << QString(QLatin1String(
|
2012-03-07 13:53:24 +00:00
|
|
|
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
|
2012-03-08 14:01:53 +00:00
|
|
|
"QtQml is not configured for debugging.")).arg(
|
2011-09-19 11:20:41 +00:00
|
|
|
appD->qmljsDebugArgumentsString());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
return qQmlDebugServer;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServer::QQmlDebugServer()
|
|
|
|
: QObject(*(new QQmlDebugServerPrivate))
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-12-20 12:41:50 +00:00
|
|
|
qAddPostRoutine(cleanup);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugServer::~QQmlDebugServer()
|
2011-12-20 12:41:50 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQmlDebugServer);
|
2011-12-20 12:41:50 +00:00
|
|
|
|
|
|
|
QReadLocker(&d->pluginsLock);
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (QQmlDebugService *service, d->plugins.values()) {
|
|
|
|
service->stateAboutToBeChanged(QQmlDebugService::NotConnected);
|
2011-12-20 12:41:50 +00:00
|
|
|
service->d_func()->server = 0;
|
2012-02-16 04:43:03 +00:00
|
|
|
service->d_func()->state = QQmlDebugService::NotConnected;
|
|
|
|
service->stateChanged(QQmlDebugService::NotConnected);
|
2011-12-20 12:41:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->thread) {
|
|
|
|
d->thread->exit();
|
2011-12-20 13:26:39 +00:00
|
|
|
d->thread->wait();
|
2011-12-20 12:41:50 +00:00
|
|
|
delete d->thread;
|
|
|
|
}
|
|
|
|
delete d->connection;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServer::receiveMessage(const QByteArray &message)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQmlDebugServer);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QDataStream 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) {
|
|
|
|
int version;
|
|
|
|
in >> version >> d->clientPlugins;
|
|
|
|
|
|
|
|
// Send the hello answer immediately, since it needs to arrive before
|
|
|
|
// the plugins below start sending messages.
|
|
|
|
QByteArray helloAnswer;
|
|
|
|
{
|
|
|
|
QDataStream out(&helloAnswer, QIODevice::WriteOnly);
|
2011-12-15 16:52:22 +00:00
|
|
|
QStringList pluginNames;
|
|
|
|
QList<float> pluginVersions;
|
2012-02-16 04:43:03 +00:00
|
|
|
foreach (QQmlDebugService *service, d->plugins.values()) {
|
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")) << 0 << protocolVersion << pluginNames << pluginVersions;
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
2011-12-20 15:54:50 +00:00
|
|
|
d->connection->send(QList<QByteArray>() << helloAnswer);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
d->gotHello = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
QReadLocker(&d->pluginsLock);
|
2012-02-16 04:43:03 +00:00
|
|
|
QHash<QString, QQmlDebugService*>::ConstIterator iter = d->plugins.constBegin();
|
2011-08-24 11:51:07 +00:00
|
|
|
for (; iter != d->plugins.constEnd(); ++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-02-02 10:18:08 +00:00
|
|
|
iter.value()->d_func()->state = newState;
|
|
|
|
iter.value()->stateChanged(newState);
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
d->messageArrivedCondition.wakeAll();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
} else if (op == 1) {
|
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
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
QReadLocker(&d->pluginsLock);
|
2012-02-16 04:43:03 +00:00
|
|
|
QHash<QString, QQmlDebugService*>::ConstIterator iter = d->plugins.constBegin();
|
2011-08-24 11:51:07 +00:00
|
|
|
for (; iter != d->plugins.constEnd(); ++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-02-02 10:18:08 +00:00
|
|
|
iter.value()->d_func()->state = newState;
|
|
|
|
iter.value()->stateChanged(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;
|
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
QReadLocker(&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-03-07 13:53:24 +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);
|
|
|
|
|
|
|
|
if (d->waitingForMessageNames.removeOne(name))
|
|
|
|
d->messageArrivedCondition.wakeAll();
|
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-02-16 04:43:03 +00:00
|
|
|
void QQmlDebugServerPrivate::_q_sendMessages(const QList<QByteArray> &messages)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QList<QQmlDebugService*> QQmlDebugServer::services() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
const Q_D(QQmlDebugServer);
|
2011-08-24 11:51:07 +00:00
|
|
|
QReadLocker(&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-02-16 04:43:03 +00:00
|
|
|
const Q_D(QQmlDebugServer);
|
2011-08-24 11:51:07 +00:00
|
|
|
QReadLocker(&d->pluginsLock);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->plugins.keys();
|
|
|
|
}
|
|
|
|
|
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);
|
2011-08-24 11:51:07 +00:00
|
|
|
{
|
|
|
|
QWriteLocker(&d->pluginsLock);
|
|
|
|
if (!service || d->plugins.contains(service->name()))
|
|
|
|
return false;
|
|
|
|
d->plugins.insert(service->name(), service);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QReadLocker(&d->pluginsLock);
|
|
|
|
d->advertisePlugins();
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::Unavailable;
|
2011-08-24 11:51:07 +00:00
|
|
|
if (d->clientPlugins.contains(service->name()))
|
2012-02-16 04:43:03 +00:00
|
|
|
newState = QQmlDebugService::Enabled;
|
2012-02-02 10:18:08 +00:00
|
|
|
service->d_func()->state = newState;
|
2011-08-24 11:51:07 +00:00
|
|
|
}
|
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);
|
2011-08-24 11:51:07 +00:00
|
|
|
{
|
|
|
|
QWriteLocker(&d->pluginsLock);
|
|
|
|
if (!service || !d->plugins.contains(service->name()))
|
|
|
|
return false;
|
|
|
|
d->plugins.remove(service->name());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QReadLocker(&d->pluginsLock);
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugService::State newState = QQmlDebugService::NotConnected;
|
2012-02-02 10:18:08 +00:00
|
|
|
service->stateAboutToBeChanged(newState);
|
2011-12-20 13:26:39 +00:00
|
|
|
d->advertisePlugins();
|
2011-08-24 11:51:07 +00:00
|
|
|
service->d_func()->server = 0;
|
2012-02-02 10:18:08 +00:00
|
|
|
service->d_func()->state = newState;
|
|
|
|
service->stateChanged(newState);
|
2011-08-24 11:51:07 +00:00
|
|
|
}
|
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;
|
|
|
|
foreach (const QByteArray &message, messages) {
|
|
|
|
QByteArray prefixed;
|
|
|
|
QDataStream 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
|
|
|
|
2011-12-20 15:54:50 +00:00
|
|
|
QMetaObject::invokeMethod(this, "_q_sendMessages", Qt::QueuedConnection, Q_ARG(QList<QByteArray>, prefixedMessages));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQmlDebugServer::waitForMessage(QQmlDebugService *service)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQmlDebugServer);
|
2011-08-24 11:51:07 +00:00
|
|
|
QReadLocker(&d->pluginsLock);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
if (!service
|
2011-08-24 11:51:07 +00:00
|
|
|
|| !d->plugins.contains(service->name()))
|
2011-04-27 12:13:26 +00:00
|
|
|
return false;
|
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
d->messageArrivedMutex.lock();
|
|
|
|
d->waitingForMessageNames << service->name();
|
2011-04-27 12:13:26 +00:00
|
|
|
do {
|
2011-08-24 11:51:07 +00:00
|
|
|
d->messageArrivedCondition.wait(&d->messageArrivedMutex);
|
|
|
|
} while (d->waitingForMessageNames.contains(service->name()));
|
|
|
|
d->messageArrivedMutex.unlock();
|
2011-04-27 12:13:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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"
|