summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Krammer <kevin.krammer.qnx@kdab.com>2012-03-20 13:55:50 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-22 10:51:43 +0100
commit25db638d26a0d3ca6a403987d40e142f498b21ad (patch)
treedcea1ec855c89d00339da5fa31bf8e264704de05
parent37cfea29101361e57c185923e2de7ce0ab3ab74e (diff)
Use main thread event loop for navigator event processing
Removes the need for an extra thread by creating the event handler's socket notifier in the context of the main thread. Backport of 9dc86ac0f2d019f93665c1ae0e3c2cd33fd88bce Change-Id: I5c31d904191f45698085e8fd576481018e072ef4 Reviewed-by: Sean Harmer <sh@theharmers.co.uk> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
-rw-r--r--src/plugins/platforms/blackberry/blackberry.pro4
-rw-r--r--src/plugins/platforms/blackberry/qbbintegration.cpp16
-rw-r--r--src/plugins/platforms/blackberry/qbbintegration.h4
-rw-r--r--src/plugins/platforms/blackberry/qbbnavigatoreventhandler.cpp (renamed from src/plugins/platforms/blackberry/qbbnavigatorthread.cpp)81
-rw-r--r--src/plugins/platforms/blackberry/qbbnavigatoreventhandler.h (renamed from src/plugins/platforms/blackberry/qbbnavigatorthread.h)19
5 files changed, 53 insertions, 71 deletions
diff --git a/src/plugins/platforms/blackberry/blackberry.pro b/src/plugins/platforms/blackberry/blackberry.pro
index 9978945267..0e55090396 100644
--- a/src/plugins/platforms/blackberry/blackberry.pro
+++ b/src/plugins/platforms/blackberry/blackberry.pro
@@ -11,7 +11,7 @@ SOURCES = main.cpp \
qbbglwindowsurface.cpp \
qbbinputcontext.cpp \
qbbintegration.cpp \
- qbbnavigatorthread.cpp \
+ qbbnavigatoreventhandler.cpp \
qbbscreen.cpp \
qbbwindow.cpp \
qbbrasterwindowsurface.cpp \
@@ -24,7 +24,7 @@ HEADERS = qbbbuffer.h \
qbbeventthread.h \
qbbinputcontext.h \
qbbintegration.h \
- qbbnavigatorthread.h \
+ qbbnavigatoreventhandler.h \
qbbglcontext.h \
qbbglwindowsurface.h \
qbbscreen.h \
diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp
index cc169384c2..7cada161b4 100644
--- a/src/plugins/platforms/blackberry/qbbintegration.cpp
+++ b/src/plugins/platforms/blackberry/qbbintegration.cpp
@@ -44,7 +44,7 @@
#include "qbbeventthread.h"
#include "qbbglcontext.h"
#include "qbbglwindowsurface.h"
-#include "qbbnavigatorthread.h"
+#include "qbbnavigatoreventhandler.h"
#include "qbbrasterwindowsurface.h"
#include "qbbscreen.h"
#include "qbbwindow.h"
@@ -93,9 +93,15 @@ QBBIntegration::QBBIntegration() :
mEventThread = new QBBEventThread(mContext, *QBBScreen::primaryDisplay());
mEventThread->start();
- // create/start navigator thread
- mNavigatorThread = new QBBNavigatorThread(*QBBScreen::primaryDisplay());
- mNavigatorThread->start();
+ // Create/start navigator event handler
+ // Not on BlackBerry, it has specialised event dispatcher which also handles navigator events
+#ifndef Q_OS_BLACKBERRY
+ mNavigatorEventHandler = new QBBNavigatorEventHandler(*QBBScreen::primaryDisplay());
+
+ // delay invocation of start() to the time the event loop is up and running
+ // needed to have the QThread internals of the main thread properly initialized
+ QMetaObject::invokeMethod(mNavigatorEventHandler, "start", Qt::QueuedConnection);
+#endif
#ifdef QBBLOCALETHREAD_ENABLED
// Start the locale change monitoring thread.
@@ -127,7 +133,7 @@ QBBIntegration::~QBBIntegration()
delete mEventThread;
// stop/destroy navigator thread
- delete mNavigatorThread;
+ delete mNavigatorEventHandler;
// destroy all displays
QBBScreen::destroyDisplays();
diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h
index 8c20b6ccfa..2a9fceb626 100644
--- a/src/plugins/platforms/blackberry/qbbintegration.h
+++ b/src/plugins/platforms/blackberry/qbbintegration.h
@@ -47,7 +47,7 @@
QT_BEGIN_NAMESPACE
class QBBEventThread;
-class QBBNavigatorThread;
+class QBBNavigatorEventHandler;
class QBBLocaleThread;
class QBBIntegration : public QPlatformIntegration
@@ -77,7 +77,7 @@ public:
private:
screen_context_t mContext;
QBBEventThread *mEventThread;
- QBBNavigatorThread *mNavigatorThread;
+ QBBNavigatorEventHandler *mNavigatorEventHandler;
QBBLocaleThread *mLocaleThread;
QPlatformFontDatabase *mFontDb;
bool mPaintUsingOpenGL;
diff --git a/src/plugins/platforms/blackberry/qbbnavigatorthread.cpp b/src/plugins/platforms/blackberry/qbbnavigatoreventhandler.cpp
index 675e812b04..877e91cdd4 100644
--- a/src/plugins/platforms/blackberry/qbbnavigatorthread.cpp
+++ b/src/plugins/platforms/blackberry/qbbnavigatoreventhandler.cpp
@@ -37,10 +37,10 @@
**
****************************************************************************/
-//#define QBBNAVIGATORTHREAD_DEBUG
+//#define QBBNAVIGATOREVENTHANDLER_DEBUG
-#include "qbbnavigatorthread.h"
+#include "qbbnavigatoreventhandler.h"
#include "qbbscreen.h"
#include <QtCore/private/qcore_unix_p.h>
@@ -61,25 +61,29 @@
#define NAV_CONTROL_PATH "/pps/services/navigator/control"
#define PPS_BUFFER_SIZE 4096
-QBBNavigatorThread::QBBNavigatorThread(QBBScreen& primaryScreen)
+QBBNavigatorEventHandler::QBBNavigatorEventHandler(QBBScreen& primaryScreen)
: mPrimaryScreen(primaryScreen),
mFd(-1),
mReadNotifier(0)
{
}
-QBBNavigatorThread::~QBBNavigatorThread()
+QBBNavigatorEventHandler::~QBBNavigatorEventHandler()
{
- // block until thread terminates
- shutdown();
-
delete mReadNotifier;
+
+ if (mFd != -1)
+ close(mFd);
+
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
+ qDebug() << "QBB: navigator event handler stopped";
+#endif
}
-void QBBNavigatorThread::run()
+void QBBNavigatorEventHandler::start()
{
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
- qDebug() << "QBB: navigator thread started";
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
+ qDebug() << "QBB: navigator event handler started";
#endif
// open connection to navigator
@@ -91,39 +95,12 @@ void QBBNavigatorThread::run()
}
mReadNotifier = new QSocketNotifier(mFd, QSocketNotifier::Read);
- // using direct connection to get the slot called in this thread's context
- connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(readData()), Qt::DirectConnection);
-
- exec();
-
- // close connection to navigator
- close(mFd);
-
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
- qDebug() << "QBB: navigator thread stopped";
-#endif
-}
-
-void QBBNavigatorThread::shutdown()
-{
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
- qDebug() << "QBB: navigator thread shutdown begin";
-#endif
-
- // signal thread to terminate
- quit();
-
- // block until thread terminates
- wait();
-
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
- qDebug() << "QBB: navigator thread shutdown end";
-#endif
+ connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(readData()));
}
-void QBBNavigatorThread::parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id)
+void QBBNavigatorEventHandler::parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id)
{
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: data=" << ppsData;
#endif
@@ -141,7 +118,7 @@ void QBBNavigatorThread::parsePPS(const QByteArray &ppsData, QByteArray &msg, QB
// tokenize current attribute
const QByteArray &attr = lines.at(i);
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: attr=" << attr;
#endif
@@ -160,7 +137,7 @@ void QBBNavigatorThread::parsePPS(const QByteArray &ppsData, QByteArray &msg, QB
QByteArray key = attr.left(firstColon);
QByteArray value = attr.mid(secondColon + 1);
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: key=" << key;
qDebug() << "PPS: val=" << value;
#endif
@@ -178,7 +155,7 @@ void QBBNavigatorThread::parsePPS(const QByteArray &ppsData, QByteArray &msg, QB
}
}
-void QBBNavigatorThread::replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat)
+void QBBNavigatorEventHandler::replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat)
{
// construct pps message
QByteArray ppsData = "res::";
@@ -191,7 +168,7 @@ void QBBNavigatorThread::replyPPS(const QByteArray &res, const QByteArray &id, c
}
ppsData += "\n";
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS reply=" << ppsData;
#endif
@@ -203,9 +180,9 @@ void QBBNavigatorThread::replyPPS(const QByteArray &res, const QByteArray &id, c
}
}
-void QBBNavigatorThread::handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id)
+void QBBNavigatorEventHandler::handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id)
{
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: msg=" << msg << ", dat=" << dat << ", id=" << id;
#endif
@@ -213,7 +190,7 @@ void QBBNavigatorThread::handleMessage(const QByteArray &msg, const QByteArray &
if (msg == "orientationCheck") {
// reply to navigator that (any) orientation is acceptable
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: orientation check, o=" << dat;
#endif
replyPPS(msg, id, "true");
@@ -221,7 +198,7 @@ void QBBNavigatorThread::handleMessage(const QByteArray &msg, const QByteArray &
} else if (msg == "orientation") {
// update screen geometry and reply to navigator that we're ready
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: orientation, o=" << dat;
#endif
mPrimaryScreen.setRotation( dat.toInt() );
@@ -231,7 +208,7 @@ void QBBNavigatorThread::handleMessage(const QByteArray &msg, const QByteArray &
} else if (msg == "SWIPE_DOWN") {
// simulate menu key press
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: menu";
#endif
QWidget *w = QApplication::activeWindow();
@@ -241,16 +218,16 @@ void QBBNavigatorThread::handleMessage(const QByteArray &msg, const QByteArray &
} else if (msg == "exit") {
// shutdown everything
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "PPS: exit";
#endif
QApplication::quit();
}
}
-void QBBNavigatorThread::readData()
+void QBBNavigatorEventHandler::readData()
{
-#if defined(QBBNAVIGATORTHREAD_DEBUG)
+#if defined(QBBNAVIGATOREVENTHANDLER_DEBUG)
qDebug() << "QBB: reading navigator data";
#endif
diff --git a/src/plugins/platforms/blackberry/qbbnavigatorthread.h b/src/plugins/platforms/blackberry/qbbnavigatoreventhandler.h
index a4dd23a31f..4bac9096d9 100644
--- a/src/plugins/platforms/blackberry/qbbnavigatorthread.h
+++ b/src/plugins/platforms/blackberry/qbbnavigatoreventhandler.h
@@ -37,25 +37,25 @@
**
****************************************************************************/
-#ifndef QBBNAVIGATORTHREAD_H
-#define QBBNAVIGATORTHREAD_H
+#ifndef QBBNAVIGATOREVENTHANDLER_H
+#define QBBNAVIGATOREVENTHANDLER_H
-#include <QThread>
+#include <QObject>
QT_BEGIN_NAMESPACE
class QBBScreen;
class QSocketNotifier;
-class QBBNavigatorThread : public QThread
+class QBBNavigatorEventHandler : public QObject
{
Q_OBJECT
public:
- QBBNavigatorThread(QBBScreen& primaryScreen);
- virtual ~QBBNavigatorThread();
+ QBBNavigatorEventHandler(QBBScreen& primaryScreen);
+ virtual ~QBBNavigatorEventHandler();
-protected:
- virtual void run();
+public Q_SLOTS:
+ void start();
private Q_SLOTS:
void readData();
@@ -65,7 +65,6 @@ private:
int mFd;
QSocketNotifier *mReadNotifier;
- void shutdown();
void parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id);
void replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat);
void handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id);
@@ -73,4 +72,4 @@ private:
QT_END_NAMESPACE
-#endif // QBBNAVIGATORTHREAD_H
+#endif // QBBNAVIGATOREVENTHANDLER_H