Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qeventdispatcher_glib.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | struct GPollFDWithQSocketNotifier | - | ||||||
9 | { | - | ||||||
10 | GPollFD pollfd; | - | ||||||
11 | QSocketNotifier *socketNotifier; | - | ||||||
12 | }; | - | ||||||
13 | - | |||||||
14 | struct GSocketNotifierSource | - | ||||||
15 | { | - | ||||||
16 | GSource source; | - | ||||||
17 | QList<GPollFDWithQSocketNotifier *> pollfds; | - | ||||||
18 | }; | - | ||||||
19 | - | |||||||
20 | static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout) | - | ||||||
21 | { | - | ||||||
22 | if (timeout) | - | ||||||
23 | *timeout = -1; | - | ||||||
24 | return false; | - | ||||||
25 | } | - | ||||||
26 | - | |||||||
27 | static gboolean socketNotifierSourceCheck(GSource *source) | - | ||||||
28 | { | - | ||||||
29 | GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source); | - | ||||||
30 | - | |||||||
31 | bool pending = false; | - | ||||||
32 | for (int i = 0; !pending && i < src->pollfds.count(); ++i) { | - | ||||||
33 | GPollFDWithQSocketNotifier *p = src->pollfds.at(i); | - | ||||||
34 | - | |||||||
35 | if (p->pollfd.revents & G_IO_NVAL) { | - | ||||||
36 | - | |||||||
37 | static const char *t[] = { "Read", "Write", "Exception" }; | - | ||||||
38 | QMessageLogger(__FILE__, 7985, __PRETTY_FUNCTION__).warning("QSocketNotifier: Invalid socket %d and type '%s', disabling...", | - | ||||||
39 | p->pollfd.fd, t[int(p->socketNotifier->type())]); | - | ||||||
40 | - | |||||||
41 | p->socketNotifier->setEnabled(false); | - | ||||||
42 | } | - | ||||||
43 | - | |||||||
44 | pending = ((p->pollfd.revents & p->pollfd.events) != 0); | - | ||||||
45 | } | - | ||||||
46 | - | |||||||
47 | return pending; | - | ||||||
48 | } | - | ||||||
49 | - | |||||||
50 | static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer) | - | ||||||
51 | { | - | ||||||
52 | QEvent event(QEvent::SockAct); | - | ||||||
53 | - | |||||||
54 | GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source); | - | ||||||
55 | for (int i = 0; i < src->pollfds.count(); ++i) { | - | ||||||
56 | GPollFDWithQSocketNotifier *p = src->pollfds.at(i); | - | ||||||
57 | - | |||||||
58 | if ((p->pollfd.revents & p->pollfd.events) != 0) | - | ||||||
59 | QCoreApplication::sendEvent(p->socketNotifier, &event); | - | ||||||
60 | } | - | ||||||
61 | - | |||||||
62 | return true; | - | ||||||
63 | } | - | ||||||
64 | - | |||||||
65 | static GSourceFuncs socketNotifierSourceFuncs = { | - | ||||||
66 | socketNotifierSourcePrepare, | - | ||||||
67 | socketNotifierSourceCheck, | - | ||||||
68 | socketNotifierSourceDispatch, | - | ||||||
69 | __null, | - | ||||||
70 | __null, | - | ||||||
71 | __null | - | ||||||
72 | }; | - | ||||||
73 | - | |||||||
74 | struct GTimerSource | - | ||||||
75 | { | - | ||||||
76 | GSource source; | - | ||||||
77 | QTimerInfoList timerList; | - | ||||||
78 | QEventLoop::ProcessEventsFlags processEventsFlags; | - | ||||||
79 | bool runWithIdlePriority; | - | ||||||
80 | }; | - | ||||||
81 | - | |||||||
82 | static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout) | - | ||||||
83 | { | - | ||||||
84 | timespec tv = { 0l, 0l }; | - | ||||||
85 | if (!(src->processEventsFlags & QEventLoop::X11ExcludeTimers) && src->timerList.timerWait(tv)) | - | ||||||
86 | *timeout = (tv.tv_sec * 1000) + ((tv.tv_nsec + 999999) / 1000 / 1000); | - | ||||||
87 | else | - | ||||||
88 | *timeout = -1; | - | ||||||
89 | - | |||||||
90 | return (*timeout == 0); | - | ||||||
91 | } | - | ||||||
92 | - | |||||||
93 | static gboolean timerSourceCheckHelper(GTimerSource *src) | - | ||||||
94 | { | - | ||||||
95 | if (src->timerList.isEmpty()
| 287220-3126615 | ||||||
96 | || (src->processEventsFlags & QEventLoop::X11ExcludeTimers)) | - | ||||||
97 | return executed 3126617 times by 362 tests: false;return false; Executed by:
executed 3126617 times by 362 tests: return false; Executed by:
| 3126617 | ||||||
98 | - | |||||||
99 | if (src->timerList.updateCurrentTime() < src->timerList.firstconstFirst()->timeout
| 2363-284855 | ||||||
100 | return executed 284855 times by 208 tests: false;return false; Executed by:
executed 284855 times by 208 tests: return false; Executed by:
| 284855 | ||||||
101 | - | |||||||
102 | return executed 2363 times by 53 tests: true;return true; Executed by:
executed 2363 times by 53 tests: return true; Executed by:
| 2363 | ||||||
103 | } | - | ||||||
104 | - | |||||||
105 | static gboolean timerSourcePrepare(GSource *source, gint *timeout) | - | ||||||
106 | { | - | ||||||
107 | gint dummy; | - | ||||||
108 | if (!timeout) | - | ||||||
109 | timeout = &dummy; | - | ||||||
110 | - | |||||||
111 | GTimerSource *src = reinterpret_cast<GTimerSource *>(source); | - | ||||||
112 | if (src->runWithIdlePriority) { | - | ||||||
113 | if (timeout) | - | ||||||
114 | *timeout = -1; | - | ||||||
115 | return false; | - | ||||||
116 | } | - | ||||||
117 | - | |||||||
118 | return timerSourcePrepareHelper(src, timeout); | - | ||||||
119 | } | - | ||||||
120 | - | |||||||
121 | static gboolean timerSourceCheck(GSource *source) | - | ||||||
122 | { | - | ||||||
123 | GTimerSource *src = reinterpret_cast<GTimerSource *>(source); | - | ||||||
124 | if (src->runWithIdlePriority) | - | ||||||
125 | return false; | - | ||||||
126 | return timerSourceCheckHelper(src); | - | ||||||
127 | } | - | ||||||
128 | - | |||||||
129 | static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer) | - | ||||||
130 | { | - | ||||||
131 | GTimerSource *timerSource = reinterpret_cast<GTimerSource *>(source); | - | ||||||
132 | if (timerSource->processEventsFlags & QEventLoop::X11ExcludeTimers) | - | ||||||
133 | return true; | - | ||||||
134 | timerSource->runWithIdlePriority = true; | - | ||||||
135 | (void) timerSource->timerList.activateTimers(); | - | ||||||
136 | return true; | - | ||||||
137 | } | - | ||||||
138 | - | |||||||
139 | static GSourceFuncs timerSourceFuncs = { | - | ||||||
140 | timerSourcePrepare, | - | ||||||
141 | timerSourceCheck, | - | ||||||
142 | timerSourceDispatch, | - | ||||||
143 | __null, | - | ||||||
144 | __null, | - | ||||||
145 | __null | - | ||||||
146 | }; | - | ||||||
147 | - | |||||||
148 | struct GIdleTimerSource | - | ||||||
149 | { | - | ||||||
150 | GSource source; | - | ||||||
151 | GTimerSource *timerSource; | - | ||||||
152 | }; | - | ||||||
153 | - | |||||||
154 | static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout) | - | ||||||
155 | { | - | ||||||
156 | GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source); | - | ||||||
157 | GTimerSource *timerSource = idleTimerSource->timerSource; | - | ||||||
158 | if (!timerSource->runWithIdlePriority) { | - | ||||||
159 | - | |||||||
160 | if (timeout) | - | ||||||
161 | *timeout = -1; | - | ||||||
162 | return false; | - | ||||||
163 | } | - | ||||||
164 | - | |||||||
165 | return timerSourcePrepareHelper(timerSource, timeout); | - | ||||||
166 | } | - | ||||||
167 | - | |||||||
168 | static gboolean idleTimerSourceCheck(GSource *source) | - | ||||||
169 | { | - | ||||||
170 | GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source); | - | ||||||
171 | GTimerSource *timerSource = idleTimerSource->timerSource; | - | ||||||
172 | if (!timerSource->runWithIdlePriority) { | - | ||||||
173 | - | |||||||
174 | return false; | - | ||||||
175 | } | - | ||||||
176 | return timerSourceCheckHelper(timerSource); | - | ||||||
177 | } | - | ||||||
178 | - | |||||||
179 | static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer) | - | ||||||
180 | { | - | ||||||
181 | GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource; | - | ||||||
182 | (void) timerSourceDispatch(&timerSource->source, 0, 0); | - | ||||||
183 | return true; | - | ||||||
184 | } | - | ||||||
185 | - | |||||||
186 | static GSourceFuncs idleTimerSourceFuncs = { | - | ||||||
187 | idleTimerSourcePrepare, | - | ||||||
188 | idleTimerSourceCheck, | - | ||||||
189 | idleTimerSourceDispatch, | - | ||||||
190 | __null, | - | ||||||
191 | __null, | - | ||||||
192 | __null | - | ||||||
193 | }; | - | ||||||
194 | - | |||||||
195 | struct GPostEventSource | - | ||||||
196 | { | - | ||||||
197 | GSource source; | - | ||||||
198 | QAtomicInt serialNumber; | - | ||||||
199 | int lastSerialNumber; | - | ||||||
200 | QEventDispatcherGlibPrivate *d; | - | ||||||
201 | }; | - | ||||||
202 | - | |||||||
203 | static gboolean postEventSourcePrepare(GSource *s, gint *timeout) | - | ||||||
204 | { | - | ||||||
205 | QThreadData *data = QThreadData::current(); | - | ||||||
206 | if (!data) | - | ||||||
207 | return false; | - | ||||||
208 | - | |||||||
209 | gint dummy; | - | ||||||
210 | if (!timeout) | - | ||||||
211 | timeout = &dummy; | - | ||||||
212 | const bool canWait = data->canWaitLocked(); | - | ||||||
213 | *timeout = canWait ? -1 : 0; | - | ||||||
214 | - | |||||||
215 | GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s); | - | ||||||
216 | return (!canWait | - | ||||||
217 | || (source->serialNumber.load() != source->lastSerialNumber)); | - | ||||||
218 | } | - | ||||||
219 | - | |||||||
220 | static gboolean postEventSourceCheck(GSource *source) | - | ||||||
221 | { | - | ||||||
222 | return postEventSourcePrepare(source, 0); | - | ||||||
223 | } | - | ||||||
224 | - | |||||||
225 | static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer) | - | ||||||
226 | { | - | ||||||
227 | GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s); | - | ||||||
228 | source->lastSerialNumber = source->serialNumber.load(); | - | ||||||
229 | QCoreApplication::sendPostedEvents(); | - | ||||||
230 | source->d->runTimersOnceWithNormalPriority(); | - | ||||||
231 | return true; | - | ||||||
232 | } | - | ||||||
233 | - | |||||||
234 | static GSourceFuncs postEventSourceFuncs = { | - | ||||||
235 | postEventSourcePrepare, | - | ||||||
236 | postEventSourceCheck, | - | ||||||
237 | postEventSourceDispatch, | - | ||||||
238 | __null, | - | ||||||
239 | __null, | - | ||||||
240 | __null | - | ||||||
241 | }; | - | ||||||
242 | - | |||||||
243 | - | |||||||
244 | QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) | - | ||||||
245 | : mainContext(context) | - | ||||||
246 | { | - | ||||||
247 | if (mainContext) { | - | ||||||
248 | g_main_context_ref(mainContext); | - | ||||||
249 | } else { | - | ||||||
250 | QCoreApplication *app = QCoreApplication::instance(); | - | ||||||
251 | if (app && QThread::currentThread() == app->thread()) { | - | ||||||
252 | mainContext = g_main_context_default(); | - | ||||||
253 | g_main_context_ref(mainContext); | - | ||||||
254 | } else { | - | ||||||
255 | mainContext = g_main_context_new(); | - | ||||||
256 | } | - | ||||||
257 | } | - | ||||||
258 | - | |||||||
259 | - | |||||||
260 | g_main_context_push_thread_default (mainContext); | - | ||||||
261 | - | |||||||
262 | - | |||||||
263 | - | |||||||
264 | postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs, | - | ||||||
265 | sizeof(GPostEventSource))); | - | ||||||
266 | postEventSource->serialNumber.store(1); | - | ||||||
267 | postEventSource->d = this; | - | ||||||
268 | g_source_set_can_recurse(&postEventSource->source, true); | - | ||||||
269 | g_source_attach(&postEventSource->source, mainContext); | - | ||||||
270 | - | |||||||
271 | - | |||||||
272 | socketNotifierSource = | - | ||||||
273 | reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs, | - | ||||||
274 | sizeof(GSocketNotifierSource))); | - | ||||||
275 | (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>(); | - | ||||||
276 | g_source_set_can_recurse(&socketNotifierSource->source, true); | - | ||||||
277 | g_source_attach(&socketNotifierSource->source, mainContext); | - | ||||||
278 | - | |||||||
279 | - | |||||||
280 | timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs, | - | ||||||
281 | sizeof(GTimerSource))); | - | ||||||
282 | (void) new (&timerSource->timerList) QTimerInfoList(); | - | ||||||
283 | timerSource->processEventsFlags = QEventLoop::AllEvents; | - | ||||||
284 | timerSource->runWithIdlePriority = false; | - | ||||||
285 | g_source_set_can_recurse(&timerSource->source, true); | - | ||||||
286 | g_source_attach(&timerSource->source, mainContext); | - | ||||||
287 | - | |||||||
288 | idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs, | - | ||||||
289 | sizeof(GIdleTimerSource))); | - | ||||||
290 | idleTimerSource->timerSource = timerSource; | - | ||||||
291 | g_source_set_can_recurse(&idleTimerSource->source, true); | - | ||||||
292 | g_source_set_priority(&idleTimerSource->source, 200); | - | ||||||
293 | g_source_attach(&idleTimerSource->source, mainContext); | - | ||||||
294 | } | - | ||||||
295 | - | |||||||
296 | void QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority() | - | ||||||
297 | { | - | ||||||
298 | timerSource->runWithIdlePriority = false; | - | ||||||
299 | } | - | ||||||
300 | - | |||||||
301 | QEventDispatcherGlib::QEventDispatcherGlib(QObject *parent) | - | ||||||
302 | : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate), parent) | - | ||||||
303 | { | - | ||||||
304 | } | - | ||||||
305 | - | |||||||
306 | QEventDispatcherGlib::QEventDispatcherGlib(GMainContext *mainContext, QObject *parent) | - | ||||||
307 | : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate(mainContext)), parent) | - | ||||||
308 | { } | - | ||||||
309 | - | |||||||
310 | QEventDispatcherGlib::~QEventDispatcherGlib() | - | ||||||
311 | { | - | ||||||
312 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
313 | - | |||||||
314 | - | |||||||
315 | qDeleteAll(d->timerSource->timerList); | - | ||||||
316 | d->timerSource->timerList.~QTimerInfoList(); | - | ||||||
317 | g_source_destroy(&d->timerSource->source); | - | ||||||
318 | g_source_unref(&d->timerSource->source); | - | ||||||
319 | d->timerSource = 0; | - | ||||||
320 | g_source_destroy(&d->idleTimerSource->source); | - | ||||||
321 | g_source_unref(&d->idleTimerSource->source); | - | ||||||
322 | d->idleTimerSource = 0; | - | ||||||
323 | - | |||||||
324 | - | |||||||
325 | for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) { | - | ||||||
326 | GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds[i]; | - | ||||||
327 | g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd); | - | ||||||
328 | delete p; | - | ||||||
329 | } | - | ||||||
330 | d->socketNotifierSource->pollfds.~QList<GPollFDWithQSocketNotifier *>(); | - | ||||||
331 | g_source_destroy(&d->socketNotifierSource->source); | - | ||||||
332 | g_source_unref(&d->socketNotifierSource->source); | - | ||||||
333 | d->socketNotifierSource = 0; | - | ||||||
334 | - | |||||||
335 | - | |||||||
336 | g_source_destroy(&d->postEventSource->source); | - | ||||||
337 | g_source_unref(&d->postEventSource->source); | - | ||||||
338 | d->postEventSource = 0; | - | ||||||
339 | - | |||||||
340 | ((!(d->mainContext != 0)) ? qt_assert("d->mainContext != 0",__FILE__,390396) : qt_noop()); | - | ||||||
341 | - | |||||||
342 | g_main_context_pop_thread_default (d->mainContext); | - | ||||||
343 | - | |||||||
344 | g_main_context_unref(d->mainContext); | - | ||||||
345 | d->mainContext = 0; | - | ||||||
346 | } | - | ||||||
347 | - | |||||||
348 | bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags) | - | ||||||
349 | { | - | ||||||
350 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
351 | - | |||||||
352 | const bool canWait = (flags & QEventLoop::WaitForMoreEvents); | - | ||||||
353 | if (canWait) | - | ||||||
354 | aboutToBlock(); | - | ||||||
355 | else | - | ||||||
356 | awake(); | - | ||||||
357 | - | |||||||
358 | - | |||||||
359 | QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags; | - | ||||||
360 | d->timerSource->processEventsFlags = flags; | - | ||||||
361 | - | |||||||
362 | if (!(flags & QEventLoop::EventLoopExec)) { | - | ||||||
363 | - | |||||||
364 | d->timerSource->runWithIdlePriority = false; | - | ||||||
365 | } | - | ||||||
366 | - | |||||||
367 | bool result = g_main_context_iteration(d->mainContext, canWait); | - | ||||||
368 | while (!result && canWait) | - | ||||||
369 | result = g_main_context_iteration(d->mainContext, canWait); | - | ||||||
370 | - | |||||||
371 | d->timerSource->processEventsFlags = savedFlags; | - | ||||||
372 | - | |||||||
373 | if (canWait) | - | ||||||
374 | awake(); | - | ||||||
375 | - | |||||||
376 | return result; | - | ||||||
377 | } | - | ||||||
378 | - | |||||||
379 | bool QEventDispatcherGlib::hasPendingEvents() | - | ||||||
380 | { | - | ||||||
381 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
382 | return g_main_context_pending(d->mainContext); | - | ||||||
383 | } | - | ||||||
384 | - | |||||||
385 | void QEventDispatcherGlib::registerSocketNotifier(QSocketNotifier *notifier) | - | ||||||
386 | { | - | ||||||
387 | ((!(notifier)) ? qt_assert("notifier",__FILE__,437443) : qt_noop()); | - | ||||||
388 | int sockfd = notifier->socket(); | - | ||||||
389 | int type = notifier->type(); | - | ||||||
390 | - | |||||||
391 | if (sockfd < 0) { | - | ||||||
392 | QMessageLogger(__FILE__, 442448, __PRETTY_FUNCTION__).warning("QSocketNotifier: Internal error"); | - | ||||||
393 | return; | - | ||||||
394 | } else if (notifier->thread() != thread() | - | ||||||
395 | || thread() != QThread::currentThread()) { | - | ||||||
396 | QMessageLogger(__FILE__, 446452, __PRETTY_FUNCTION__).warning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); | - | ||||||
397 | return; | - | ||||||
398 | } | - | ||||||
399 | - | |||||||
400 | - | |||||||
401 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
402 | - | |||||||
403 | - | |||||||
404 | GPollFDWithQSocketNotifier *p = new GPollFDWithQSocketNotifier; | - | ||||||
405 | p->pollfd.fd = sockfd; | - | ||||||
406 | switch (type) { | - | ||||||
407 | case QSocketNotifier::Read: | - | ||||||
408 | p->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; | - | ||||||
409 | break; | - | ||||||
410 | case QSocketNotifier::Write: | - | ||||||
411 | p->pollfd.events = G_IO_OUT | G_IO_ERR; | - | ||||||
412 | break; | - | ||||||
413 | case QSocketNotifier::Exception: | - | ||||||
414 | p->pollfd.events = G_IO_PRI | G_IO_ERR; | - | ||||||
415 | break; | - | ||||||
416 | } | - | ||||||
417 | p->socketNotifier = notifier; | - | ||||||
418 | - | |||||||
419 | d->socketNotifierSource->pollfds.append(p); | - | ||||||
420 | - | |||||||
421 | g_source_add_poll(&d->socketNotifierSource->source, &p->pollfd); | - | ||||||
422 | } | - | ||||||
423 | - | |||||||
424 | void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier) | - | ||||||
425 | { | - | ||||||
426 | ((!(notifier)) ? qt_assert("notifier",__FILE__,476482) : qt_noop()); | - | ||||||
427 | - | |||||||
428 | int sockfd = notifier->socket(); | - | ||||||
429 | if (sockfd < 0) { | - | ||||||
430 | QMessageLogger(__FILE__, 480486, __PRETTY_FUNCTION__).warning("QSocketNotifier: Internal error"); | - | ||||||
431 | return; | - | ||||||
432 | } else if (notifier->thread() != thread() | - | ||||||
433 | || thread() != QThread::currentThread()) { | - | ||||||
434 | QMessageLogger(__FILE__, 484490, __PRETTY_FUNCTION__).warning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); | - | ||||||
435 | return; | - | ||||||
436 | } | - | ||||||
437 | - | |||||||
438 | - | |||||||
439 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
440 | - | |||||||
441 | for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) { | - | ||||||
442 | GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i); | - | ||||||
443 | if (p->socketNotifier == notifier) { | - | ||||||
444 | - | |||||||
445 | g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd); | - | ||||||
446 | - | |||||||
447 | d->socketNotifierSource->pollfds.removeAt(i); | - | ||||||
448 | delete p; | - | ||||||
449 | - | |||||||
450 | return; | - | ||||||
451 | } | - | ||||||
452 | } | - | ||||||
453 | } | - | ||||||
454 | - | |||||||
455 | void QEventDispatcherGlib::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object) | - | ||||||
456 | { | - | ||||||
457 | - | |||||||
458 | if (timerId < 1 || interval < 0 || !object) { | - | ||||||
459 | QMessageLogger(__FILE__, 509515, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::registerTimer: invalid arguments"); | - | ||||||
460 | return; | - | ||||||
461 | } else if (object->thread() != thread() || thread() != QThread::currentThread()) { | - | ||||||
462 | QMessageLogger(__FILE__, 512518, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::registerTimer: timers cannot be started from another thread"); | - | ||||||
463 | return; | - | ||||||
464 | } | - | ||||||
465 | - | |||||||
466 | - | |||||||
467 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
468 | d->timerSource->timerList.registerTimer(timerId, interval, timerType, object); | - | ||||||
469 | } | - | ||||||
470 | - | |||||||
471 | bool QEventDispatcherGlib::unregisterTimer(int timerId) | - | ||||||
472 | { | - | ||||||
473 | - | |||||||
474 | if (timerId < 1) { | - | ||||||
475 | QMessageLogger(__FILE__, 525531, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::unregisterTimer: invalid argument"); | - | ||||||
476 | return false; | - | ||||||
477 | } else if (thread() != QThread::currentThread()) { | - | ||||||
478 | QMessageLogger(__FILE__, 528534, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::unregisterTimer: timers cannot be stopped from another thread"); | - | ||||||
479 | return false; | - | ||||||
480 | } | - | ||||||
481 | - | |||||||
482 | - | |||||||
483 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
484 | return d->timerSource->timerList.unregisterTimer(timerId); | - | ||||||
485 | } | - | ||||||
486 | - | |||||||
487 | bool QEventDispatcherGlib::unregisterTimers(QObject *object) | - | ||||||
488 | { | - | ||||||
489 | - | |||||||
490 | if (!object) { | - | ||||||
491 | QMessageLogger(__FILE__, 541547, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::unregisterTimers: invalid argument"); | - | ||||||
492 | return false; | - | ||||||
493 | } else if (object->thread() != thread() || thread() != QThread::currentThread()) { | - | ||||||
494 | QMessageLogger(__FILE__, 544550, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::unregisterTimers: timers cannot be stopped from another thread"); | - | ||||||
495 | return false; | - | ||||||
496 | } | - | ||||||
497 | - | |||||||
498 | - | |||||||
499 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
500 | return d->timerSource->timerList.unregisterTimers(object); | - | ||||||
501 | } | - | ||||||
502 | - | |||||||
503 | QList<QEventDispatcherGlib::TimerInfo> QEventDispatcherGlib::registeredTimers(QObject *object) const | - | ||||||
504 | { | - | ||||||
505 | if (!object) { | - | ||||||
506 | QMessageLogger(__FILE__, 556562, __PRETTY_FUNCTION__).warning("QEventDispatcherUNIX:registeredTimers: invalid argument"); | - | ||||||
507 | return QList<TimerInfo>(); | - | ||||||
508 | } | - | ||||||
509 | - | |||||||
510 | const QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
511 | return d->timerSource->timerList.registeredTimers(object); | - | ||||||
512 | } | - | ||||||
513 | - | |||||||
514 | int QEventDispatcherGlib::remainingTime(int timerId) | - | ||||||
515 | { | - | ||||||
516 | - | |||||||
517 | if (timerId < 1) { | - | ||||||
518 | QMessageLogger(__FILE__, 568574, __PRETTY_FUNCTION__).warning("QEventDispatcherGlib::remainingTimeTime: invalid argument"); | - | ||||||
519 | return -1; | - | ||||||
520 | } | - | ||||||
521 | - | |||||||
522 | - | |||||||
523 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
524 | return d->timerSource->timerList.timerRemainingTime(timerId); | - | ||||||
525 | } | - | ||||||
526 | - | |||||||
527 | void QEventDispatcherGlib::interrupt() | - | ||||||
528 | { | - | ||||||
529 | wakeUp(); | - | ||||||
530 | } | - | ||||||
531 | - | |||||||
532 | void QEventDispatcherGlib::wakeUp() | - | ||||||
533 | { | - | ||||||
534 | QEventDispatcherGlibPrivate * const d = d_func(); | - | ||||||
535 | d->postEventSource->serialNumber.ref(); | - | ||||||
536 | g_main_context_wakeup(d->mainContext); | - | ||||||
537 | } | - | ||||||
538 | - | |||||||
539 | void QEventDispatcherGlib::flush() | - | ||||||
540 | { | - | ||||||
541 | } | - | ||||||
542 | - | |||||||
543 | bool QEventDispatcherGlib::versionSupported() | - | ||||||
544 | { | - | ||||||
545 | - | |||||||
546 | - | |||||||
547 | - | |||||||
548 | return ((2 << 16) + (42 << 8) + 1) >= 0x020301; | - | ||||||
549 | - | |||||||
550 | } | - | ||||||
551 | - | |||||||
552 | QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObject *parent) | - | ||||||
553 | : QAbstractEventDispatcher(dd, parent) | - | ||||||
554 | { | - | ||||||
555 | } | - | ||||||
556 | - | |||||||
557 | - | |||||||
Switch to Source code | Preprocessed file |