45 #include <private/qmutexpool_p.h> 46 #include <private/qthread_p.h> 51 #include <QtCore/qhash.h> 52 #include <QtCore/qlist.h> 53 #include <QtCore/qpair.h> 83 for (
int i = 0; !pending && i < src->
pollfds.
count(); ++i) {
86 if (p->
pollfd.revents & G_IO_NVAL) {
88 static const char *t[] = {
"Read",
"Write",
"Exception" };
89 qWarning(
"QSocketNotifier: Invalid socket %d and type '%s', disabling...",
135 timeval tv = { 0
l, 0
l };
137 *timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
141 return (*timeout == 0);
264 *timeout = canWait ? -1 : 0;
296 : mainContext(context)
299 static int dummyValue = 0;
301 if (!g_thread_supported())
317 #if GLIB_CHECK_VERSION (2, 22, 0) 374 d->timerSource->timerList.~QTimerInfoList();
375 g_source_destroy(&
d->timerSource->source);
376 g_source_unref(&
d->timerSource->source);
378 g_source_destroy(&
d->idleTimerSource->source);
379 g_source_unref(&
d->idleTimerSource->source);
380 d->idleTimerSource = 0;
383 for (
int i = 0; i <
d->socketNotifierSource->pollfds.count(); ++i) {
385 g_source_remove_poll(&
d->socketNotifierSource->source, &p->
pollfd);
389 g_source_destroy(&
d->socketNotifierSource->source);
390 g_source_unref(&
d->socketNotifierSource->source);
391 d->socketNotifierSource = 0;
394 g_source_destroy(&
d->postEventSource->source);
395 g_source_unref(&
d->postEventSource->source);
396 d->postEventSource = 0;
399 #if GLIB_CHECK_VERSION (2, 22, 0) 400 g_main_context_pop_thread_default (
d->mainContext);
402 g_main_context_unref(
d->mainContext);
417 QEventLoop::ProcessEventsFlags savedFlags =
d->timerSource->processEventsFlags;
418 d->timerSource->processEventsFlags = flags;
422 d->timerSource->runWithIdlePriority =
false;
425 bool result = g_main_context_iteration(
d->mainContext, canWait);
426 while (!result && canWait)
427 result = g_main_context_iteration(
d->mainContext, canWait);
429 d->timerSource->processEventsFlags = savedFlags;
440 return g_main_context_pending(
d->mainContext);
446 int sockfd = notifier->
socket();
450 qWarning(
"QSocketNotifier: Internal error");
454 qWarning(
"QSocketNotifier: socket notifiers cannot be enabled from another thread");
466 p->
pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
469 p->
pollfd.events = G_IO_OUT | G_IO_ERR;
472 p->
pollfd.events = G_IO_PRI | G_IO_ERR;
477 d->socketNotifierSource->pollfds.append(p);
479 g_source_add_poll(&
d->socketNotifierSource->source, &p->
pollfd);
486 int sockfd = notifier->
socket();
488 qWarning(
"QSocketNotifier: Internal error");
492 qWarning(
"QSocketNotifier: socket notifiers cannot be disabled from another thread");
499 for (
int i = 0; i <
d->socketNotifierSource->pollfds.count(); ++i) {
503 g_source_remove_poll(&
d->socketNotifierSource->source, &p->
pollfd);
505 d->socketNotifierSource->pollfds.removeAt(i);
516 if (timerId < 1 || interval < 0 || !
object) {
517 qWarning(
"QEventDispatcherGlib::registerTimer: invalid arguments");
520 qWarning(
"QObject::startTimer: timers cannot be started from another thread");
526 d->timerSource->timerList.registerTimer(timerId, interval,
object);
533 qWarning(
"QEventDispatcherGlib::unregisterTimer: invalid argument");
536 qWarning(
"QObject::killTimer: timers cannot be stopped from another thread");
542 return d->timerSource->timerList.unregisterTimer(timerId);
549 qWarning(
"QEventDispatcherGlib::unregisterTimers: invalid argument");
552 qWarning(
"QObject::killTimers: timers cannot be stopped from another thread");
558 return d->timerSource->timerList.unregisterTimers(
object);
564 qWarning(
"QEventDispatcherUNIX:registeredTimers: invalid argument");
569 return d->timerSource->timerList.registeredTimers(
object);
580 d->postEventSource->serialNumber.ref();
581 g_main_context_wakeup(
d->mainContext);
590 #if !defined(GLIB_MAJOR_VERSION) || !defined(GLIB_MINOR_VERSION) || !defined(GLIB_MICRO_VERSION) 593 return ((GLIB_MAJOR_VERSION << 16) + (GLIB_MINOR_VERSION << 8) + GLIB_MICRO_VERSION) >= 0x020301;
static gboolean timerSourceCheckHelper(GTimerSource *src)
void unregisterSocketNotifier(QSocketNotifier *socketNotifier)
Unregisters notifier from the event dispatcher.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QEventLoop::ProcessEventsFlags processEventsFlags
static bool versionSupported()
static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer)
#define QT_END_NAMESPACE
This macro expands to.
static gboolean postEventSourcePrepare(GSource *s, gint *timeout)
void wakeUp()
Wakes up the event loop.
The QAtomicInt class provides platform-independent atomic operations on integers. ...
timeval updateCurrentTime()
GIdleTimerSource * idleTimerSource
static GSourceFuncs postEventSourceFuncs
static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer)
GTimerSource * timerSource
int count(const T &t) const
Returns the number of occurrences of value in the list.
static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout)
static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean postEventSourceCheck(GSource *source)
The QObject class is the base class of all Qt objects.
static gboolean socketNotifierSourceCheck(GSource *source)
QSocketNotifier * socketNotifier
GPostEventSource * postEventSource
Type type() const
Returns the socket event type specified to the constructor.
QEventDispatcherGlibPrivate * d
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
static GSourceFuncs socketNotifierSourceFuncs
bool hasPendingEvents()
Returns true if there is an event waiting; otherwise returns false.
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
void flush()
Flushes the event queue.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void awake()
This signal is emitted after the event loop returns from a function that could block.
static bool isEmpty(const char *str)
static GSourceFuncs timerSourceFuncs
GMainContext * mainContext
QEventDispatcherGlibPrivate(GMainContext *context=0)
static gboolean idleTimerSourceCheck(GSource *source)
void interrupt()
Interrupts event dispatching; i.
const T & at(int i) const
Returns the item at index position i in the list.
static QMutexPool * instance()
Returns the global QMutexPool instance.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
GTimerSource * timerSource
static void sendPostedEvents()
void runTimersOnceWithNormalPriority()
static GSourceFuncs idleTimerSourceFuncs
static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout)
QList< GPollFDWithQSocketNotifier * > pollfds
T & first()
Returns a reference to the first item in the list.
The QCoreApplication class provides an event loop for console Qt applications.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
void aboutToBlock()
This signal is emitted before the event loop calls a function that could block.
void registerTimer(int timerId, int interval, QObject *object)
Register a timer with the specified timerId and interval for the given object.
static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout)
static QCoreApplication * instance()
Returns a pointer to the application's QCoreApplication (or QApplication) instance.
QObject * parent() const
Returns a pointer to the parent object.
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
static gboolean timerSourceCheck(GSource *source)
static QThreadData * current()
void registerSocketNotifier(QSocketNotifier *socketNotifier)
Registers notifier with the event loop.
bool unregisterTimers(QObject *object)
Unregisters all the timers associated with the given object.
QEventDispatcherGlib(QObject *parent=0)
bool timerWait(timeval &)
struct _GMainContext GMainContext
QThread * thread() const
Returns the thread in which the object lives.
static gboolean timerSourcePrepare(GSource *source, gint *timeout)
QList< TimerInfo > registeredTimers(QObject *object) const
Returns a list of registered timers for object.
The QEvent class is the base class of all event classes.
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
The QAbstractEventDispatcher class provides an interface to manage Qt's event queue.
bool processEvents(QEventLoop::ProcessEventsFlags flags)
Processes pending events that match flags until there are no more events to process.
int socket() const
Returns the socket identifier specified to the constructor.
The QList class is a template class that provides lists.
bool unregisterTimer(int timerId)
Unregisters the timer with the given timerId.
GSocketNotifierSource * socketNotifierSource