From 9eca9e028884fb82d97e284826faa7965af356bd Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 13 Jul 2009 17:44:29 +1000 Subject: Rename QmlDebugServerPlugin -> QmlDebugService --- src/declarative/canvas/qsimplecanvas.cpp | 2 +- .../canvas/qsimplecanvasdebugplugin.cpp | 6 +- .../canvas/qsimplecanvasdebugplugin_p.h | 6 +- src/declarative/debugger/debugger.pri | 4 +- src/declarative/debugger/qmldebugserver.cpp | 380 --------------------- src/declarative/debugger/qmldebugserver.h | 86 ----- src/declarative/debugger/qmldebugservice.cpp | 380 +++++++++++++++++++++ src/declarative/debugger/qmldebugservice.h | 86 +++++ src/declarative/qml/qmlenginedebug.cpp | 12 +- src/declarative/qml/qmlenginedebug_p.h | 4 +- 10 files changed, 483 insertions(+), 483 deletions(-) delete mode 100644 src/declarative/debugger/qmldebugserver.cpp delete mode 100644 src/declarative/debugger/qmldebugserver.h create mode 100644 src/declarative/debugger/qmldebugservice.cpp create mode 100644 src/declarative/debugger/qmldebugservice.h diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp index a4998dc..3e586f7 100644 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ b/src/declarative/canvas/qsimplecanvas.cpp @@ -573,7 +573,7 @@ void QSimpleCanvasPrivate::init(QSimpleCanvas::CanvasMode mode) if (continuousUpdate()) qWarning("QSimpleCanvas: Continuous update enabled"); - if (QmlDebugServerPlugin::isDebuggingEnabled()) { + if (QmlDebugService::isDebuggingEnabled()) { debugPlugin = new QSimpleCanvasDebugPlugin(q); new QSimpleCanvasSceneDebugPlugin(q); } diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp index 12088c1..ffb3517 100644 --- a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp +++ b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp @@ -67,7 +67,7 @@ private: }; QSimpleCanvasDebugPlugin::QSimpleCanvasDebugPlugin(QObject *parent) -: QmlDebugServerPlugin(QLatin1String("CanvasFrameRate"), parent), _breaks(0) +: QmlDebugService(QLatin1String("CanvasFrameRate"), parent), _breaks(0) { _time.start(); new FrameBreakAnimation(this); @@ -96,7 +96,7 @@ void QSimpleCanvasDebugPlugin::frameBreak() } QSimpleCanvasSceneDebugPlugin::QSimpleCanvasSceneDebugPlugin(QSimpleCanvas *parent) -: QmlDebugServerPlugin(QLatin1String("CanvasScene"), parent), m_canvas(parent) +: QmlDebugService(QLatin1String("CanvasScene"), parent), m_canvas(parent) { } @@ -120,7 +120,7 @@ void QSimpleCanvasSceneDebugPlugin::refresh() void QSimpleCanvasSceneDebugPlugin::refresh(QDataStream &ds, QSimpleCanvasItem *item) { - ds << QmlDebugServerPlugin::objectToString(item) << item->x() << item->y() + ds << QmlDebugService::objectToString(item) << item->x() << item->y() << item->z() << item->width() << item->height() << (int)item->transformOrigin() << item->scale() << (int)item->flip() #ifdef QFX_RENDER_OPENGL diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h index 270b78c..4c6af2c 100644 --- a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h +++ b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h @@ -46,10 +46,10 @@ #include "qtcpserver.h" #include "qtcpsocket.h" #include "qdatetime.h" -#include +#include QT_BEGIN_NAMESPACE -class QSimpleCanvasDebugPlugin : public QmlDebugServerPlugin +class QSimpleCanvasDebugPlugin : public QmlDebugService { public: QSimpleCanvasDebugPlugin(QObject *parent = 0); @@ -65,7 +65,7 @@ private: class QSimpleCanvas; class QSimpleCanvasItem; -class QSimpleCanvasSceneDebugPlugin : public QmlDebugServerPlugin +class QSimpleCanvasSceneDebugPlugin : public QmlDebugService { public: QSimpleCanvasSceneDebugPlugin(QSimpleCanvas *parent = 0); diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 33076ea..82746fc 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -1,11 +1,11 @@ SOURCES += debugger/qmldebuggerstatus.cpp \ debugger/qpacketprotocol.cpp \ - debugger/qmldebugserver.cpp \ + debugger/qmldebugservice.cpp \ debugger/qmldebugclient.cpp \ debugger/qmldebug.cpp HEADERS += debugger/qmldebuggerstatus.h \ debugger/qpacketprotocol.h \ - debugger/qmldebugserver.h \ + debugger/qmldebugservice.h \ debugger/qmldebugclient.h \ debugger/qmldebug.h diff --git a/src/declarative/debugger/qmldebugserver.cpp b/src/declarative/debugger/qmldebugserver.cpp deleted file mode 100644 index ddfb88a..0000000 --- a/src/declarative/debugger/qmldebugserver.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 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. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmldebugserver.h" -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlDebugServerPrivate; -class QmlDebugServer : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlDebugServer) - Q_DISABLE_COPY(QmlDebugServer) -public: - static QmlDebugServer *instance(); - -private slots: - void readyRead(); - -private: - friend class QmlDebugServerPlugin; - friend class QmlDebugServerPluginPrivate; - QmlDebugServer(int); -}; - -class QmlDebugServerPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlDebugServer) -public: - QmlDebugServerPrivate(); - void init(int port); - - QTcpSocket *connection; - QPacketProtocol *protocol; - QHash plugins; - QStringList enabledPlugins; -}; - -class QmlDebugServerPluginPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlDebugServerPlugin) -public: - QmlDebugServerPluginPrivate(); - - QString name; - QmlDebugServer *server; -}; - -QmlDebugServerPrivate::QmlDebugServerPrivate() -: connection(0), protocol(0) -{ -} - -void QmlDebugServerPrivate::init(int port) -{ - Q_Q(QmlDebugServer); - QTcpServer server; - - if (!server.listen(QHostAddress::Any, port)) { - qWarning("QmlDebugServer: Unable to listen on port %d", port); - return; - } - - qWarning("QmlDebugServer: Waiting for connection on port %d...", port); - - if (!server.waitForNewConnection(-1)) { - qWarning("QmlDebugServer: Connection error"); - return; - } - - connection = server.nextPendingConnection(); - connection->setParent(q); - protocol = new QPacketProtocol(connection, q); - - // ### Wait for hello - while (!protocol->packetsAvailable()) { - connection->waitForReadyRead(); - } - QPacket hello = protocol->read(); - QString name; - hello >> name >> enabledPlugins; - if (name != QLatin1String("QmlDebugServer")) { - qWarning("QmlDebugServer: Invalid hello message"); - delete protocol; delete connection; connection = 0; protocol = 0; - return; - } - - QObject::connect(protocol, SIGNAL(readyRead()), q, SLOT(readyRead())); - q->readyRead(); - - qWarning("QmlDebugServer: Connection established"); -} - -QmlDebugServer *QmlDebugServer::instance() -{ - static bool envTested = false; - static QmlDebugServer *server = 0; - - if (!envTested) { - envTested = true; - QByteArray env = qgetenv("QML_DEBUG_SERVER_PORT"); - - bool ok = false; - int port = env.toInt(&ok); - - if (ok && port > 1024) - server = new QmlDebugServer(port); - } - - if (server && server->d_func()->connection) - return server; - else - return 0; -} - -QmlDebugServer::QmlDebugServer(int port) -: QObject(*(new QmlDebugServerPrivate)) -{ - Q_D(QmlDebugServer); - d->init(port); -} - -void QmlDebugServer::readyRead() -{ - Q_D(QmlDebugServer); - - QString debugServer(QLatin1String("QmlDebugServer")); - - while (d->protocol->packetsAvailable()) { - QPacket pack = d->protocol->read(); - - QString name; - pack >> name; - - if (name == debugServer) { - int op = -1; QString plugin; - pack >> op >> plugin; - - if (op == 1) { - // Enable - if (!d->enabledPlugins.contains(plugin)) { - d->enabledPlugins.append(plugin); - QHash::Iterator iter = - d->plugins.find(plugin); - if (iter != d->plugins.end()) - (*iter)->enabledChanged(true); - } - - } else if (op == 2) { - // Disable - if (d->enabledPlugins.contains(plugin)) { - d->enabledPlugins.removeAll(plugin); - QHash::Iterator iter = - d->plugins.find(plugin); - if (iter != d->plugins.end()) - (*iter)->enabledChanged(false); - } - } else { - qWarning("QmlDebugServer: Invalid control message %d", op); - } - - } else { - QByteArray message; - pack >> message; - - QHash::Iterator iter = - d->plugins.find(name); - if (iter == d->plugins.end()) { - qWarning() << "QmlDebugServer: Message received for missing plugin" << name; - } else { - (*iter)->messageReceived(message); - } - } - } -} - -QmlDebugServerPluginPrivate::QmlDebugServerPluginPrivate() -: server(0) -{ -} - -QmlDebugServerPlugin::QmlDebugServerPlugin(const QString &name, QObject *parent) -: QObject(*(new QmlDebugServerPluginPrivate), parent) -{ - Q_D(QmlDebugServerPlugin); - d->name = name; - d->server = QmlDebugServer::instance(); - - if (!d->server) - return; - - if (d->server->d_func()->plugins.contains(name)) { - qWarning() << "QmlDebugServerPlugin: Conflicting plugin name" << name; - d->server = 0; - } else { - d->server->d_func()->plugins.insert(name, this); - } -} - -QString QmlDebugServerPlugin::name() const -{ - Q_D(const QmlDebugServerPlugin); - return d->name; -} - -bool QmlDebugServerPlugin::isEnabled() const -{ - Q_D(const QmlDebugServerPlugin); - return (d->server && d->server->d_func()->enabledPlugins.contains(d->name)); -} - -namespace { - - struct ObjectReference - { - QPointer object; - int id; - }; - - struct ObjectReferenceHash - { - ObjectReferenceHash() : nextId(0) {} - - QHash objects; - QHash ids; - - int nextId; - }; - -} -Q_GLOBAL_STATIC(ObjectReferenceHash, objectReferenceHash); - - -/*! - Returns a unique id for \a object. Calling this method multiple times - for the same object will return the same id. -*/ -int QmlDebugServerPlugin::idForObject(QObject *object) -{ - if (!object) - return -1; - - ObjectReferenceHash *hash = objectReferenceHash(); - QHash::Iterator iter = - hash->objects.find(object); - - if (iter == hash->objects.end()) { - int id = hash->nextId++; - - hash->ids.insert(id, object); - iter = hash->objects.insert(object, ObjectReference()); - iter->object = object; - iter->id = id; - } else if (iter->object != object) { - int id = hash->nextId++; - - hash->ids.remove(iter->id); - - hash->ids.insert(id, object); - iter->object = object; - iter->id = id; - } - return iter->id; -} - -/*! - Returns the object for unique \a id. If the object has not previously been - assigned an id, through idForObject(), then 0 is returned. If the object - has been destroyed, 0 is returned. -*/ -QObject *QmlDebugServerPlugin::objectForId(int id) -{ - ObjectReferenceHash *hash = objectReferenceHash(); - - QHash::Iterator iter = hash->ids.find(id); - if (iter == hash->ids.end()) - return 0; - - - QHash::Iterator objIter = - hash->objects.find(*iter); - Q_ASSERT(objIter != hash->objects.end()); - - if (objIter->object == 0) { - hash->ids.erase(iter); - hash->objects.erase(objIter); - return 0; - } else { - return *iter; - } -} - -bool QmlDebugServerPlugin::isDebuggingEnabled() -{ - return QmlDebugServer::instance() != 0; -} - -QString QmlDebugServerPlugin::objectToString(QObject *obj) -{ - if(!obj) - return QLatin1String("NULL"); - - QString objectName = obj->objectName(); - if(objectName.isEmpty()) - objectName = QLatin1String(""); - - QString rv = QLatin1String(obj->metaObject()->className()) + - QLatin1String(": ") + objectName; - - return rv; -} - -void QmlDebugServerPlugin::sendMessage(const QByteArray &message) -{ - Q_D(QmlDebugServerPlugin); - - if (!d->server || !d->server->d_func()->connection) - return; - - QPacket pack; - pack << d->name << message; - d->server->d_func()->protocol->send(pack); - d->server->d_func()->connection->flush(); -} - -void QmlDebugServerPlugin::enabledChanged(bool) -{ -} - -void QmlDebugServerPlugin::messageReceived(const QByteArray &) -{ -} - -QT_END_NAMESPACE - -#include "qmldebugserver.moc" diff --git a/src/declarative/debugger/qmldebugserver.h b/src/declarative/debugger/qmldebugserver.h deleted file mode 100644 index b15ee2e..0000000 --- a/src/declarative/debugger/qmldebugserver.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 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. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLDEBUGSERVER_H -#define QMLDEBUGSERVER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QmlDebugServerPluginPrivate; -class QmlDebugServerPlugin : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlDebugServerPlugin) - Q_DISABLE_COPY(QmlDebugServerPlugin) -public: - QmlDebugServerPlugin(const QString &, QObject *parent = 0); - - QString name() const; - - bool isEnabled() const; - - void sendMessage(const QByteArray &); - - static int idForObject(QObject *); - static QObject *objectForId(int); - - - static bool isDebuggingEnabled(); - static QString objectToString(QObject *obj); - -protected: - virtual void enabledChanged(bool); - virtual void messageReceived(const QByteArray &); - -private: - friend class QmlDebugServer; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLDEBUGSERVER_H - diff --git a/src/declarative/debugger/qmldebugservice.cpp b/src/declarative/debugger/qmldebugservice.cpp new file mode 100644 index 0000000..9725494 --- /dev/null +++ b/src/declarative/debugger/qmldebugservice.cpp @@ -0,0 +1,380 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 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. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmldebugservice.h" +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlDebugServerPrivate; +class QmlDebugServer : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugServer) + Q_DISABLE_COPY(QmlDebugServer) +public: + static QmlDebugServer *instance(); + +private slots: + void readyRead(); + +private: + friend class QmlDebugService; + friend class QmlDebugServicePrivate; + QmlDebugServer(int); +}; + +class QmlDebugServerPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDebugServer) +public: + QmlDebugServerPrivate(); + void init(int port); + + QTcpSocket *connection; + QPacketProtocol *protocol; + QHash plugins; + QStringList enabledPlugins; +}; + +class QmlDebugServicePrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDebugService) +public: + QmlDebugServicePrivate(); + + QString name; + QmlDebugServer *server; +}; + +QmlDebugServerPrivate::QmlDebugServerPrivate() +: connection(0), protocol(0) +{ +} + +void QmlDebugServerPrivate::init(int port) +{ + Q_Q(QmlDebugServer); + QTcpServer server; + + if (!server.listen(QHostAddress::Any, port)) { + qWarning("QmlDebugServer: Unable to listen on port %d", port); + return; + } + + qWarning("QmlDebugServer: Waiting for connection on port %d...", port); + + if (!server.waitForNewConnection(-1)) { + qWarning("QmlDebugServer: Connection error"); + return; + } + + connection = server.nextPendingConnection(); + connection->setParent(q); + protocol = new QPacketProtocol(connection, q); + + // ### Wait for hello + while (!protocol->packetsAvailable()) { + connection->waitForReadyRead(); + } + QPacket hello = protocol->read(); + QString name; + hello >> name >> enabledPlugins; + if (name != QLatin1String("QmlDebugServer")) { + qWarning("QmlDebugServer: Invalid hello message"); + delete protocol; delete connection; connection = 0; protocol = 0; + return; + } + + QObject::connect(protocol, SIGNAL(readyRead()), q, SLOT(readyRead())); + q->readyRead(); + + qWarning("QmlDebugServer: Connection established"); +} + +QmlDebugServer *QmlDebugServer::instance() +{ + static bool envTested = false; + static QmlDebugServer *server = 0; + + if (!envTested) { + envTested = true; + QByteArray env = qgetenv("QML_DEBUG_SERVER_PORT"); + + bool ok = false; + int port = env.toInt(&ok); + + if (ok && port > 1024) + server = new QmlDebugServer(port); + } + + if (server && server->d_func()->connection) + return server; + else + return 0; +} + +QmlDebugServer::QmlDebugServer(int port) +: QObject(*(new QmlDebugServerPrivate)) +{ + Q_D(QmlDebugServer); + d->init(port); +} + +void QmlDebugServer::readyRead() +{ + Q_D(QmlDebugServer); + + QString debugServer(QLatin1String("QmlDebugServer")); + + while (d->protocol->packetsAvailable()) { + QPacket pack = d->protocol->read(); + + QString name; + pack >> name; + + if (name == debugServer) { + int op = -1; QString plugin; + pack >> op >> plugin; + + if (op == 1) { + // Enable + if (!d->enabledPlugins.contains(plugin)) { + d->enabledPlugins.append(plugin); + QHash::Iterator iter = + d->plugins.find(plugin); + if (iter != d->plugins.end()) + (*iter)->enabledChanged(true); + } + + } else if (op == 2) { + // Disable + if (d->enabledPlugins.contains(plugin)) { + d->enabledPlugins.removeAll(plugin); + QHash::Iterator iter = + d->plugins.find(plugin); + if (iter != d->plugins.end()) + (*iter)->enabledChanged(false); + } + } else { + qWarning("QmlDebugServer: Invalid control message %d", op); + } + + } else { + QByteArray message; + pack >> message; + + QHash::Iterator iter = + d->plugins.find(name); + if (iter == d->plugins.end()) { + qWarning() << "QmlDebugServer: Message received for missing plugin" << name; + } else { + (*iter)->messageReceived(message); + } + } + } +} + +QmlDebugServicePrivate::QmlDebugServicePrivate() +: server(0) +{ +} + +QmlDebugService::QmlDebugService(const QString &name, QObject *parent) +: QObject(*(new QmlDebugServicePrivate), parent) +{ + Q_D(QmlDebugService); + d->name = name; + d->server = QmlDebugServer::instance(); + + if (!d->server) + return; + + if (d->server->d_func()->plugins.contains(name)) { + qWarning() << "QmlDebugService: Conflicting plugin name" << name; + d->server = 0; + } else { + d->server->d_func()->plugins.insert(name, this); + } +} + +QString QmlDebugService::name() const +{ + Q_D(const QmlDebugService); + return d->name; +} + +bool QmlDebugService::isEnabled() const +{ + Q_D(const QmlDebugService); + return (d->server && d->server->d_func()->enabledPlugins.contains(d->name)); +} + +namespace { + + struct ObjectReference + { + QPointer object; + int id; + }; + + struct ObjectReferenceHash + { + ObjectReferenceHash() : nextId(0) {} + + QHash objects; + QHash ids; + + int nextId; + }; + +} +Q_GLOBAL_STATIC(ObjectReferenceHash, objectReferenceHash); + + +/*! + Returns a unique id for \a object. Calling this method multiple times + for the same object will return the same id. +*/ +int QmlDebugService::idForObject(QObject *object) +{ + if (!object) + return -1; + + ObjectReferenceHash *hash = objectReferenceHash(); + QHash::Iterator iter = + hash->objects.find(object); + + if (iter == hash->objects.end()) { + int id = hash->nextId++; + + hash->ids.insert(id, object); + iter = hash->objects.insert(object, ObjectReference()); + iter->object = object; + iter->id = id; + } else if (iter->object != object) { + int id = hash->nextId++; + + hash->ids.remove(iter->id); + + hash->ids.insert(id, object); + iter->object = object; + iter->id = id; + } + return iter->id; +} + +/*! + Returns the object for unique \a id. If the object has not previously been + assigned an id, through idForObject(), then 0 is returned. If the object + has been destroyed, 0 is returned. +*/ +QObject *QmlDebugService::objectForId(int id) +{ + ObjectReferenceHash *hash = objectReferenceHash(); + + QHash::Iterator iter = hash->ids.find(id); + if (iter == hash->ids.end()) + return 0; + + + QHash::Iterator objIter = + hash->objects.find(*iter); + Q_ASSERT(objIter != hash->objects.end()); + + if (objIter->object == 0) { + hash->ids.erase(iter); + hash->objects.erase(objIter); + return 0; + } else { + return *iter; + } +} + +bool QmlDebugService::isDebuggingEnabled() +{ + return QmlDebugServer::instance() != 0; +} + +QString QmlDebugService::objectToString(QObject *obj) +{ + if(!obj) + return QLatin1String("NULL"); + + QString objectName = obj->objectName(); + if(objectName.isEmpty()) + objectName = QLatin1String(""); + + QString rv = QLatin1String(obj->metaObject()->className()) + + QLatin1String(": ") + objectName; + + return rv; +} + +void QmlDebugService::sendMessage(const QByteArray &message) +{ + Q_D(QmlDebugService); + + if (!d->server || !d->server->d_func()->connection) + return; + + QPacket pack; + pack << d->name << message; + d->server->d_func()->protocol->send(pack); + d->server->d_func()->connection->flush(); +} + +void QmlDebugService::enabledChanged(bool) +{ +} + +void QmlDebugService::messageReceived(const QByteArray &) +{ +} + +QT_END_NAMESPACE + +#include "qmldebugservice.moc" diff --git a/src/declarative/debugger/qmldebugservice.h b/src/declarative/debugger/qmldebugservice.h new file mode 100644 index 0000000..b1344c4 --- /dev/null +++ b/src/declarative/debugger/qmldebugservice.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 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. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLDEBUGSERVICE_H +#define QMLDEBUGSERVICE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QmlDebugServicePrivate; +class QmlDebugService : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugService) + Q_DISABLE_COPY(QmlDebugService) +public: + QmlDebugService(const QString &, QObject *parent = 0); + + QString name() const; + + bool isEnabled() const; + + void sendMessage(const QByteArray &); + + static int idForObject(QObject *); + static QObject *objectForId(int); + + + static bool isDebuggingEnabled(); + static QString objectToString(QObject *obj); + +protected: + virtual void enabledChanged(bool); + virtual void messageReceived(const QByteArray &); + +private: + friend class QmlDebugServer; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLDEBUGSERVICE_H + diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index b5e44e7..2b8aac3 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE QList QmlEngineDebugServer::m_engines; QmlEngineDebugServer::QmlEngineDebugServer(QObject *parent) -: QmlDebugServerPlugin(QLatin1String("QmlEngine"), parent) +: QmlDebugService(QLatin1String("QmlEngine"), parent) { } @@ -135,7 +135,7 @@ void QmlEngineDebugServer::buildObjectList(QDataStream &message, QmlContextPrivate *p = (QmlContextPrivate *)QObjectPrivate::get(ctxt); QString ctxtName = ctxt->objectName(); - int ctxtId = QmlDebugServerPlugin::idForObject(ctxt); + int ctxtId = QmlDebugService::idForObject(ctxt); message << ctxtName << ctxtId; @@ -182,7 +182,7 @@ QmlEngineDebugServer::objectData(QObject *object) rv.objectName = object->objectName(); rv.objectType = object->metaObject()->className(); - rv.objectId = QmlDebugServerPlugin::idForObject(object); + rv.objectId = QmlDebugService::idForObject(object); return rv; } @@ -207,7 +207,7 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message) QmlEngine *engine = m_engines.at(ii); QString engineName = engine->objectName(); - int engineId = QmlDebugServerPlugin::idForObject(engine); + int engineId = QmlDebugService::idForObject(engine); rs << engineName << engineId; } @@ -219,7 +219,7 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message) ds >> queryId >> engineId; QmlEngine *engine = - qobject_cast(QmlDebugServerPlugin::objectForId(engineId)); + qobject_cast(QmlDebugService::objectForId(engineId)); QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); @@ -236,7 +236,7 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message) ds >> queryId >> objectId >> recurse; - QObject *object = QmlDebugServerPlugin::objectForId(objectId); + QObject *object = QmlDebugService::objectForId(objectId); QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); diff --git a/src/declarative/qml/qmlenginedebug_p.h b/src/declarative/qml/qmlenginedebug_p.h index 634f55f..e85ab6f 100644 --- a/src/declarative/qml/qmlenginedebug_p.h +++ b/src/declarative/qml/qmlenginedebug_p.h @@ -53,7 +53,7 @@ // We mean it. // -#include +#include #include #include @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE class QmlEngine; class QmlContext; class QDataStream; -class QmlEngineDebugServer : public QmlDebugServerPlugin +class QmlEngineDebugServer : public QmlDebugService { public: QmlEngineDebugServer(QObject * = 0); -- cgit v0.12