aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAurindam Jana <aurindam.jana@nokia.com>2011-11-08 11:47:33 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-09 16:18:51 +0100
commitf161773a0221393192b20bab25c62a8645e6cdd4 (patch)
treec516d38849de8c9f88a93f7a1720856f4fec2de2 /src
parent88bce0425979f80439d03862d49ef81a9422c5cf (diff)
QDeclarativeDebug: Add a debug message service.
QDeclarativeDebugMsgService installs a QtMsgHandler which forwards debug output to a client defined port only if the service is Enabled. It also forwards the debug output to the previous message handler. Effectively, this service just eavesdrop on debug output, forwarding it to a port only if a client is connected. Change-Id: Ie0ee7bab57ef8f03a2de34d91921f054a7ec147f Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src')
-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
4 files changed, 217 insertions, 2 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();
}
}