Qt 6.x
The Qt SDK
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:
177 void startingUp() override;
179
180 bool processEvents(QEventLoop::ProcessEventsFlags flags) override;
181
184
185 void registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object) override;
186 bool unregisterTimer(int timerId) override;
187 bool unregisterTimers(QObject *object) override;
189
190 int remainingTime(int timerId) override;
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
213 };
214
216
217private:
218 RunLoopSource<> m_postedEventsRunLoopSource;
219 RunLoopObserver<> m_runLoopActivityObserver;
220
221 QT_MANGLE_NAMESPACE(RunLoopModeTracker) *m_runLoopModeTracker;
222
223 QTimerInfoList m_timerInfoList;
224 CFRunLoopTimerRef m_runLoopTimer;
225 CFRunLoopTimerRef m_blockedRunLoopTimer;
226 QCFType<CFRunLoopRef> m_runLoop;
227 bool m_overdueTimerScheduled;
228
229 QCFSocketNotifier m_cfSocketNotifier;
230
231 void processTimers(CFRunLoopTimerRef);
232
233 void handleRunLoopActivity(CFRunLoopActivity activity);
234
235 void updateTimers();
236 void invalidateTimer();
237};
238
240
241#endif // QEVENTDISPATCHER_CF_P_H
DarwinBluetooth::LECBManagerNotifier * notifier
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore
Definition qatomic.h:18
void interrupt() override
Interrupts event dispatching.
virtual bool processPostedEvents()
QList< QAbstractEventDispatcher::TimerInfo > registeredTimers(QObject *object) const override
Returns a list of registered timers for object.
void registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object) override
Register a timer with the specified timerId, interval, and timerType for the given object.
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
bool unregisterTimers(QObject *object) override
Unregisters all the timers associated with the given object.
QEventDispatcherCoreFoundation(QObject *parent=nullptr)
void unregisterSocketNotifier(QSocketNotifier *notifier) override
Unregisters notifier from the event dispatcher.
bool unregisterTimer(int timerId) override
Unregisters the timer with the given timerId.
QEventLoop * currentEventLoop() const
int remainingTime(int timerId) override
Returns the remaining time in milliseconds with the given timerId.
\inmodule QtCore
Definition qeventloop.h:16
Definition qlist.h:74
\inmodule QtCore
Definition qobject.h:90
\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_NAMESPACE
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
long long qint64
Definition qtypes.h:55
static int toInt(const QChar &qc, int R)
QFileInfo info(fileName)
[8]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent