DeclarativeDebug: Add version info to service plugins
authorAurindam Jana <aurindam.jana@nokia.com>
Thu, 15 Dec 2011 16:52:22 +0000 (17:52 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 16 Dec 2011 10:42:57 +0000 (11:42 +0100)
Send the version info of each plugin alongwith the
plugin names to client.

Change-Id: I223689b32cdc5b0c48a4f508330033352b427937
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
16 files changed:
src/declarative/debugger/qdeclarativedebugclient.cpp
src/declarative/debugger/qdeclarativedebugclient_p.h
src/declarative/debugger/qdeclarativedebugserver.cpp
src/declarative/debugger/qdeclarativedebugservice.cpp
src/declarative/debugger/qdeclarativedebugservice_p.h
src/declarative/debugger/qdeclarativedebugservice_p_p.h
src/declarative/debugger/qdeclarativedebugtrace.cpp
src/declarative/debugger/qdeclarativeenginedebugservice.cpp
src/declarative/debugger/qdeclarativeinspectorservice.cpp
src/declarative/debugger/qv8debugservice.cpp
src/declarative/debugger/qv8profilerservice.cpp
tests/auto/declarative/debugger/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp
tests/auto/declarative/debugger/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
tests/auto/declarative/debugger/shared/debugutil.cpp
tests/auto/declarative/debugger/shared/debugutil_p.h

index 5018e95..9d5b88c 100644 (file)
@@ -75,7 +75,7 @@ public:
     QIODevice *device;
 
     bool gotHello;
-    QStringList serverPlugins;
+    QHash <QString, float> serverPlugins;
     QHash<QString, QDeclarativeDebugClient *> plugins;
 
     void advertisePlugins();
@@ -130,7 +130,21 @@ void QDeclarativeDebugConnectionPrivate::readyRead()
                 int version = -1;
                 pack >> version;
                 if (version == protocolVersion) {
-                    pack >> serverPlugins;
+                    QStringList pluginNames;
+                    QList<float> pluginVersions;
+                    pack >> pluginNames;
+                    if (!pack.isEmpty())
+                        pack >> pluginVersions;
+
+                    const int pluginNamesSize = pluginNames.size();
+                    const int pluginVersionsSize = pluginVersions.size();
+                    for (int i = 0; i < pluginNamesSize; ++i) {
+                        float pluginVersion = 1.0;
+                        if (i < pluginVersionsSize)
+                            pluginVersion = pluginVersions.at(i);
+                        serverPlugins.insert(pluginNames.at(i), pluginVersion);
+                    }
+
                     validHello = true;
                 }
             }
