aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/debugger/debugger.pri6
-rw-r--r--src/declarative/debugger/qdebugmessageservice.cpp123
-rw-r--r--src/declarative/debugger/qdebugmessageservice_p.h88
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp2
-rw-r--r--tests/auto/declarative/debugger/debugger.pro3
-rw-r--r--tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml51
-rw-r--r--tests/auto/declarative/debugger/qdebugmessageservice/qdebugmessageservice.pro21
-rw-r--r--tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp186
8 files changed, 477 insertions, 3 deletions
diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri
index e5508a2bb2..34e88ae1b5 100644
--- a/src/declarative/debugger/debugger.pri
+++ b/src/declarative/debugger/debugger.pri
@@ -9,7 +9,8 @@ SOURCES += \
$$PWD/qdeclarativeinspectorservice.cpp \
$$PWD/qv8debugservice.cpp \
$$PWD/qv8profilerservice.cpp \
- $$PWD/qdeclarativeenginedebugservice.cpp
+ $$PWD/qdeclarativeenginedebugservice.cpp \
+ $$PWD/qdebugmessageservice.cpp
HEADERS += \
$$PWD/qpacketprotocol_p.h \
@@ -27,4 +28,5 @@ HEADERS += \
$$PWD/qv8debugservice_p.h \
$$PWD/qv8profilerservice_p.h \
$$PWD/qdeclarativeenginedebugservice_p.h \
- $$PWD/qdeclarativedebug.h
+ $$PWD/qdeclarativedebug.h \
+ $$PWD/qdebugmessageservice_p.h
diff --git a/src/declarative/debugger/qdebugmessageservice.cpp b/src/declarative/debugger/qdebugmessageservice.cpp
new file mode 100644
index 0000000000..1604e3524b
--- /dev/null
+++ b/src/declarative/debugger/qdebugmessageservice.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** 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.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdebugmessageservice_p.h"
+#include "qdeclarativedebugservice_p_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QDebugMessageService, declarativeDebugMessageService)
+
+void DebugMessageHandler(QtMsgType type, const char *buf)
+{
+ QDebugMessageService::instance()->sendDebugMessage(type, buf);
+}
+
+class QDebugMessageServicePrivate : public QDeclarativeDebugServicePrivate
+{
+public:
+ QDebugMessageServicePrivate()
+ : oldMsgHandler(0)
+ , prevStatus(QDeclarativeDebugService::NotConnected)
+ {
+ }
+
+ QtMsgHandler oldMsgHandler;
+ QDeclarativeDebugService::Status prevStatus;
+};
+
+QDebugMessageService::QDebugMessageService(QObject *parent) :
+ QDeclarativeDebugService(*(new QDebugMessageServicePrivate()),
+ QLatin1String("DebugMessages"), 1, parent)
+{
+ Q_D(QDebugMessageService);
+
+ registerService();
+ if (status() == Enabled) {
+ d->oldMsgHandler = qInstallMsgHandler(DebugMessageHandler);
+ d->prevStatus = Enabled;
+ }
+}
+
+QDebugMessageService *QDebugMessageService::instance()
+{
+ return declarativeDebugMessageService();
+}
+
+void QDebugMessageService::sendDebugMessage(QtMsgType type, const char *buf)
+{
+ Q_D(QDebugMessageService);
+
+ //We do not want to alter the message handling mechanism
+ //We just eavesdrop and forward the messages to a port
+ //only if a client is connected to it.
+ QByteArray debugMessage;
+ QDataStream rs(&debugMessage, QIODevice::WriteOnly);
+ rs << type << QString::fromLocal8Bit(buf).toUtf8();
+
+ QByteArray message;
+ QDataStream ws(&message, QIODevice::WriteOnly);
+ ws << QByteArray("MESSAGE") << debugMessage;
+
+ sendMessage(message);
+ if (d->oldMsgHandler)
+ (*d->oldMsgHandler)(type, buf);
+}
+
+void QDebugMessageService::statusChanged(Status status)
+{
+ Q_D(QDebugMessageService);
+
+ if (status != Enabled && d->prevStatus == Enabled) {
+ QtMsgHandler handler = qInstallMsgHandler(d->oldMsgHandler);
+ // has our handler been overwritten in between?
+ if (handler != DebugMessageHandler)
+ qInstallMsgHandler(handler);
+
+ } else if (status == Enabled && d->prevStatus != Enabled) {
+ d->oldMsgHandler = qInstallMsgHandler(DebugMessageHandler);
+
+ }
+
+ d->prevStatus = status;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/debugger/qdebugmessageservice_p.h b/src/declarative/debugger/qdebugmessageservice_p.h
new file mode 100644
index 0000000000..c2951e61ae
--- /dev/null
+++ b/src/declarative/debugger/qdebugmessageservice_p.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** 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.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDEBUGMESSAGESERVICE_P_H
+#define QDEBUGMESSAGESERVICE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qdeclarativedebugservice_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QDebugMessageServicePrivate;
+
+class QDebugMessageService : public QDeclarativeDebugService
+{
+ Q_OBJECT
+public:
+ QDebugMessageService(QObject *parent = 0);
+
+ static QDebugMessageService *instance();
+
+ void sendDebugMessage(QtMsgType type, const char *buf);
+
+protected:
+ void statusChanged(Status);
+
+private:
+ Q_DISABLE_COPY(QDebugMessageService)
+ Q_DECLARE_PRIVATE(QDebugMessageService)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QDEBUGMESSAGESERVICE_P_H
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 113abdcecc..1d613ccc26 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -70,6 +70,7 @@
#include <private/qdeclarativedebugtrace_p.h>
#include <private/qdeclarativeapplication_p.h>
#include <private/qv8debugservice_p.h>
+#include <private/qdebugmessageservice_p.h>
#include "qdeclarativeincubator.h"
#include <private/qv8profilerservice_p.h>
@@ -451,6 +452,7 @@ void QDeclarativeEnginePrivate::init()
QV8DebugService::initialize(v8engine());
QV8ProfilerService::initialize();
QDeclarativeDebugTrace::initialize();
+ QDebugMessageService::instance();
}
}
diff --git a/tests/auto/declarative/debugger/debugger.pro b/tests/auto/declarative/debugger/debugger.pro
index bdcb528c07..6d7548cec8 100644
--- a/tests/auto/declarative/debugger/debugger.pro
+++ b/tests/auto/declarative/debugger/debugger.pro
@@ -8,7 +8,8 @@ PRIVATETESTS += \
qdeclarativeinspector \
qdeclarativedebugtrace \
qpacketprotocol \
- qv8profilerservice
+ qv8profilerservice \
+ qdebugmessageservice
contains(QT_CONFIG, private_tests) {
SUBDIRS += $$PRIVATETESTS
diff --git a/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml b/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml
new file mode 100644
index 0000000000..7377d4584c
--- /dev/null
+++ b/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** 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.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Item {
+ width: 360
+ height: 360
+ Timer {
+ interval: 100; running: true; repeat: true
+ onTriggered: console.log("Timer")
+ }
+}
diff --git a/tests/auto/declarative/debugger/qdebugmessageservice/qdebugmessageservice.pro b/tests/auto/declarative/debugger/qdebugmessageservice/qdebugmessageservice.pro
new file mode 100644
index 0000000000..698e9604f0
--- /dev/null
+++ b/tests/auto/declarative/debugger/qdebugmessageservice/qdebugmessageservice.pro
@@ -0,0 +1,21 @@
+CONFIG += testcase
+TARGET = tst_qdebugmessageservice
+QT += network declarative-private testlib
+macx:CONFIG -= app_bundle
+
+HEADERS += ../shared/debugutil_p.h
+
+SOURCES += tst_qdebugmessageservice.cpp \
+ ../shared/debugutil.cpp
+
+INCLUDEPATH += ../shared
+
+include(../../../shared/util.pri)
+
+testDataFiles.files = data
+testDataFiles.path = .
+DEPLOYMENT += testDataFiles
+
+CONFIG += parallel_test
+
+OTHER_FILES += data/test.qml
diff --git a/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp b/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp
new file mode 100644
index 0000000000..62f89e9540
--- /dev/null
+++ b/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp
@@ -0,0 +1,186 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** 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.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDeclarative/private/qdeclarativedebugclient_p.h>
+
+//QDeclarativeDebugTest
+#include "../shared/debugutil_p.h"
+#include "../../../shared/util.h"
+
+#include <QtCore/QString>
+#include <QtTest/QtTest>
+
+const char *NORMALMODE = "-qmljsdebugger=port:3777";
+const char *QMLFILE = "test.qml";
+
+class QDeclarativeDebugMsgClient;
+class tst_QDebugMessageService : public QDeclarativeDataTest
+{
+ Q_OBJECT
+
+public:
+ tst_QDebugMessageService();
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void init();
+ void cleanup();
+
+ void retrieveDebugOutput();
+
+private:
+ QDeclarativeDebugProcess *m_process;
+ QDeclarativeDebugMsgClient *m_client;
+ QDeclarativeDebugConnection *m_connection;
+};
+
+class QDeclarativeDebugMsgClient : public QDeclarativeDebugClient
+{
+ Q_OBJECT
+public:
+ QDeclarativeDebugMsgClient(QDeclarativeDebugConnection *connection)
+ : QDeclarativeDebugClient(QLatin1String("DebugMessages"), connection)
+ {
+ }
+
+protected:
+ //inherited from QDeclarativeDebugClient
+ void statusChanged(Status status);
+ void messageReceived(const QByteArray &data);
+
+signals:
+ void enabled();
+ void debugOutput();
+
+public:
+ QByteArray debugMessage;
+};
+
+void QDeclarativeDebugMsgClient::statusChanged(Status status)
+{
+ if (status == Enabled) {
+ emit enabled();
+ }
+}
+
+void QDeclarativeDebugMsgClient::messageReceived(const QByteArray &data)
+{
+ QDataStream ds(data);
+ QByteArray command;
+ ds >> command;
+
+ if (command == "MESSAGE") {
+ int type;
+ ds >> type >> debugMessage;
+ emit debugOutput();
+ }
+}
+
+tst_QDebugMessageService::tst_QDebugMessageService()
+{
+}
+
+void tst_QDebugMessageService::initTestCase()
+{
+ QDeclarativeDataTest::initTestCase();
+ m_process = 0;
+ m_client = 0;
+ m_connection = 0;
+}
+
+void tst_QDebugMessageService::cleanupTestCase()
+{
+ if (m_process)
+ delete m_process;
+
+ if (m_client)
+ delete m_client;
+
+ if (m_connection)
+ delete m_connection;
+}
+
+void tst_QDebugMessageService::init()
+{
+ m_connection = new QDeclarativeDebugConnection();
+ m_process = new QDeclarativeDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene");
+ m_client = new QDeclarativeDebugMsgClient(m_connection);
+
+ m_process->start(QStringList() << QLatin1String(NORMALMODE) << QDeclarativeDataTest::instance()->testFile(QMLFILE));
+ if (!m_process->waitForSessionStart()) {
+ QFAIL(QString("Could not launch app. Application output: \n%1").arg(m_process->output()).toAscii());
+ }
+
+ m_connection->connectToHost("127.0.0.1", 3777);
+ QVERIFY(m_connection->waitForConnected());
+
+ QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(enabled())));
+}
+
+void tst_QDebugMessageService::cleanup()
+{
+ if (QTest::currentTestFailed())
+ qDebug() << m_process->output();
+ if (m_process)
+ delete m_process;
+
+ if (m_client)
+ delete m_client;
+
+ if (m_connection)
+ delete m_connection;
+
+ m_process = 0;
+ m_client = 0;
+ m_connection = 0;
+}
+
+void tst_QDebugMessageService::retrieveDebugOutput()
+{
+ if (m_client->debugMessage.isEmpty())
+ QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(debugOutput())));
+}
+
+QTEST_MAIN(tst_QDebugMessageService)
+
+#include "tst_qdebugmessageservice.moc"