iOS: QIOSEventDispatcher: add runloop source for processing events

Change-Id: I6cd649a493dab9a982d71921f19d2a9252fc14b0
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2012-11-05 10:53:59 +01:00 committed by Tor Arne Vestbø
parent a685df0584
commit 145abdc442
2 changed files with 64 additions and 8 deletions

View File

@ -77,6 +77,7 @@
#define QEVENTDISPATCHER_IOS_P_H
#include <QtCore/qabstracteventdispatcher.h>
#include <CoreFoundation/CoreFoundation.h>
QT_BEGIN_NAMESPACE
@ -85,7 +86,8 @@ class QIOSEventDispatcher : public QAbstractEventDispatcher
Q_OBJECT
public:
explicit QIOSEventDispatcher(QObject *parent = 0); ~QIOSEventDispatcher();
explicit QIOSEventDispatcher(QObject *parent = 0);
~QIOSEventDispatcher();
bool processEvents(QEventLoop::ProcessEventsFlags flags);
bool hasPendingEvents();
@ -103,6 +105,11 @@ public:
void wakeUp();
void interrupt();
void flush();
private:
CFRunLoopSourceRef m_postedEventsSource;
static void postedEventsSourceCallback(void *info);
void processPostedEvents();
};
QT_END_NAMESPACE

View File

@ -75,42 +75,80 @@
#include "qioseventdispatcher.h"
#include <qdebug.h>
#include <qpa/qwindowsysteminterface.h>
QT_BEGIN_NAMESPACE
QT_USE_NAMESPACE
QIOSEventDispatcher::QIOSEventDispatcher(QObject *parent)
static Boolean runLoopSourceEqualCallback(const void *info1, const void *info2)
{
Q_UNUSED(parent);
qDebug() << __FUNCTION__ << "eventdispatcher not implemented";
return info1 == info2;
}
void QIOSEventDispatcher::postedEventsSourceCallback(void *info)
{
QIOSEventDispatcher *self = static_cast<QIOSEventDispatcher *>(info);
self->processPostedEvents();
}
void QIOSEventDispatcher::processPostedEvents()
{
qDebug() << __FUNCTION__ << "called";
QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
}
QIOSEventDispatcher::QIOSEventDispatcher(QObject *parent)
: QAbstractEventDispatcher(parent)
{
CFRunLoopRef mainRunLoop = CFRunLoopGetMain();
CFRunLoopSourceContext context;
bzero(&context, sizeof(CFRunLoopSourceContext));
context.equal = runLoopSourceEqualCallback;
context.info = this;
// source used to send posted events:
context.perform = QIOSEventDispatcher::postedEventsSourceCallback;
m_postedEventsSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
Q_ASSERT(m_postedEventsSource);
CFRunLoopAddSource(mainRunLoop, m_postedEventsSource, kCFRunLoopCommonModes);
}
QIOSEventDispatcher::~QIOSEventDispatcher()
{}
{
CFRunLoopRef mainRunLoop = CFRunLoopGetMain();
CFRunLoopRemoveSource(mainRunLoop, m_postedEventsSource, kCFRunLoopCommonModes);
CFRelease(m_postedEventsSource);
}
bool QIOSEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
{
Q_UNUSED(flags);
qDebug() << __FUNCTION__ << "not implemented";
return false;
}
bool QIOSEventDispatcher::hasPendingEvents()
{
qDebug() << __FUNCTION__ << "not implemented";
return false;
}
void QIOSEventDispatcher::registerSocketNotifier(QSocketNotifier *notifier)
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(notifier);
}
void QIOSEventDispatcher::unregisterSocketNotifier(QSocketNotifier *notifier)
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(notifier);
}
void QIOSEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(timerId);
Q_UNUSED(interval);
Q_UNUSED(timerType);
@ -119,36 +157,47 @@ void QIOSEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType
bool QIOSEventDispatcher::unregisterTimer(int timerId)
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(timerId);
return false;
}
bool QIOSEventDispatcher::unregisterTimers(QObject *object)
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(object);
return false;
}
QList<QAbstractEventDispatcher::TimerInfo> QIOSEventDispatcher::registeredTimers(QObject *object) const
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(object);
return QList<TimerInfo>();
}
int QIOSEventDispatcher::remainingTime(int timerId)
{
qDebug() << __FUNCTION__ << "not implemented";
Q_UNUSED(timerId);
return 0;
}
void QIOSEventDispatcher::wakeUp()
{}
{
CFRunLoopSourceSignal(m_postedEventsSource);
CFRunLoopWakeUp(CFRunLoopGetMain());
}
void QIOSEventDispatcher::interrupt()
{}
{
qDebug() << __FUNCTION__ << "not implemented";
}
void QIOSEventDispatcher::flush()
{}
{
qDebug() << __FUNCTION__ << "not implemented";
}
QT_END_NAMESPACE