@@ -163,8 +177,23 @@ void QDeclarativeDebugConnectionPrivate::readyRead()
 
             if (op == 1) {
                 // Service Discovery
-                QStringList oldServerPlugins = serverPlugins;
-                pack >> serverPlugins;
+                QHash<QString, float> oldServerPlugins = serverPlugins;
+                serverPlugins.clear();
+
+                QStringList pluginNames;
+                QList<float> pluginVersions;
+                pack >> pluginNames;
+                if (!pack.isEmpty())
+                    pack >> pluginVersions;
+
+                const int pluginNamesSize = pluginNames.size();
+                const int pluginVersionsSize = pluginVersions.size();
+                for (int i = 0; i < pluginNamesSize; ++i) {
+                    float pluginVersion = 1.0;
+                    if (i < pluginVersionsSize)
+                        pluginVersion = pluginVersions.at(i);
+                    serverPlugins.insert(pluginNames.at(i), pluginVersion);
+                }
 
                 QHash<QString, QDeclarativeDebugClient *>::Iterator iter = plugins.begin();
                 for (; iter != plugins.end(); ++iter) {
@@ -345,6 +374,14 @@ QString QDeclarativeDebugClient::name() const
     return d->name;
 }
 
+float QDeclarativeDebugClient::serviceVersion() const
+{
+    Q_D(const QDeclarativeDebugClient);
+    if (d->connection->d->serverPlugins.contains(d->name))
+        return d->connection->d->serverPlugins.value(d->name);
+    return -1;
+}
+
 QDeclarativeDebugClient::Status QDeclarativeDebugClient::status() const
 {
     Q_D(const QDeclarativeDebugClient);
index 5b21935..7b9a342 100644 (file)
@@ -111,7 +111,7 @@ public:
     ~QDeclarativeDebugClient();
 
     QString name() const;
-
+    float serviceVersion() const;
     Status status() const;
 
     virtual void sendMessage(const QByteArray &);
index b8963d2..23f1e0d 100644 (file)
@@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE
        version: an int representing the highest protocol version the client knows
        pluginNames: plugins available on client side
     2. Server sends
-         "QDeclarativeDebugClient" 0 version pluginNames
+         "QDeclarativeDebugClient" 0 version pluginNames pluginVersions
        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
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
          "QDeclarativeDebugServer" 1 pluginNames
   server plugin advertisement
     1. Server sends
-         "QDeclarativeDebugClient" 1 pluginNames
+         "QDeclarativeDebugClient" 1 pluginNames pluginVersions
   plugin communication:
        Everything send with a header different to "QDeclarativeDebugServer" is sent to the appropriate plugin.
   */
@@ -146,7 +146,13 @@ void QDeclarativeDebugServerPrivate::advertisePlugins()
     QByteArray message;
     {
         QDataStream out(&message, QIODevice::WriteOnly);
-        out << QString(QLatin1String("QDeclarativeDebugClient")) << 1 << plugins.keys();
+        QStringList pluginNames;
+        QList<float> pluginVersions;
+        foreach (QDeclarativeDebugService *service, plugins.values()) {
+            pluginNames << service->name();
+            pluginVersions << service->version();
+        }
+        out << QString(QLatin1String("QDeclarativeDebugClient")) << 1 << pluginNames << pluginVersions;
     }
 
     QMetaObject::invokeMethod(q, "_q_sendMessage", Qt::QueuedConnection, Q_ARG(QByteArray, message));
@@ -326,7 +332,14 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message)
             QByteArray helloAnswer;
             {
                 QDataStream out(&helloAnswer, QIODevice::WriteOnly);
-                out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << d->plugins.keys();
+                QStringList pluginNames;
+                QList<float> pluginVersions;
+                foreach (QDeclarativeDebugService *service, d->plugins.values()) {
+                    pluginNames << service->name();
+                    pluginVersions << service->version();
+                }
+
+                out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << pluginNames << pluginVersions;
             }
             d->connection->send(helloAnswer);
 
index 2bdcf2f..5606540 100644 (file)
@@ -53,11 +53,12 @@ QDeclarativeDebugServicePrivate::QDeclarativeDebugServicePrivate()
 {
 }
 
-QDeclarativeDebugService::QDeclarativeDebugService(const QString &name, QObject *parent)
+QDeclarativeDebugService::QDeclarativeDebugService(const QString &name, float version, QObject *parent)
     : QObject(*(new QDeclarativeDebugServicePrivate), parent)
 {
     Q_D(QDeclarativeDebugService);
     d->name = name;
+    d->version = version;
     d->server = QDeclarativeDebugServer::instance();
     d->status = QDeclarativeDebugService::NotConnected;
 
@@ -65,11 +66,12 @@ QDeclarativeDebugService::QDeclarativeDebugService(const QString &name, QObject
 }
 
 QDeclarativeDebugService::QDeclarativeDebugService(QDeclarativeDebugServicePrivate &dd,
-                                                   const QString &name, QObject *parent)
+                                                   const QString &name, float version, QObject *parent)
     : QObject(dd, parent)
 {
     Q_D(QDeclarativeDebugService);
     d->name = name;
+    d->version = version;
     d->server = QDeclarativeDebugServer::instance();
     d->status = QDeclarativeDebugService::NotConnected;
 }
@@ -107,6 +109,12 @@ QString QDeclarativeDebugService::name() const
     return d->name;
 }
 
+float QDeclarativeDebugService::version() const
+{
+    Q_D(const QDeclarativeDebugService);
+    return d->version;
+}
+
 QDeclarativeDebugService::Status QDeclarativeDebugService::status() const
 {
     Q_D(const QDeclarativeDebugService);
index 3bcf310..9698f91 100644 (file)
@@ -71,10 +71,11 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugService : public QObject
     Q_DISABLE_COPY(QDeclarativeDebugService)
 
 public:
-    explicit QDeclarativeDebugService(const QString &, QObject *parent = 0);
+    explicit QDeclarativeDebugService(const QString &, float version, QObject *parent = 0);
     ~QDeclarativeDebugService();
 
     QString name() const;
+    float version() const;
 
     enum Status { NotConnected, Unavailable, Enabled };
     Status status() const;
@@ -91,7 +92,7 @@ public:
     static bool hasDebuggingClient();
 
 protected:
-    QDeclarativeDebugService(QDeclarativeDebugServicePrivate &dd, const QString &, QObject *parent = 0);
+    QDeclarativeDebugService(QDeclarativeDebugServicePrivate &dd, const QString &name, float version, QObject *parent = 0);
 
     Status registerService();
 
index 12233ed..3c501e8 100644 (file)
@@ -71,6 +71,7 @@ public:
     QDeclarativeDebugServicePrivate();
 
     QString name;
+    float version;
     QDeclarativeDebugServer *server;
     QDeclarativeDebugService::Status status;
 };
index f3f8156..724399d 100644 (file)
@@ -74,7 +74,7 @@ QByteArray QDeclarativeDebugData::toByteArray() const
 }
 
 QDeclarativeDebugTrace::QDeclarativeDebugTrace()
-    : QDeclarativeDebugService(QLatin1String("CanvasFrameRate")),
+    : QDeclarativeDebugService(QLatin1String("CanvasFrameRate"), 1),
       m_enabled(false), m_messageReceived(false)
 {
     m_timer.start();
index f831929..0e3c055 100644 (file)
@@ -67,7 +67,7 @@ QDeclarativeEngineDebugService *QDeclarativeEngineDebugService::instance()
 }
 
 QDeclarativeEngineDebugService::QDeclarativeEngineDebugService(QObject *parent)
-    : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent),
+    : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), 1, parent),
       m_watch(new QDeclarativeWatcher(this)),
       m_statesDelegate(0)
 {
index 07fed4d..729a71a 100644 (file)
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
 Q_GLOBAL_STATIC(QDeclarativeInspectorService, serviceInstance)
 
 QDeclarativeInspectorService::QDeclarativeInspectorService()
-    : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode"))
+    : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode"), 1)
     , m_currentInspectorPlugin(0)
 {
     registerService();
index 933c37a..976f501 100644 (file)
 //V8 DEBUG SERVICE PROTOCOL
 // <HEADER><COMMAND><DATA>
 // <HEADER> : "V8DEBUG"
-// <COMMAND> : ["connect", "disconnect", "interrupt", "version",
+// <COMMAND> : ["connect", "disconnect", "interrupt",
 //              "v8request", "v8message", "breakonsignal",
 //              "breakaftercompile"]
 // <DATA> : connect, disconnect, interrupt: empty
-//          version: <version_string>
 //          v8request, v8message: <JSONrequest_string>
 //          breakonsignal: <signalname_string><enabled_bool>
 //          breakaftercompile: <enabled_bool>
 
-const char *V8_DEBUGGER_KEY_VERSION_NUMBER = "1.1";
 const char *V8_DEBUGGER_KEY_VERSION = "version";
 const char *V8_DEBUGGER_KEY_CONNECT = "connect";
 const char *V8_DEBUGGER_KEY_INTERRUPT = "interrupt";
@@ -122,7 +120,7 @@ public:
 
 QV8DebugService::QV8DebugService(QObject *parent)
     : QDeclarativeDebugService(*(new QV8DebugServicePrivate()),
-                               QLatin1String("V8Debugger"), parent)
+                               QLatin1String("V8Debugger"), 2, parent)
 {
     Q_D(QV8DebugService);
     v8ServiceInstancePtr = this;
@@ -267,12 +265,6 @@ void QV8DebugService::messageReceived(const QByteArray &message)
             rs >> d->breakAfterCompile;
             sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_BREAK_AFTER_COMPILE)));
 
-        } else if (command == V8_DEBUGGER_KEY_VERSION) {
-            //We dont check the client version
-            //just send the debugger version
-            sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_VERSION),
-                                                            QLatin1String(V8_DEBUGGER_KEY_VERSION_NUMBER)));
-
         }
     }
 }
index 7cbd336..f5c980e 100644 (file)
@@ -100,7 +100,7 @@ public:
 };
 
 QV8ProfilerService::QV8ProfilerService(QObject *parent)
