qeventdispatcher_glib.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qeventdispatcher_glib.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qeventdispatcher_glib_p.h"-
41#include "qeventdispatcher_unix_p.h"-
42-
43#include <private/qthread_p.h>-
44-
45#include "qcoreapplication.h"-
46#include "qsocketnotifier.h"-
47-
48#include <QtCore/qlist.h>-
49#include <QtCore/qpair.h>-
50-
51#include <glib.h>-
52-
53QT_BEGIN_NAMESPACE-
54-
55struct GPollFDWithQSocketNotifier-
56{-
57 GPollFD pollfd;-
58 QSocketNotifier *socketNotifier;-
59};-
60-
61struct GSocketNotifierSource-
62{-
63 GSource source;-
64 QList<GPollFDWithQSocketNotifier *> pollfds;-
65};-
66-
67static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout)-
68{-
69 if (timeout)-
70 *timeout = -1;-
71 return false;-
72}-
73-
74static gboolean socketNotifierSourceCheck(GSource *source)-
75{-
76 GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);-
77-
78 bool pending = false;-
79 for (int i = 0; !pending && i < src->pollfds.count(); ++i) {-
80 GPollFDWithQSocketNotifier *p = src->pollfds.at(i);-
81-
82 if (p->pollfd.revents & G_IO_NVAL) {-
83 // disable the invalid socket notifier-
84 static const char *t[] = { "Read", "Write", "Exception" };-
85 qWarning("QSocketNotifier: Invalid socket %d and type '%s', disabling...",-
86 p->pollfd.fd, t[int(p->socketNotifier->type())]);-
87 // ### note, modifies src->pollfds!-
88 p->socketNotifier->setEnabled(false);-
89 }-
90-
91 pending = ((p->pollfd.revents & p->pollfd.events) != 0);-
92 }-
93-
94 return pending;-
95}-
96-
97static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer)-
98{-
99 QEvent event(QEvent::SockAct);-
100-
101 GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);-
102 for (int i = 0; i < src->pollfds.count(); ++i) {-
103 GPollFDWithQSocketNotifier *p = src->pollfds.at(i);-
104-
105 if ((p->pollfd.revents & p->pollfd.events) != 0)-
106 QCoreApplication::sendEvent(p->socketNotifier, &event);-
107 }-
108-
109 return true; // ??? don't remove, right?-
110}-
111-
112static GSourceFuncs socketNotifierSourceFuncs = {-
113 socketNotifierSourcePrepare,-
114 socketNotifierSourceCheck,-
115 socketNotifierSourceDispatch,-
116 NULL,-
117 NULL,-
118 NULL-
119};-
120-
121struct GTimerSource-
122{-
123 GSource source;-
124 QTimerInfoList timerList;-
125 QEventLoop::ProcessEventsFlags processEventsFlags;-
126 bool runWithIdlePriority;-
127};-
128-
129static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout)-
130{-
131 timespec tv = { 0l, 0l };-
132 if (!(src->processEventsFlags & QEventLoop::X11ExcludeTimers) && src->timerList.timerWait(tv))-
133 *timeout = (tv.tv_sec * 1000) + ((tv.tv_nsec + 999999) / 1000 / 1000);-
134 else-
135 *timeout = -1;-
136-
137 return (*timeout == 0);-
138}-
139-
140static gboolean timerSourceCheckHelper(GTimerSource *src)-
141{-
142 if (src->timerList.isEmpty()
src->timerList.isEmpty()Description
TRUEevaluated 3126615 times by 362 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractAnimation
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • ...
FALSEevaluated 287220 times by 208 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractAnimation
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBuffer
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • ...
287220-3126615
143 || (src->processEventsFlags & QEventLoop::X11ExcludeTimers))-
144 return false;
executed 3126617 times by 362 tests: return false;
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractAnimation
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • ...
3126617
145-
146 if (src->timerList.updateCurrentTime() < src->timerList.firstconstFirst()->timeout)
src->timerList...rst()->timeoutDescription
TRUEevaluated 284855 times by 208 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractAnimation
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBuffer
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • ...
FALSEevaluated 2363 times by 53 tests
Evaluated by:
  • tst_QAbstractScrollArea
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QColorDialog
  • tst_QCommandLinkButton
  • tst_QCoreApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusMarshall
  • tst_QDialog
  • tst_QEventLoop
  • tst_QFileDialog2
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFontDialog
  • tst_QFtp
  • tst_QGraphicsScene
  • tst_QGuiApplication
  • tst_QGuiEventLoop
  • tst_QHostInfo
  • tst_QItemDelegate
  • tst_QKeySequenceEdit
  • tst_QMenu
  • tst_QMessageBox
  • tst_QMovie
  • tst_QNetworkAccessManager_And_QProgressDialog
  • ...
2363-284855
147 return false;
executed 284855 times by 208 tests: return false;
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractAnimation
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBuffer
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • ...
284855
148-
149 return true;
executed 2363 times by 53 tests: return true;
Executed by:
  • tst_QAbstractScrollArea
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QColorDialog
  • tst_QCommandLinkButton
  • tst_QCoreApplication
  • tst_QDBusAbstractInterface
  • tst_QDBusMarshall
  • tst_QDialog
  • tst_QEventLoop
  • tst_QFileDialog2
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFontDialog
  • tst_QFtp
  • tst_QGraphicsScene
  • tst_QGuiApplication
  • tst_QGuiEventLoop
  • tst_QHostInfo
  • tst_QItemDelegate
  • tst_QKeySequenceEdit
  • tst_QMenu
  • tst_QMessageBox
  • tst_QMovie
  • tst_QNetworkAccessManager_And_QProgressDialog
  • ...
2363
150}-
151-
152static gboolean timerSourcePrepare(GSource *source, gint *timeout)-
153{-
154 gint dummy;-
155 if (!timeout)-
156 timeout = &dummy;-
157-
158 GTimerSource *src = reinterpret_cast<GTimerSource *>(source);-
159 if (src->runWithIdlePriority) {-
160 if (timeout)-
161 *timeout = -1;-
162 return false;-
163 }-
164-
165 return timerSourcePrepareHelper(src, timeout);-
166}-
167-
168static gboolean timerSourceCheck(GSource *source)-
169{-
170 GTimerSource *src = reinterpret_cast<GTimerSource *>(source);-
171 if (src->runWithIdlePriority)-
172 return false;-
173 return timerSourceCheckHelper(src);-
174}-
175-
176static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer)-
177{-
178 GTimerSource *timerSource = reinterpret_cast<GTimerSource *>(source);-
179 if (timerSource->processEventsFlags & QEventLoop::X11ExcludeTimers)-
180 return true;-
181 timerSource->runWithIdlePriority = true;-
182 (void) timerSource->timerList.activateTimers();-
183 return true; // ??? don't remove, right again?-
184}-
185-
186static GSourceFuncs timerSourceFuncs = {-
187 timerSourcePrepare,-
188 timerSourceCheck,-
189 timerSourceDispatch,-
190 NULL,-
191 NULL,-
192 NULL-
193};-
194-
195struct GIdleTimerSource-
196{-
197 GSource source;-
198 GTimerSource *timerSource;-
199};-
200-
201static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout)-
202{-
203 GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);-
204 GTimerSource *timerSource = idleTimerSource->timerSource;-
205 if (!timerSource->runWithIdlePriority) {-
206 // Yield to the normal priority timer source-
207 if (timeout)-
208 *timeout = -1;-
209 return false;-
210 }-
211-
212 return timerSourcePrepareHelper(timerSource, timeout);-
213}-
214-
215static gboolean idleTimerSourceCheck(GSource *source)-
216{-
217 GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);-
218 GTimerSource *timerSource = idleTimerSource->timerSource;-
219 if (!timerSource->runWithIdlePriority) {-
220 // Yield to the normal priority timer source-
221 return false;-
222 }-
223 return timerSourceCheckHelper(timerSource);-
224}-
225-
226static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer)-
227{-
228 GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource;-
229 (void) timerSourceDispatch(&timerSource->source, 0, 0);-
230 return true;-
231}-
232-
233static GSourceFuncs idleTimerSourceFuncs = {-
234 idleTimerSourcePrepare,-
235 idleTimerSourceCheck,-
236 idleTimerSourceDispatch,-
237 NULL,-
238 NULL,-
239 NULL-
240};-
241-
242struct GPostEventSource-
243{-
244 GSource source;-
245 QAtomicInt serialNumber;-
246 int lastSerialNumber;-
247 QEventDispatcherGlibPrivate *d;-
248};-
249-
250static gboolean postEventSourcePrepare(GSource *s, gint *timeout)-
251{-
252 QThreadData *data = QThreadData::current();-
253 if (!data)-
254 return false;-
255-
256 gint dummy;-
257 if (!timeout)-
258 timeout = &dummy;-
259 const bool canWait = data->canWaitLocked();-
260 *timeout = canWait ? -1 : 0;-
261-
262 GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);-
263 return (!canWait-
264 || (source->serialNumber.load() != source->lastSerialNumber));-
265}-
266-
267static gboolean postEventSourceCheck(GSource *source)-
268{-
269 return postEventSourcePrepare(source, 0);-
270}-
271-
272static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer)-
273{-
274 GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);-
275 source->lastSerialNumber = source->serialNumber.load();-
276 QCoreApplication::sendPostedEvents();-
277 source->d->runTimersOnceWithNormalPriority();-
278 return true; // i dunno, george...-
279}-
280-
281static GSourceFuncs postEventSourceFuncs = {-
282 postEventSourcePrepare,-
283 postEventSourceCheck,-
284 postEventSourceDispatch,-
285 NULL,-
286 NULL,-
287 NULL-
288};-
289-
290-
291QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context)-
292 : mainContext(context)-
293{-
294#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32-
295 if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) {-
296 static QBasicMutex mutex;-
297 QMutexLocker locker(&mutex);-
298 if (!g_thread_supported())-
299 g_thread_init(NULL);-
300 }-
301#endif-
302-
303 if (mainContext) {-
304 g_main_context_ref(mainContext);-
305 } else {-
306 QCoreApplication *app = QCoreApplication::instance();-
307 if (app && QThread::currentThread() == app->thread()) {-
308 mainContext = g_main_context_default();-
309 g_main_context_ref(mainContext);-
310 } else {-
311 mainContext = g_main_context_new();-
312 }-
313 }-
314-
315#if GLIB_CHECK_VERSION (2, 22, 0)-
316 g_main_context_push_thread_default (mainContext);-
317#endif-
318-
319 // setup post event source-
320 postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs,-
321 sizeof(GPostEventSource)));-
322 postEventSource->serialNumber.store(1);-
323 postEventSource->d = this;-
324 g_source_set_can_recurse(&postEventSource->source, true);-
325 g_source_attach(&postEventSource->source, mainContext);-
326-
327 // setup socketNotifierSource-
328 socketNotifierSource =-
329 reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs,-
330 sizeof(GSocketNotifierSource)));-
331 (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>();-
332 g_source_set_can_recurse(&socketNotifierSource->source, true);-
333 g_source_attach(&socketNotifierSource->source, mainContext);-
334-
335 // setup normal and idle timer sources-
336 timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs,-
337 sizeof(GTimerSource)));-
338 (void) new (&timerSource->timerList) QTimerInfoList();-
339 timerSource->processEventsFlags = QEventLoop::AllEvents;-
340 timerSource->runWithIdlePriority = false;-
341 g_source_set_can_recurse(&timerSource->source, true);-
342 g_source_attach(&timerSource->source, mainContext);-
343-
344 idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs,-
345 sizeof(GIdleTimerSource)));-
346 idleTimerSource->timerSource = timerSource;-
347 g_source_set_can_recurse(&idleTimerSource->source, true);-
348 g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE);-
349 g_source_attach(&idleTimerSource->source, mainContext);-
350}-
351-
352void QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority()-
353{-
354 timerSource->runWithIdlePriority = false;-
355}-
356-
357QEventDispatcherGlib::QEventDispatcherGlib(QObject *parent)-
358 : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate), parent)-
359{-
360}-
361-
362QEventDispatcherGlib::QEventDispatcherGlib(GMainContext *mainContext, QObject *parent)-
363 : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate(mainContext)), parent)-
364{ }-
365-
366QEventDispatcherGlib::~QEventDispatcherGlib()-
367{-
368 Q_D(QEventDispatcherGlib);-
369-
370 // destroy all timer sources-
371 qDeleteAll(d->timerSource->timerList);-
372 d->timerSource->timerList.~QTimerInfoList();-
373 g_source_destroy(&d->timerSource->source);-
374 g_source_unref(&d->timerSource->source);-
375 d->timerSource = 0;-
376 g_source_destroy(&d->idleTimerSource->source);-
377 g_source_unref(&d->idleTimerSource->source);-
378 d->idleTimerSource = 0;-
379-
380 // destroy socket notifier source-
381 for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) {-
382 GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds[i];-
383 g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);-
384 delete p;-
385 }-
386 d->socketNotifierSource->pollfds.~QList<GPollFDWithQSocketNotifier *>();-
387 g_source_destroy(&d->socketNotifierSource->source);-
388 g_source_unref(&d->socketNotifierSource->source);-
389 d->socketNotifierSource = 0;-
390-
391 // destroy post event source-
392 g_source_destroy(&d->postEventSource->source);-
393 g_source_unref(&d->postEventSource->source);-
394 d->postEventSource = 0;-
395-
396 Q_ASSERT(d->mainContext != 0);-
397#if GLIB_CHECK_VERSION (2, 22, 0)-
398 g_main_context_pop_thread_default (d->mainContext);-
399#endif-
400 g_main_context_unref(d->mainContext);-
401 d->mainContext = 0;-
402}-
403-
404bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)-
405{-
406 Q_D(QEventDispatcherGlib);-
407-
408 const bool canWait = (flags & QEventLoop::WaitForMoreEvents);-
409 if (canWait)-
410 emit aboutToBlock();-
411 else-
412 emit awake();-
413-
414 // tell postEventSourcePrepare() and timerSource about any new flags-
415 QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags;-
416 d->timerSource->processEventsFlags = flags;-
417-
418 if (!(flags & QEventLoop::EventLoopExec)) {-
419 // force timers to be sent at normal priority-
420 d->timerSource->runWithIdlePriority = false;-
421 }-
422-
423 bool result = g_main_context_iteration(d->mainContext, canWait);-
424 while (!result && canWait)-
425 result = g_main_context_iteration(d->mainContext, canWait);-
426-
427 d->timerSource->processEventsFlags = savedFlags;-
428-
429 if (canWait)-
430 emit awake();-
431-
432 return result;-
433}-
434-
435bool QEventDispatcherGlib::hasPendingEvents()-
436{-
437 Q_D(QEventDispatcherGlib);-
438 return g_main_context_pending(d->mainContext);-
439}-
440-
441void QEventDispatcherGlib::registerSocketNotifier(QSocketNotifier *notifier)-
442{-
443 Q_ASSERT(notifier);-
444 int sockfd = notifier->socket();-
445 int type = notifier->type();-
446#ifndef QT_NO_DEBUG-
447 if (sockfd < 0) {-
448 qWarning("QSocketNotifier: Internal error");-
449 return;-
450 } else if (notifier->thread() != thread()-
451 || thread() != QThread::currentThread()) {-
452 qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread");-
453 return;-
454 }-
455#endif-
456-
457 Q_D(QEventDispatcherGlib);-
458-
459-
460 GPollFDWithQSocketNotifier *p = new GPollFDWithQSocketNotifier;-
461 p->pollfd.fd = sockfd;-
462 switch (type) {-
463 case QSocketNotifier::Read:-
464 p->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;-
465 break;-
466 case QSocketNotifier::Write:-
467 p->pollfd.events = G_IO_OUT | G_IO_ERR;-
468 break;-
469 case QSocketNotifier::Exception:-
470 p->pollfd.events = G_IO_PRI | G_IO_ERR;-
471 break;-
472 }-
473 p->socketNotifier = notifier;-
474-
475 d->socketNotifierSource->pollfds.append(p);-
476-
477 g_source_add_poll(&d->socketNotifierSource->source, &p->pollfd);-
478}-
479-
480void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier)-
481{-
482 Q_ASSERT(notifier);-
483#ifndef QT_NO_DEBUG-
484 int sockfd = notifier->socket();-
485 if (sockfd < 0) {-
486 qWarning("QSocketNotifier: Internal error");-
487 return;-
488 } else if (notifier->thread() != thread()-
489 || thread() != QThread::currentThread()) {-
490 qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread");-
491 return;-
492 }-
493#endif-
494-
495 Q_D(QEventDispatcherGlib);-
496-
497 for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) {-
498 GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i);-
499 if (p->socketNotifier == notifier) {-
500 // found it-
501 g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);-
502-
503 d->socketNotifierSource->pollfds.removeAt(i);-
504 delete p;-
505-
506 return;-
507 }-
508 }-
509}-
510-
511void QEventDispatcherGlib::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object)-
512{-
513#ifndef QT_NO_DEBUG-
514 if (timerId < 1 || interval < 0 || !object) {-
515 qWarning("QEventDispatcherGlib::registerTimer: invalid arguments");-
516 return;-
517 } else if (object->thread() != thread() || thread() != QThread::currentThread()) {-
518 qWarning("QEventDispatcherGlib::registerTimer: timers cannot be started from another thread");-
519 return;-
520 }-
521#endif-
522-
523 Q_D(QEventDispatcherGlib);-
524 d->timerSource->timerList.registerTimer(timerId, interval, timerType, object);-
525}-
526-
527bool QEventDispatcherGlib::unregisterTimer(int timerId)-
528{-
529#ifndef QT_NO_DEBUG-
530 if (timerId < 1) {-
531 qWarning("QEventDispatcherGlib::unregisterTimer: invalid argument");-
532 return false;-
533 } else if (thread() != QThread::currentThread()) {-
534 qWarning("QEventDispatcherGlib::unregisterTimer: timers cannot be stopped from another thread");-
535 return false;-
536 }-
537#endif-
538-
539 Q_D(QEventDispatcherGlib);-
540 return d->timerSource->timerList.unregisterTimer(timerId);-
541}-
542-
543bool QEventDispatcherGlib::unregisterTimers(QObject *object)-
544{-
545#ifndef QT_NO_DEBUG-
546 if (!object) {-
547 qWarning("QEventDispatcherGlib::unregisterTimers: invalid argument");-
548 return false;-
549 } else if (object->thread() != thread() || thread() != QThread::currentThread()) {-
550 qWarning("QEventDispatcherGlib::unregisterTimers: timers cannot be stopped from another thread");-
551 return false;-
552 }-
553#endif-
554-
555 Q_D(QEventDispatcherGlib);-
556 return d->timerSource->timerList.unregisterTimers(object);-
557}-
558-
559QList<QEventDispatcherGlib::TimerInfo> QEventDispatcherGlib::registeredTimers(QObject *object) const-
560{-
561 if (!object) {-
562 qWarning("QEventDispatcherUNIX:registeredTimers: invalid argument");-
563 return QList<TimerInfo>();-
564 }-
565-
566 Q_D(const QEventDispatcherGlib);-
567 return d->timerSource->timerList.registeredTimers(object);-
568}-
569-
570int QEventDispatcherGlib::remainingTime(int timerId)-
571{-
572#ifndef QT_NO_DEBUG-
573 if (timerId < 1) {-
574 qWarning("QEventDispatcherGlib::remainingTimeTime: invalid argument");-
575 return -1;-
576 }-
577#endif-
578-
579 Q_D(QEventDispatcherGlib);-
580 return d->timerSource->timerList.timerRemainingTime(timerId);-
581}-
582-
583void QEventDispatcherGlib::interrupt()-
584{-
585 wakeUp();-
586}-
587-
588void QEventDispatcherGlib::wakeUp()-
589{-
590 Q_D(QEventDispatcherGlib);-
591 d->postEventSource->serialNumber.ref();-
592 g_main_context_wakeup(d->mainContext);-
593}-
594-
595void QEventDispatcherGlib::flush()-
596{-
597}-
598-
599bool QEventDispatcherGlib::versionSupported()-
600{-
601#if !defined(GLIB_MAJOR_VERSION) || !defined(GLIB_MINOR_VERSION) || !defined(GLIB_MICRO_VERSION)-
602 return false;-
603#else-
604 return ((GLIB_MAJOR_VERSION << 16) + (GLIB_MINOR_VERSION << 8) + GLIB_MICRO_VERSION) >= 0x020301;-
605#endif-
606}-
607-
608QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObject *parent)-
609 : QAbstractEventDispatcher(dd, parent)-
610{-
611}-
612-
613QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9