author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qeventdispatcher_glib_p.h" |
|
43 |
#include "qeventdispatcher_unix_p.h" |
|
44 |
||
45 |
#include <private/qmutexpool_p.h> |
|
46 |
#include <private/qthread_p.h> |
|
47 |
||
48 |
#include "qcoreapplication.h" |
|
49 |
#include "qsocketnotifier.h" |
|
50 |
||
51 |
#include <QtCore/qhash.h> |
|
52 |
#include <QtCore/qlist.h> |
|
53 |
#include <QtCore/qpair.h> |
|
54 |
||
55 |
#include <glib.h> |
|
56 |
||
57 |
QT_BEGIN_NAMESPACE |
|
58 |
||
59 |
struct GPollFDWithQSocketNotifier |
|
60 |
{ |
|
61 |
GPollFD pollfd; |
|
62 |
QSocketNotifier *socketNotifier; |
|
63 |
}; |
|
64 |
||
65 |
struct GSocketNotifierSource |
|
66 |
{ |
|
67 |
GSource source; |
|
68 |
QList<GPollFDWithQSocketNotifier *> pollfds; |
|
69 |
}; |
|
70 |
||
71 |
static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout) |
|
72 |
{ |
|
73 |
if (timeout) |
|
74 |
*timeout = -1; |
|
75 |
return false; |
|
76 |
} |
|
77 |
||
78 |
static gboolean socketNotifierSourceCheck(GSource *source) |
|
79 |
{ |
|
80 |
GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source); |
|
81 |
||
82 |
bool pending = false; |
|
83 |
for (int i = 0; !pending && i < src->pollfds.count(); ++i) { |
|
84 |
GPollFDWithQSocketNotifier *p = src->pollfds.at(i); |
|
85 |
||
86 |
if (p->pollfd.revents & G_IO_NVAL) { |
|
87 |
// disable the invalid socket notifier |
|
88 |
static const char *t[] = { "Read", "Write", "Exception" }; |
|
89 |
qWarning("QSocketNotifier: Invalid socket %d and type '%s', disabling...", |
|
90 |
p->pollfd.fd, t[int(p->socketNotifier->type())]); |
|
91 |
// ### note, modifies src->pollfds! |
|
92 |
p->socketNotifier->setEnabled(false); |
|
93 |
} |
|
94 |
||
95 |
pending = ((p->pollfd.revents & p->pollfd.events) != 0); |
|
96 |
} |
|
97 |
||
98 |
return pending; |
|
99 |
} |
|
100 |
||
101 |
static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer) |
|
102 |
{ |
|
103 |
QEvent event(QEvent::SockAct); |
|
104 |
||
105 |
GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source); |
|
106 |
for (int i = 0; i < src->pollfds.count(); ++i) { |
|
107 |
GPollFDWithQSocketNotifier *p = src->pollfds.at(i); |
|
108 |
||
109 |
if ((p->pollfd.revents & p->pollfd.events) != 0) |
|
110 |
QCoreApplication::sendEvent(p->socketNotifier, &event); |
|
111 |
} |
|
112 |
||
113 |
return true; // ??? don't remove, right? |
|
114 |
} |
|
115 |
||
116 |
static GSourceFuncs socketNotifierSourceFuncs = { |
|
117 |
socketNotifierSourcePrepare, |
|
118 |
socketNotifierSourceCheck, |
|
119 |
socketNotifierSourceDispatch, |
|
120 |
NULL, |
|
121 |
NULL, |
|
122 |
NULL |
|
123 |
}; |
|
124 |
||
125 |
struct GTimerSource |
|
126 |
{ |
|
127 |
GSource source; |
|
128 |
QTimerInfoList timerList; |
|
129 |
QEventLoop::ProcessEventsFlags processEventsFlags; |
|
130 |
bool runWithIdlePriority; |
|
131 |
}; |
|
132 |
||
133 |
static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout) |
|
134 |
{ |
|
135 |
timeval tv = { 0l, 0l }; |
|
136 |
if (!(src->processEventsFlags & QEventLoop::X11ExcludeTimers) && src->timerList.timerWait(tv)) |
|
137 |
*timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); |
|
138 |
else |
|
139 |
*timeout = -1; |
|
140 |
||
141 |
return (*timeout == 0); |
|
142 |
} |
|
143 |
||
144 |
static gboolean timerSourceCheckHelper(GTimerSource *src) |
|
145 |
{ |
|
146 |
if (src->timerList.isEmpty() |
|
147 |
|| (src->processEventsFlags & QEventLoop::X11ExcludeTimers)) |
|
148 |
return false; |
|
149 |
||
150 |
if (src->timerList.updateCurrentTime() < src->timerList.first()->timeout) |
|
151 |
return false; |
|
152 |
||
153 |
return true; |
|
154 |
} |
|
155 |
||
156 |
static gboolean timerSourcePrepare(GSource *source, gint *timeout) |
|
157 |
{ |
|
158 |
gint dummy; |
|
159 |
if (!timeout) |
|
160 |
timeout = &dummy; |
|
161 |
||
162 |
GTimerSource *src = reinterpret_cast<GTimerSource *>(source); |
|
163 |
if (src->runWithIdlePriority) { |
|
164 |
if (timeout) |
|
165 |
*timeout = -1; |
|
166 |
return false; |
|
167 |
} |
|
168 |
||
169 |
return timerSourcePrepareHelper(src, timeout); |
|
170 |
} |
|
171 |
||
172 |
static gboolean timerSourceCheck(GSource *source) |
|
173 |
{ |
|
174 |
GTimerSource *src = reinterpret_cast<GTimerSource *>(source); |
|
175 |
if (src->runWithIdlePriority) |
|
176 |
return false; |
|
177 |
return timerSourceCheckHelper(src); |
|
178 |
} |
|
179 |
||
180 |
static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer) |
|
181 |
{ |
|
182 |
GTimerSource *timerSource = reinterpret_cast<GTimerSource *>(source); |
|
183 |
timerSource->runWithIdlePriority = true; |
|
184 |
(void) timerSource->timerList.activateTimers(); |
|
185 |
return true; // ??? don't remove, right again? |
|
186 |
} |
|
187 |
||
188 |
static GSourceFuncs timerSourceFuncs = { |
|
189 |
timerSourcePrepare, |
|
190 |
timerSourceCheck, |
|
191 |
timerSourceDispatch, |
|
192 |
NULL, |
|
193 |
NULL, |
|
194 |
NULL |
|
195 |
}; |
|
196 |
||
197 |
struct GIdleTimerSource |
|
198 |
{ |
|
199 |
GSource source; |
|
200 |
GTimerSource *timerSource; |
|
201 |
}; |
|
202 |
||
203 |
static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout) |
|
204 |
{ |
|
205 |
GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source); |
|
206 |
GTimerSource *timerSource = idleTimerSource->timerSource; |
|
207 |
if (!timerSource->runWithIdlePriority) { |
|
208 |
// Yield to the normal priority timer source |
|
209 |
if (timeout) |
|
210 |
*timeout = -1; |
|
211 |
return false; |
|
212 |
} |
|
213 |
||
214 |
return timerSourcePrepareHelper(timerSource, timeout); |
|
215 |
} |
|
216 |
||
217 |
static gboolean idleTimerSourceCheck(GSource *source) |
|
218 |
{ |
|
219 |
GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source); |
|
220 |
GTimerSource *timerSource = idleTimerSource->timerSource; |
|
221 |
if (!timerSource->runWithIdlePriority) { |
|
222 |
// Yield to the normal priority timer source |
|
223 |
return false; |
|
224 |
} |
|
225 |
return timerSourceCheckHelper(timerSource); |
|
226 |
} |
|
227 |
||
228 |
static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer) |
|
229 |
{ |
|
230 |
GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource; |
|
231 |
(void) timerSourceDispatch(&timerSource->source, 0, 0); |
|
232 |
return true; |
|
233 |
} |
|
234 |
||
235 |
static GSourceFuncs idleTimerSourceFuncs = { |
|
236 |
idleTimerSourcePrepare, |
|
237 |
idleTimerSourceCheck, |
|
238 |
idleTimerSourceDispatch, |
|
239 |
NULL, |
|
240 |
NULL, |
|
241 |
NULL |
|
242 |
}; |
|
243 |
||
244 |
struct GPostEventSource |
|
245 |
{ |
|
246 |
GSource source; |
|
247 |
QAtomicInt serialNumber; |
|
248 |
int lastSerialNumber; |
|
249 |
}; |
|
250 |
||
251 |
static gboolean postEventSourcePrepare(GSource *s, gint *timeout) |
|
252 |
{ |
|
253 |
QThreadData *data = QThreadData::current(); |
|
254 |
if (!data) |
|
255 |
return false; |
|
256 |
||
257 |
gint dummy; |
|
258 |
if (!timeout) |
|
259 |
timeout = &dummy; |
|
260 |
*timeout = data->canWait ? -1 : 0; |
|
261 |
||
262 |
GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s); |
|
263 |
return (!data->canWait |
|
264 |
|| (source->serialNumber != source->lastSerialNumber)); |
|
265 |
} |
|
266 |
||
267 |
static gboolean postEventSourceCheck(GSource *source) |
|
268 |
{ |
|
269 |
return postEventSourcePrepare(source, 0); |
|
270 |
} |
|
271 |
||
272 |
static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer) |
|
273 |
{ |
|
274 |
GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s); |
|
275 |
source->lastSerialNumber = source->serialNumber; |
|
276 |
QCoreApplication::sendPostedEvents(); |
|
277 |
return true; // i dunno, george... |
|
278 |
} |
|
279 |
||
280 |
static GSourceFuncs postEventSourceFuncs = { |
|
281 |
postEventSourcePrepare, |
|
282 |
postEventSourceCheck, |
|
283 |
postEventSourceDispatch, |
|
284 |
NULL, |
|
285 |
NULL, |
|
286 |
NULL |
|
287 |
}; |
|
288 |
||
289 |
||
290 |
QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) |
|
291 |
: mainContext(context) |
|
292 |
{ |
|
293 |
if (qgetenv("QT_NO_THREADED_GLIB").isEmpty()) { |
|
294 |
static int dummyValue = 0; // only used for its address |
|
295 |
QMutexLocker locker(QMutexPool::instance()->get(&dummyValue)); |
|
296 |
if (!g_thread_supported()) |
|
297 |
g_thread_init(NULL); |
|
298 |
} |
|
299 |
||
300 |
if (mainContext) { |
|
301 |
g_main_context_ref(mainContext); |
|
302 |
} else { |
|
303 |
QCoreApplication *app = QCoreApplication::instance(); |
|
304 |
if (app && QThread::currentThread() == app->thread()) { |
|
305 |
mainContext = g_main_context_default(); |
|
306 |
g_main_context_ref(mainContext); |
|
307 |
} else { |
|
308 |
mainContext = g_main_context_new(); |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
// setup post event source |
|
313 |
postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs, |
|
314 |
sizeof(GPostEventSource))); |
|
315 |
postEventSource->serialNumber = 1; |
|
316 |
g_source_set_can_recurse(&postEventSource->source, true); |
|
317 |
g_source_attach(&postEventSource->source, mainContext); |
|
318 |
||
319 |
// setup socketNotifierSource |
|
320 |
socketNotifierSource = |
|
321 |
reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs, |
|
322 |
sizeof(GSocketNotifierSource))); |
|
323 |
(void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>(); |
|
324 |
g_source_set_can_recurse(&socketNotifierSource->source, true); |
|
325 |
g_source_attach(&socketNotifierSource->source, mainContext); |
|
326 |
||
327 |
// setup normal and idle timer sources |
|
328 |
timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs, |
|
329 |
sizeof(GTimerSource))); |
|
330 |
(void) new (&timerSource->timerList) QTimerInfoList(); |
|
331 |
timerSource->processEventsFlags = QEventLoop::AllEvents; |
|
332 |
timerSource->runWithIdlePriority = false; |
|
333 |
g_source_set_can_recurse(&timerSource->source, true); |
|
334 |
g_source_attach(&timerSource->source, mainContext); |
|
335 |
||
336 |
idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs, |
|
337 |
sizeof(GIdleTimerSource))); |
|
338 |
idleTimerSource->timerSource = timerSource; |
|
339 |
g_source_set_can_recurse(&idleTimerSource->source, true); |
|
340 |
g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE); |
|
341 |
g_source_attach(&idleTimerSource->source, mainContext); |
|
342 |
} |
|
343 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
void QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
timerSource->runWithIdlePriority = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
|
0 | 349 |
QEventDispatcherGlib::QEventDispatcherGlib(QObject *parent) |
350 |
: QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate), parent) |
|
351 |
{ |
|
352 |
} |
|
353 |
||
354 |
QEventDispatcherGlib::QEventDispatcherGlib(GMainContext *mainContext, QObject *parent) |
|
355 |
: QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate(mainContext)), parent) |
|
356 |
{ } |
|
357 |
||
358 |
QEventDispatcherGlib::~QEventDispatcherGlib() |
|
359 |
{ |
|
360 |
Q_D(QEventDispatcherGlib); |
|
361 |
||
362 |
// destroy all timer sources |
|
363 |
qDeleteAll(d->timerSource->timerList); |
|
364 |
d->timerSource->timerList.~QTimerInfoList(); |
|
365 |
g_source_destroy(&d->timerSource->source); |
|
366 |
g_source_unref(&d->timerSource->source); |
|
367 |
d->timerSource = 0; |
|
368 |
g_source_destroy(&d->idleTimerSource->source); |
|
369 |
g_source_unref(&d->idleTimerSource->source); |
|
370 |
d->idleTimerSource = 0; |
|
371 |
||
372 |
// destroy socket notifier source |
|
373 |
for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) { |
|
374 |
GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds[i]; |
|
375 |
g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd); |
|
376 |
delete p; |
|
377 |
} |
|
378 |
d->socketNotifierSource->pollfds.~QList<GPollFDWithQSocketNotifier *>(); |
|
379 |
g_source_destroy(&d->socketNotifierSource->source); |
|
380 |
g_source_unref(&d->socketNotifierSource->source); |
|
381 |
d->socketNotifierSource = 0; |
|
382 |
||
383 |
// destroy post event source |
|
384 |
g_source_destroy(&d->postEventSource->source); |
|
385 |
g_source_unref(&d->postEventSource->source); |
|
386 |
d->postEventSource = 0; |
|
387 |
||
388 |
Q_ASSERT(d->mainContext != 0); |
|
389 |
g_main_context_unref(d->mainContext); |
|
390 |
d->mainContext = 0; |
|
391 |
} |
|
392 |
||
393 |
bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags) |
|
394 |
{ |
|
395 |
Q_D(QEventDispatcherGlib); |
|
396 |
||
397 |
const bool canWait = (flags & QEventLoop::WaitForMoreEvents); |
|
398 |
if (canWait) |
|
399 |
emit aboutToBlock(); |
|
400 |
else |
|
401 |
emit awake(); |
|
402 |
||
403 |
// tell postEventSourcePrepare() and timerSource about any new flags |
|
404 |
QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags; |
|
405 |
d->timerSource->processEventsFlags = flags; |
|
406 |
||
407 |
if (!(flags & QEventLoop::EventLoopExec)) { |
|
408 |
// force timers to be sent at normal priority |
|
409 |
d->timerSource->runWithIdlePriority = false; |
|
410 |
} |
|
411 |
||
412 |
bool result = g_main_context_iteration(d->mainContext, canWait); |
|
413 |
while (!result && canWait) |
|
414 |
result = g_main_context_iteration(d->mainContext, canWait); |
|
415 |
||
416 |
d->timerSource->processEventsFlags = savedFlags; |
|
417 |
||
418 |
if (canWait) |
|
419 |
emit awake(); |
|
420 |
||
421 |
return result; |
|
422 |
} |
|
423 |
||
424 |
bool QEventDispatcherGlib::hasPendingEvents() |
|
425 |
{ |
|
426 |
Q_D(QEventDispatcherGlib); |
|
427 |
return g_main_context_pending(d->mainContext); |
|
428 |
} |
|
429 |
||
430 |
void QEventDispatcherGlib::registerSocketNotifier(QSocketNotifier *notifier) |
|
431 |
{ |
|
432 |
Q_ASSERT(notifier); |
|
433 |
int sockfd = notifier->socket(); |
|
434 |
int type = notifier->type(); |
|
435 |
#ifndef QT_NO_DEBUG |
|
436 |
if (sockfd < 0) { |
|
437 |
qWarning("QSocketNotifier: Internal error"); |
|
438 |
return; |
|
439 |
} else if (notifier->thread() != thread() |
|
440 |
|| thread() != QThread::currentThread()) { |
|
441 |
qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); |
|
442 |
return; |
|
443 |
} |
|
444 |
#endif |
|
445 |
||
446 |
Q_D(QEventDispatcherGlib); |
|
447 |
||
448 |
||
449 |
GPollFDWithQSocketNotifier *p = new GPollFDWithQSocketNotifier; |
|
450 |
p->pollfd.fd = sockfd; |
|
451 |
switch (type) { |
|
452 |
case QSocketNotifier::Read: |
|
453 |
p->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; |
|
454 |
break; |
|
455 |
case QSocketNotifier::Write: |
|
456 |
p->pollfd.events = G_IO_OUT | G_IO_ERR; |
|
457 |
break; |
|
458 |
case QSocketNotifier::Exception: |
|
459 |
p->pollfd.events = G_IO_PRI | G_IO_ERR; |
|
460 |
break; |
|
461 |
} |
|
462 |
p->socketNotifier = notifier; |
|
463 |
||
464 |
d->socketNotifierSource->pollfds.append(p); |
|
465 |
||
466 |
g_source_add_poll(&d->socketNotifierSource->source, &p->pollfd); |
|
467 |
} |
|
468 |
||
469 |
void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier) |
|
470 |
{ |
|
471 |
Q_ASSERT(notifier); |
|
472 |
#ifndef QT_NO_DEBUG |
|
473 |
int sockfd = notifier->socket(); |
|
474 |
if (sockfd < 0) { |
|
475 |
qWarning("QSocketNotifier: Internal error"); |
|
476 |
return; |
|
477 |
} else if (notifier->thread() != thread() |
|
478 |
|| thread() != QThread::currentThread()) { |
|
479 |
qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); |
|
480 |
return; |
|
481 |
} |
|
482 |
#endif |
|
483 |
||
484 |
Q_D(QEventDispatcherGlib); |
|
485 |
||
486 |
for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) { |
|
487 |
GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i); |
|
488 |
if (p->socketNotifier == notifier) { |
|
489 |
// found it |
|
490 |
g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd); |
|
491 |
||
492 |
d->socketNotifierSource->pollfds.removeAt(i); |
|
493 |
delete p; |
|
494 |
||
495 |
return; |
|
496 |
} |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
void QEventDispatcherGlib::registerTimer(int timerId, int interval, QObject *object) |
|
501 |
{ |
|
502 |
#ifndef QT_NO_DEBUG |
|
503 |
if (timerId < 1 || interval < 0 || !object) { |
|
504 |
qWarning("QEventDispatcherUNIX::registerTimer: invalid arguments"); |
|
505 |
return; |
|
506 |
} else if (object->thread() != thread() || thread() != QThread::currentThread()) { |
|
507 |
qWarning("QObject::startTimer: timers cannot be started from another thread"); |
|
508 |
return; |
|
509 |
} |
|
510 |
#endif |
|
511 |
||
512 |
Q_D(QEventDispatcherGlib); |
|
513 |
d->timerSource->timerList.registerTimer(timerId, interval, object); |
|
514 |
} |
|
515 |
||
516 |
bool QEventDispatcherGlib::unregisterTimer(int timerId) |
|
517 |
{ |
|
518 |
#ifndef QT_NO_DEBUG |
|
519 |
if (timerId < 1) { |
|
520 |
qWarning("QEventDispatcherUNIX::unregisterTimer: invalid argument"); |
|
521 |
return false; |
|
522 |
} else if (thread() != QThread::currentThread()) { |
|
523 |
qWarning("QObject::killTimer: timers cannot be stopped from another thread"); |
|
524 |
return false; |
|
525 |
} |
|
526 |
#endif |
|
527 |
||
528 |
Q_D(QEventDispatcherGlib); |
|
529 |
return d->timerSource->timerList.unregisterTimer(timerId); |
|
530 |
} |
|
531 |
||
532 |
bool QEventDispatcherGlib::unregisterTimers(QObject *object) |
|
533 |
{ |
|
534 |
#ifndef QT_NO_DEBUG |
|
535 |
if (!object) { |
|
536 |
qWarning("QEventDispatcherUNIX::unregisterTimers: invalid argument"); |
|
537 |
return false; |
|
538 |
} else if (object->thread() != thread() || thread() != QThread::currentThread()) { |
|
539 |
qWarning("QObject::killTimers: timers cannot be stopped from another thread"); |
|
540 |
return false; |
|
541 |
} |
|
542 |
#endif |
|
543 |
||
544 |
Q_D(QEventDispatcherGlib); |
|
545 |
return d->timerSource->timerList.unregisterTimers(object); |
|
546 |
} |
|
547 |
||
548 |
QList<QEventDispatcherGlib::TimerInfo> QEventDispatcherGlib::registeredTimers(QObject *object) const |
|
549 |
{ |
|
550 |
if (!object) { |
|
551 |
qWarning("QEventDispatcherUNIX:registeredTimers: invalid argument"); |
|
552 |
return QList<TimerInfo>(); |
|
553 |
} |
|
554 |
||
555 |
Q_D(const QEventDispatcherGlib); |
|
556 |
return d->timerSource->timerList.registeredTimers(object); |
|
557 |
} |
|
558 |
||
559 |
void QEventDispatcherGlib::interrupt() |
|
560 |
{ |
|
561 |
wakeUp(); |
|
562 |
} |
|
563 |
||
564 |
void QEventDispatcherGlib::wakeUp() |
|
565 |
{ |
|
566 |
Q_D(QEventDispatcherGlib); |
|
567 |
d->postEventSource->serialNumber.ref(); |
|
568 |
g_main_context_wakeup(d->mainContext); |
|
569 |
} |
|
570 |
||
571 |
void QEventDispatcherGlib::flush() |
|
572 |
{ |
|
573 |
} |
|
574 |
||
575 |
bool QEventDispatcherGlib::versionSupported() |
|
576 |
{ |
|
577 |
#if !defined(GLIB_MAJOR_VERSION) || !defined(GLIB_MINOR_VERSION) || !defined(GLIB_MICRO_VERSION) |
|
578 |
return false; |
|
579 |
#else |
|
580 |
return ((GLIB_MAJOR_VERSION << 16) + (GLIB_MINOR_VERSION << 8) + GLIB_MICRO_VERSION) >= 0x020301; |
|
581 |
#endif |
|
582 |
} |
|
583 |
||
584 |
QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObject *parent) |
|
585 |
: QAbstractEventDispatcher(dd, parent) |
|
586 |
{ |
|
587 |
} |
|
588 |
||
589 |
QT_END_NAMESPACE |