diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-06-17 12:57:48 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-23 11:28:48 +0200 |
commit | c0e5f31ad8621127af17ae8cc1660a249391d1eb (patch) | |
tree | 4e71dcaf99a376174feaa6a4f0f2bea5b5d5c327 /src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h | |
parent | 29c1567ee4724b02995060035df8d93f7d6d9c37 (diff) |
iOS: Wrap CFRunLoopSource in C++ class for easier code legibility
Change-Id: If34953b171676f0246c2fb5e60c59f59350863ec
Reviewed-by: Ian Dean <ian@mediator-software.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h')
-rw-r--r-- | src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h b/src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h index 6e5ce658a8..e12098d814 100644 --- a/src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h +++ b/src/platformsupport/eventdispatchers/qeventdispatcher_cf_p.h @@ -83,6 +83,55 @@ QT_BEGIN_NAMESPACE +class QEventDispatcherCoreFoundation; + +template <class T = QEventDispatcherCoreFoundation> +class RunLoopSource +{ +public: + typedef void (T::*CallbackFunction) (); + + enum { kHighestPriority = 0 } RunLoopSourcePriority; + + RunLoopSource(T *delegate, CallbackFunction callback) + : m_delegate(delegate), m_callback(callback) + { + CFRunLoopSourceContext context = {}; + context.info = this; + context.perform = RunLoopSource::process; + + m_source = CFRunLoopSourceCreate(kCFAllocatorDefault, kHighestPriority, &context); + Q_ASSERT(m_source); + } + + ~RunLoopSource() + { + CFRunLoopSourceInvalidate(m_source); + CFRelease(m_source); + } + + void addToMode(CFStringRef mode, CFRunLoopRef runLoop = 0) + { + if (!runLoop) + runLoop = CFRunLoopGetCurrent(); + + CFRunLoopAddSource(runLoop, m_source, mode); + } + + void signal() { CFRunLoopSourceSignal(m_source); } + +private: + static void process(void *info) + { + RunLoopSource *self = static_cast<RunLoopSource *>(info); + ((self->m_delegate)->*(self->m_callback))(); + } + + T *m_delegate; + CallbackFunction m_callback; + CFRunLoopSourceRef m_source; +}; + class QEventDispatcherCoreFoundation : public QAbstractEventDispatcher { Q_OBJECT @@ -111,8 +160,8 @@ public: private: bool m_interrupted; - CFRunLoopSourceRef m_postedEventsRunLoopSource; - CFRunLoopSourceRef m_blockingTimerRunLoopSource; + RunLoopSource<> m_postedEventsRunLoopSource; + RunLoopSource<> m_blockingTimerRunLoopSource; QTimerInfoList m_timerInfoList; CFRunLoopTimerRef m_runLoopTimerRef; @@ -120,12 +169,11 @@ private: QCFSocketNotifier m_cfSocketNotifier; void processPostedEvents(); + void processTimers(); void maybeStartCFRunLoopTimer(); void maybeStopCFRunLoopTimer(); - static void postedEventsRunLoopCallback(void *info); static void nonBlockingTimerRunLoopCallback(CFRunLoopTimerRef, void *info); - static void blockingTimerRunLoopCallback(void *info); }; QT_END_NAMESPACE |