summaryrefslogtreecommitdiffstats
path: root/src/declarative/debugger
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/debugger')
-rw-r--r--src/declarative/debugger/qdeclarativedebugtrace.cpp60
-rw-r--r--src/declarative/debugger/qdeclarativedebugtrace_p.h20
2 files changed, 79 insertions, 1 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp
index d6bb5f88..366c8c57 100644
--- a/src/declarative/debugger/qdeclarativedebugtrace.cpp
+++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp
@@ -44,8 +44,68 @@
#include <QtCore/qdatastream.h>
#include <QtCore/qurl.h>
#include <QtCore/qtimer.h>
+#include <QDebug>
+
+#ifdef CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE
+
+namespace {
+
+ class GlobalInstanceDeleter
+ {
+ private:
+ QBasicAtomicPointer<QDeclarativeDebugTrace> &m_pointer;
+ public:
+ GlobalInstanceDeleter(QBasicAtomicPointer<QDeclarativeDebugTrace> &p)
+ : m_pointer(p)
+ {}
+ ~GlobalInstanceDeleter()
+ {
+ delete m_pointer.load();
+ m_pointer.store(0);
+ }
+ };
+
+ QBasicAtomicPointer<QDeclarativeDebugTrace> s_globalInstance = Q_BASIC_ATOMIC_INITIALIZER(0);
+}
+
+
+static QDeclarativeDebugTrace *traceInstance()
+{
+ return QDeclarativeDebugTrace::globalInstance();
+}
+
+QDeclarativeDebugTrace *QDeclarativeDebugTrace::globalInstance()
+{
+ if (!s_globalInstance.load()) {
+ // create default QDeclarativeDebugTrace instance if it is not explicitly set by setGlobalInstance(QDeclarativeDebugTrace *instance)
+ // thread safe implementation
+ QDeclarativeDebugTrace *x = new QDeclarativeDebugTrace();
+ if (!s_globalInstance.testAndSetOrdered(0, x))
+ delete x;
+ else
+ static GlobalInstanceDeleter cleanup(s_globalInstance);
+ }
+ return s_globalInstance.load();
+}
+
+/*!
+ * Set custom QDeclarativeDebugTrace instance \a custom_instance.
+ * Function fails if QDeclarativeDebugTrace::globalInstance() was called before.
+ * QDeclarativeDebugTrace framework takes ownership of the custom instance.
+ */
+void QDeclarativeDebugTrace::setGlobalInstance(QDeclarativeDebugTrace *custom_instance)
+{
+ if (!s_globalInstance.testAndSetOrdered(0, custom_instance)) {
+ qWarning() << "QDeclarativeDebugTrace::setGlobalInstance() - instance already set.";
+ delete custom_instance;
+ } else {
+ static GlobalInstanceDeleter cleanup(s_globalInstance);
+ }
+}
+#else // CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE
Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance);
+#endif
// convert to a QByteArray that can be sent to the debug client
// use of QDataStream can skew results if m_deferredSend == false
diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h
index f4d6c18b..dfd478b0 100644
--- a/src/declarative/debugger/qdeclarativedebugtrace_p.h
+++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h
@@ -42,6 +42,8 @@
#ifndef QDECLARATIVEDEBUGTRACE_P_H
#define QDECLARATIVEDEBUGTRACE_P_H
+#include "qtquick1global.h"
+
#include <private/qdeclarativedebugservice_p.h>
#include <private/qperformancetimer_p.h>
@@ -63,7 +65,7 @@ struct QDeclarativeDebugData
};
class QUrl;
-class Q_AUTOTEST_EXPORT QDeclarativeDebugTrace : public QDeclarativeDebugService
+class Q_QUICK1_EXPORT QDeclarativeDebugTrace : public QDeclarativeDebugService
{
public:
enum Message {
@@ -105,6 +107,21 @@ public:
static void endRange(RangeType);
QDeclarativeDebugTrace();
+#ifdef CUSTOM_DECLARATIVE_DEBUG_TRACE_INSTANCE
+public:
+ static QDeclarativeDebugTrace* globalInstance();
+ static void setGlobalInstance(QDeclarativeDebugTrace *custom_instance);
+protected:
+ virtual void messageReceived(const QByteArray &);
+protected:
+ virtual void addEventImpl(EventType);
+ virtual void startRangeImpl(RangeType);
+ virtual void rangeDataImpl(RangeType, const QString &);
+ virtual void rangeDataImpl(RangeType, const QUrl &);
+ virtual void rangeLocationImpl(RangeType, const QString &, int);
+ virtual void rangeLocationImpl(RangeType, const QUrl &, int);
+ virtual void endRangeImpl(RangeType);
+#else
protected:
virtual void messageReceived(const QByteArray &);
private:
@@ -115,6 +132,7 @@ private:
void rangeLocationImpl(RangeType, const QString &, int);
void rangeLocationImpl(RangeType, const QUrl &, int);
void endRangeImpl(RangeType);
+#endif
void processMessage(const QDeclarativeDebugData &);
void sendMessages();
QPerformanceTimer m_timer;