summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Sorvig <morten.sorvig@nokia.com>2010-03-16 14:08:30 +0100
committerMorten Sorvig <morten.sorvig@nokia.com>2010-03-16 14:08:30 +0100
commit5670562050ed2f757925b742f7b548a3e87c5909 (patch)
treeeba2eb3dc4a532b8c734a481d101440437ad11f0
parent0ade8ec2cc4b8ae544122aea5b4093d75189e912 (diff)
Implement timer support.
Timers are disabled, NPN_ScheduleTimer seems to be missing from from my version in the nacl/pepper SDK. (It is implemented in Chromium, see http://code.google.com/p/chromium/issues/detail?id=18020)
-rw-r--r--src/gui/kernel/qeventdispatcher_pepper.cpp67
-rw-r--r--src/gui/kernel/qeventdispatcher_pepper_p.h6
2 files changed, 73 insertions, 0 deletions
diff --git a/src/gui/kernel/qeventdispatcher_pepper.cpp b/src/gui/kernel/qeventdispatcher_pepper.cpp
index 8aa944b2b5..f7f6a6b9d5 100644
--- a/src/gui/kernel/qeventdispatcher_pepper.cpp
+++ b/src/gui/kernel/qeventdispatcher_pepper.cpp
@@ -58,6 +58,7 @@
#include <nacl/npruntime.h>
#include <nacl/npupp.h>
+#include "event_handler.h"
QT_BEGIN_NAMESPACE
@@ -157,6 +158,72 @@ void QEventDispatcherPepper::unregisterSocketNotifier(QSocketNotifier *notifier)
Q_UNUSED(notifier);
}
+/*
+ Timer support. Do the simplest thing possible for now,
+ re-use the QTimerInfoList from the unix dispatcher.
+ Call NPN_ScheduleTimer for each Qt timer, but
+ simply call activateTimers() in the callback and let
+ the timer list class figure out which timer to fire.
+
+ Some complexity is added because of the dual thread
+ system (Qt main thread and the plugin thread).
+*/
+
+/*
+ Timer callback. Called in the the plugin thread.
+*/
+void qt_pepper_timer_callback(NPP npp, uint32 timerID)
+{
+ Q_UNUSED(npp);
+ Q_UNUSED(timerID);
+ qDebug() << "Pepper timer callback" << timerID;
+ qt_pepper_envent_dispatcher->activateTimers();
+}
+
+struct QtPepperTimerInfo
+{
+ int interval;
+};
+
+/*
+ Timer registration function. Called in the plugin thread.
+*/
+void qt_pepper_registerTimer(void *data)
+{
+ QtPepperTimerInfo *timerInfo = static_cast<QtPepperTimerInfo *>(data);
+
+ // uint32 NPN_ScheduleTimer(NPP npp, uint32 interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32 timerID));
+ extern NPNetscapeFuncs* browser;
+ extern EventHandler* event_handler;
+ // ### disabled (no NPN_ScheduleTimer call in nacl)
+ // uint32 pepperId = browser->scheduletimer(event_handler->npp_, timerInfo->interval, true, qt_pepper_timer_callback);
+ qDebug() << "qt_pepper_registerTimer" << timerInfo->interval; // << "pepper id" << pepperId;
+ delete timerInfo;
+}
+
+void QEventDispatcherPepper::registerTimer(int timerId, int interval, QObject *object)
+{
+ qDebug() << "register timer" << timerId << interval << object;
+ QtPepperTimerInfo *timerInfo = new QtPepperTimerInfo();
+ timerInfo->interval = interval;
+
+ // register the timer in the plugin thread.
+ NPN_PluginThreadAsyncCall(event_handler->npp_, qt_pepper_registerTimer, timerInfo);
+ return QEventDispatcherUNIX::registerTimer(timerId, interval, object);
+}
+
+bool QEventDispatcherPepper::unregisterTimer(int timerId)
+{
+ qDebug() << "unregister timer" << timerId;
+ return QEventDispatcherUNIX::unregisterTimer(timerId);
+}
+
+bool QEventDispatcherPepper::unregisterTimers(QObject *object)
+{
+ qDebug() << "unregister timers" << object;
+ return QEventDispatcherUNIX::unregisterTimers(object);
+}
+
void QEventDispatcherPepper::startingUp()
{
diff --git a/src/gui/kernel/qeventdispatcher_pepper_p.h b/src/gui/kernel/qeventdispatcher_pepper_p.h
index 0bd050dca7..d500783149 100644
--- a/src/gui/kernel/qeventdispatcher_pepper_p.h
+++ b/src/gui/kernel/qeventdispatcher_pepper_p.h
@@ -82,6 +82,10 @@ public:
void registerSocketNotifier(QSocketNotifier *notifier);
void unregisterSocketNotifier(QSocketNotifier *notifier);
+ void registerTimer(int timerId, int interval, QObject *object);
+ bool unregisterTimer(int timerId);
+ bool unregisterTimers(QObject *object);
+
void wakeUp();
void interrupt();
void flush();
@@ -90,6 +94,8 @@ public:
void closingDown();
void queueEvent(NPPepperEvent *event);
+ using QEventDispatcherUNIX::activateTimers; // promote to public
+
private:
void processPepperEvent(NPPepperEvent *event);
void processKeyEvent(NPKeyEvent *key, uint32 eventType);