QV8DebugService: add version command
authorAurindam Jana <aurindam.jana@nokia.com>
Thu, 15 Dec 2011 09:54:45 +0000 (10:54 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 15 Dec 2011 11:17:16 +0000 (12:17 +0100)
Version command to retrieve debugger version info.

Change-Id: I711e2a3d639c648cef50498fe5bbb9b6b8c6c1fe
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
src/declarative/debugger/qv8debugservice.cpp
tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp

index 2fd54dc..933c37a 100644 (file)
 #include <QtCore/QFileInfo>
 #include <QtCore/QMutex>
 
+//V8 DEBUG SERVICE PROTOCOL
+// <HEADER><COMMAND><DATA>
+// <HEADER> : "V8DEBUG"
+// <COMMAND> : ["connect", "disconnect", "interrupt", "version",
+//              "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";
 const char *V8_DEBUGGER_KEY_DISCONNECT = "disconnect";
@@ -147,15 +161,6 @@ void QV8DebugService::setEngine(const QV8Engine *engine)
     d->engine = engine;
 }
 
-//V8 DEBUG SERVICE PROTOCOL
-// <HEADER><TYPE><DATA>
-// <HEADER> : "V8DEBUG"
-// <TYPE> : ("connect", "disconnect", "interrupt", "v8request", "v8message",
-//           "breakonsignal", "breakaftercompile")
-// <DATA> : For _v8request_ and _v8message_ it is the JSON request string.
-//          For _breakonsignal_ it is <signalname_string><enabled_bool>
-//          For _breakaftercompile_ it is <enabled_bool>
-//          Empty string for the other types
 void QV8DebugService::debugMessageHandler(const QString &message, const v8::DebugEvent &event)
 {
     Q_D(QV8DebugService);
@@ -164,7 +169,6 @@ void QV8DebugService::debugMessageHandler(const QString &message, const v8::Debu
         scheduledDebugBreak(true);
 }
 
-
 void QV8DebugService::signalEmitted(const QString &signal)
 {
     //This function is only called by QDeclarativeBoundSignal
@@ -213,49 +217,39 @@ void QV8DebugService::statusChanged(QDeclarativeDebugService::Status newStatus)
     }
 }
 
-
-//V8 DEBUG SERVICE PROTOCOL
-// <HEADER><TYPE><DATA>
-// <HEADER> : "V8DEBUG"
-// <TYPE> : ("connect", "disconnect", "interrupt", "v8request", "v8message",
-//           "breakonsignal", "breakaftercompile")
-// <DATA> : For _v8request_ and _v8message_ it is the JSON request string.
-//          For _breakonsignal_ it is <signalname_string><enabled_bool>
-//          For _breakaftercompile_ it is <enabled_bool>
-//          Empty string for the other types
 // executed in the debugger thread
 void QV8DebugService::messageReceived(const QByteArray &message)
 {
     Q_D(QV8DebugService);
 
     QDataStream ds(message);
-    QByteArray command;
-    ds >> command;
+    QByteArray header;
+    ds >> header;
 
-    if (command == "V8DEBUG") {
-        QByteArray type;
+    if (header == "V8DEBUG") {
+        QByteArray command;
         QByteArray data;
-        ds >> type >> data;
+        ds >> command >> data;
 
-        if (type == V8_DEBUGGER_KEY_CONNECT) {
+        if (command == V8_DEBUGGER_KEY_CONNECT) {
             QMutexLocker locker(&d->initializeMutex);
             d->connectReceived = true;
             sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_CONNECT)));
 
-        } else if (type == V8_DEBUGGER_KEY_INTERRUPT) {
+        } else if (command == V8_DEBUGGER_KEY_INTERRUPT) {
             // break has to be executed in gui thread
             QMetaObject::invokeMethod(this, "scheduledDebugBreak", Qt::QueuedConnection, Q_ARG(bool, true));
             sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_INTERRUPT)));
 
-        } else if (type == V8_DEBUGGER_KEY_DISCONNECT) {
+        } else if (command == V8_DEBUGGER_KEY_DISCONNECT) {
             // cancel break has to be executed in gui thread
             QMetaObject::invokeMethod(this, "scheduledDebugBreak", Qt::QueuedConnection, Q_ARG(bool, false));
             sendDebugMessage(QString::fromUtf8(data));
 
-        } else if (type == V8_DEBUGGER_KEY_REQUEST) {
+        } else if (command == V8_DEBUGGER_KEY_REQUEST) {
             sendDebugMessage(QString::fromUtf8(data));
 
-        } else if (type == V8_DEBUGGER_KEY_BREAK_ON_SIGNAL) {
+        } else if (command == V8_DEBUGGER_KEY_BREAK_ON_SIGNAL) {
             QDataStream rs(data);
             QByteArray signal;
             bool enabled;
@@ -268,10 +262,17 @@ void QV8DebugService::messageReceived(const QByteArray &message)
                 d->breakOnSignals.removeOne(signalName);
             sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_BREAK_ON_SIGNAL)));
 
-        } else if (type == V8_DEBUGGER_KEY_BREAK_AFTER_COMPILE) {
+        } else if (command == V8_DEBUGGER_KEY_BREAK_AFTER_COMPILE) {
             QDataStream rs(data);
             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 0f9da03..f2c0282 100644 (file)
@@ -174,6 +174,7 @@ private slots:
     void connect();
     void interrupt();
     void breakAfterCompile();
+    void getDebuggerVersion();
     void getVersion();
     void getVersionWhenAttaching();
 
@@ -270,6 +271,7 @@ 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());
@@ -301,6 +303,7 @@ signals:
     void connected();
     void interruptRequested();
     void breakAfterCompileRequested();
+    void gotVersion();
     void result();
     void stopped();
 
@@ -339,6 +342,11 @@ void QJSDebugClient::breakAfterCompile(bool enabled)
     sendMessage(packMessage(BREAKAFTERCOMPILE, request));
 }
 
+void QJSDebugClient::debuggerVersion()
+{
+    sendMessage(packMessage(VERSION));
+}
+
 void QJSDebugClient::continueDebugging(StepAction action, int count)
 {
     //    { "seq"       : <number>,
@@ -951,6 +959,8 @@ void QJSDebugClient::messageReceived(const QByteArray &data)
         } else if (type == BREAKAFTERCOMPILE) {
             emit breakAfterCompileRequested();
 
+        } else if (type == VERSION) {
+            emit gotVersion();
         }
     }
 }
@@ -1079,6 +1089,17 @@ 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()