Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qeventdispatcher_cf_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4/****************************************************************************
5**
6** Copyright (c) 2007-2008, Apple, Inc.
7**
8** All rights reserved.
9**
10** Redistribution and use in source and binary forms, with or without
11** modification, are permitted provided that the following conditions are met:
12**
13** * Redistributions of source code must retain the above copyright notice,
14** this list of conditions and the following disclaimer.
15**
16** * Redistributions in binary form must reproduce the above copyright notice,
17** this list of conditions and the following disclaimer in the documentation
18** and/or other materials provided with the distribution.
19**
20** * Neither the name of Apple, Inc. nor the names of its contributors
21** may be used to endorse or promote products derived from this software
22** without specific prior written permission.
23**
24** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35**
36****************************************************************************/
37
38#ifndef QEVENTDISPATCHER_CF_P_H
39#define QEVENTDISPATCHER_CF_P_H
40
41//
42// W A R N I N G
43// -------------
44//
45// This file is not part of the Qt API. It exists purely as an
46// implementation detail. This header file may change from version to
47// version without notice, or even be removed.
48//
49// We mean it.
50//
51
52#include <QtCore/qabstracteventdispatcher.h>
53#include <QtCore/private/qtimerinfo_unix_p.h>
54#include <QtCore/private/qcfsocketnotifier_p.h>
55#include <QtCore/private/qcore_mac_p.h>
56#include <QtCore/qdebug.h>
57#include <QtCore/qloggingcategory.h>
58
59#include <CoreFoundation/CoreFoundation.h>
60
62
64
65namespace QtPrivate {
66Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcEventDispatcher, Q_CORE_EXPORT)
67Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcEventDispatcherTimers, Q_CORE_EXPORT)
68}
69
71
72template <class T = QEventDispatcherCoreFoundation>
74{
75public:
76 typedef bool (T::*CallbackFunction)();
77
79
80 RunLoopSource(T *delegate, CallbackFunction callback)
81 : m_delegate(delegate), m_callback(callback)
82 {
83 CFRunLoopSourceContext context = {};
84 context.info = this;
85 context.perform = RunLoopSource::process;
86
87 m_source = CFRunLoopSourceCreate(kCFAllocatorDefault, kHighestPriority, &context);
88 Q_ASSERT(m_source);
89 }
90
92 {
93 CFRunLoopSourceInvalidate(m_source);
94 CFRelease(m_source);
95 }
96
97 void addToMode(CFStringRef mode, CFRunLoopRef runLoop = 0)
98 {
99 if (!runLoop)
100 runLoop = CFRunLoopGetCurrent();
101
102 CFRunLoopAddSource(runLoop, m_source, mode);
103 }
104
105 void signal() { CFRunLoopSourceSignal(m_source); }
106
107private:
108 static void process(void *info)
109 {
110 RunLoopSource *self = static_cast<RunLoopSource *>(info);
111 ((self->m_delegate)->*(self->m_callback))();
112 }
113
114 T *m_delegate;
115 CallbackFunction m_callback;
116 CFRunLoopSourceRef m_source;
117};
118
119template <class T = QEventDispatcherCoreFoundation>
121{
122public:
123 typedef void (T::*CallbackFunction) (CFRunLoopActivity activity);
124
125 RunLoopObserver(T *delegate, CallbackFunction callback, CFOptionFlags activities)
126 : m_delegate(delegate), m_callback(callback)
127 {
128 CFRunLoopObserverContext context = {};
129 context.info = this;
130
131 m_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, activities, true, 0, process, &context);
132 Q_ASSERT(m_observer);
133 }
134
136 {
137 CFRunLoopObserverInvalidate(m_observer);
138 CFRelease(m_observer);
139 }
140
141 void addToMode(CFStringRef mode, CFRunLoopRef runLoop = 0)
142 {
143 if (!runLoop)
144 runLoop = CFRunLoopGetCurrent();
145
146 if (!CFRunLoopContainsObserver(runLoop, m_observer, mode))
147 CFRunLoopAddObserver(runLoop, m_observer, mode);
148 }
149
150 void removeFromMode(CFStringRef mode, CFRunLoopRef runLoop = 0)
151 {
152 if (!runLoop)
153 runLoop = CFRunLoopGetCurrent();
154
155 if (CFRunLoopContainsObserver(runLoop, m_observer, mode))
156 CFRunLoopRemoveObserver(runLoop, m_observer, mode);
157 }
158
159private:
160 static void process(CFRunLoopObserverRef, CFRunLoopActivity activity, void *info)
161 {
162 RunLoopObserver *self = static_cast<RunLoopObserver *>(info);
163 ((self->m_delegate)->*(self->m_callback))(activity);
164 }
165
166 T *m_delegate;
167 CallbackFunction m_callback;
168 CFRunLoopObserverRef m_observer;
169};
170
172{
174
175public:
176 explicit QEventDispatcherCoreFoundation(QObject *parent = nullptr);
177 void startingUp() override;
179
180 bool processEvents(QEventLoop::ProcessEventsFlags flags) override;
181
184
185 void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType,
186 QObject *object) override final;
187 bool unregisterTimer(Qt::TimerId timerId) override final;
188 bool unregisterTimers(QObject *object) override final;
189 QList<TimerInfoV2> timersForObject(QObject *object) const override final;
190 Duration remainingTime(Qt::TimerId timerId) const override final;
191
192 void wakeUp() override;
193 void interrupt() override;
194
195protected:
197
198 virtual bool processPostedEvents();
199
201 {
202 ProcessEventsState(QEventLoop::ProcessEventsFlags f)
203 : flags(f.toInt()), wasInterrupted(false)
204 , processedPostedEvents(false), processedTimers(false)
205 , deferredWakeUp(false), deferredUpdateTimers(false) {}
206
208 : flags(other.flags.loadAcquire())
209 , wasInterrupted(other.wasInterrupted.loadAcquire())
210 , processedPostedEvents(other.processedPostedEvents.loadAcquire())
211 , processedTimers(other.processedTimers.loadAcquire())
212 , deferredWakeUp(other.deferredWakeUp.loadAcquire())
213 , deferredUpdateTimers(other.deferredUpdateTimers) {}
214
216 {
217 flags.storeRelease(other.flags.loadAcquire());
218 wasInterrupted.storeRelease(other.wasInterrupted.loadAcquire());
219 processedPostedEvents.storeRelease(other.processedPostedEvents.loadAcquire());
220 processedTimers.storeRelease(other.processedTimers.loadAcquire());
221 deferredWakeUp.storeRelease(other.deferredWakeUp.loadAcquire());
222 deferredUpdateTimers = other.deferredUpdateTimers;
223 return *this;
224 }
225
227 QAtomicInteger<char> wasInterrupted;
228 QAtomicInteger<char> processedPostedEvents;
229 QAtomicInteger<char> processedTimers;
230 QAtomicInteger<char> deferredWakeUp;
232 };
233
235
236private:
237 RunLoopSource<> m_postedEventsRunLoopSource;
238 RunLoopObserver<> m_runLoopActivityObserver;
239
240 QT_MANGLE_NAMESPACE(RunLoopModeTracker) *m_runLoopModeTracker;
241
242 QTimerInfoList m_timerInfoList;
243 CFRunLoopTimerRef m_runLoopTimer;
244 CFRunLoopTimerRef m_blockedRunLoopTimer;
245 QCFType<CFRunLoopRef> m_runLoop;
246 bool m_overdueTimerScheduled;
247
248 QCFSocketNotifier m_cfSocketNotifier;
249
250 void processTimers(CFRunLoopTimerRef);
251
252 void handleRunLoopActivity(CFRunLoopActivity activity);
253
254 void updateTimers();
255 void invalidateTimer();
256};
257
259
260#endif // QEVENTDISPATCHER_CF_P_H
DarwinBluetooth::LECBManagerNotifier * notifier
std::chrono::nanoseconds Duration
A {std::chrono::duration} type that is used in various API in this class.
\inmodule QtCore
Definition qatomic.h:112
void interrupt() override
Interrupts event dispatching.
virtual bool processPostedEvents()
void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object) override final
void registerSocketNotifier(QSocketNotifier *notifier) override
Registers notifier with the event loop.
bool processEvents(QEventLoop::ProcessEventsFlags flags) override
Processes pending events that match flags until there are no more events to process.
void wakeUp() override
\threadsafe
QEventDispatcherCoreFoundation(QObject *parent=nullptr)
QList< TimerInfoV2 > timersForObject(QObject *object) const override final
bool unregisterTimer(Qt::TimerId timerId) override final
void unregisterSocketNotifier(QSocketNotifier *notifier) override
Unregisters notifier from the event dispatcher.
QEventLoop * currentEventLoop() const
Duration remainingTime(Qt::TimerId timerId) const override final
Returns the remaining time of the timer with the given timerId.
bool unregisterTimers(QObject *object) override final
Unregisters all the timers associated with the given object.
\inmodule QtCore
Definition qeventloop.h:16
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
void(T::* CallbackFunction)(CFRunLoopActivity activity)
void addToMode(CFStringRef mode, CFRunLoopRef runLoop=0)
RunLoopObserver(T *delegate, CallbackFunction callback, CFOptionFlags activities)
void removeFromMode(CFStringRef mode, CFRunLoopRef runLoop=0)
void addToMode(CFStringRef mode, CFRunLoopRef runLoop=0)
RunLoopSource(T *delegate, CallbackFunction callback)
enum RunLoopSource::@34 RunLoopSourcePriority
bool(T::* CallbackFunction)()
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
TimerType
static void * context
#define Q_FORWARD_DECLARE_OBJC_CLASS(classname)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, export_macro)
GLenum mode
GLfloat GLfloat f
GLbitfield flags
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QT_MANGLE_NAMESPACE(name)
#define Q_OBJECT
static int toInt(const QChar &qc, int R)
QSharedPointer< T > other(t)
[5]
QHostInfo info
[0]
ProcessEventsState & operator=(const ProcessEventsState &other)