-    : QDeclarativeDebugService(*(new QV8ProfilerServicePrivate()), QLatin1String("V8Profiler"), parent)
+    : QDeclarativeDebugService(*(new QV8ProfilerServicePrivate()), QLatin1String("V8Profiler"), 1, parent)
 {
     Q_D(QV8ProfilerService);
 
index 43f92df..7306b89 100644 (file)
@@ -109,14 +109,16 @@ void tst_QDeclarativeDebugClient::status()
         QDeclarativeDebugConnection dummyConn;
         QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::status()", &dummyConn);
         QCOMPARE(client.status(), QDeclarativeDebugClient::NotConnected);
+        QCOMPARE(client.serviceVersion(), -1.0f);
     }
 
     QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::status()", m_conn);
     QCOMPARE(client.status(), QDeclarativeDebugClient::Unavailable);
 
     {
-        QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::status()");
+        QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::status()", 2);
         QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
+        QCOMPARE(client.serviceVersion(), 2.0f);
     }
 
     QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Unavailable);
index f2c0282..0f9da03 100644 (file)
@@ -174,7 +174,6 @@ private slots:
     void connect();
     void interrupt();
     void breakAfterCompile();
-    void getDebuggerVersion();
     void getVersion();
     void getVersionWhenAttaching();
 
@@ -271,7 +270,6 @@ public:
     void connect();
     void interrupt();
     void breakAfterCompile(bool enabled);
-    void debuggerVersion();
 
     void continueDebugging(StepAction stepAction, int stepCount = 1);
     void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
@@ -303,7 +301,6 @@ signals:
     void connected();
     void interruptRequested();
     void breakAfterCompileRequested();
-    void gotVersion();
     void result();
     void stopped();
 
@@ -342,11 +339,6 @@ void QJSDebugClient::breakAfterCompile(bool enabled)
     sendMessage(packMessage(BREAKAFTERCOMPILE, request));
 }
 
-void QJSDebugClient::debuggerVersion()
-{
-    sendMessage(packMessage(VERSION));
-}
-
 void QJSDebugClient::continueDebugging(StepAction action, int count)
 {
     //    { "seq"       : <number>,
@@ -959,8 +951,6 @@ void QJSDebugClient::messageReceived(const QByteArray &data)
         } else if (type == BREAKAFTERCOMPILE) {
             emit breakAfterCompileRequested();
 
-        } else if (type == VERSION) {
-            emit gotVersion();
         }
     }
 }
@@ -1089,17 +1079,6 @@ void tst_QDeclarativeDebugJS::breakAfterCompile()
     QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped())));
 }
 
-void tst_QDeclarativeDebugJS::getDebuggerVersion()
-{
-    QVERIFY(init());
-    client->debuggerVersion();
-
-    QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(gotVersion())));
-
-    QString version(client->response);
-    QCOMPARE(version, QLatin1String("1.1"));
-}
-
 void tst_QDeclarativeDebugJS::getVersion()
 {
     //void version()
index 6754503..77a2514 100644 (file)
@@ -66,6 +66,7 @@ private slots:
     void initTestCase();
 
     void name();
+    void version();
     void status();
     void sendMessage();
     void idForObject();
@@ -99,10 +100,18 @@ void tst_QDeclarativeDebugService::name()
 {
     QString name = "tst_QDeclarativeDebugService::name()";
 
-    QDeclarativeDebugService service(name);
+    QDeclarativeDebugService service(name, 1);
     QCOMPARE(service.name(), name);
 }
 
+void tst_QDeclarativeDebugService::version()
+{
+    QString name = "tst_QDeclarativeDebugService::name()";
+
+    QDeclarativeDebugService service(name, 2);
+    QCOMPARE(service.version(), 2.0f);
+}
+
 void tst_QDeclarativeDebugService::status()
 {
     QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::status()");
index c259ac9..41c97ea 100644 (file)
@@ -58,8 +58,8 @@ bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member,
     return timer.isActive();
 }
 
-QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, QObject *parent)
-    : QDeclarativeDebugService(s, parent)
+QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, float version, QObject *parent)
+    : QDeclarativeDebugService(s, version, parent)
 {
     registerService();
 }
index 4d2ee16..e24bdbd 100644 (file)
@@ -64,7 +64,7 @@ class QDeclarativeDebugTestService : public QDeclarativeDebugService
 {
     Q_OBJECT
 public:
-    QDeclarativeDebugTestService(const QString &s, QObject *parent = 0);
+    QDeclarativeDebugTestService(const QString &s, float version = 1, QObject *parent = 0);
 
 signals:
     void statusHasChanged();