Qt 4.8
Classes | Functions | Variables
qeventdispatcher_glib.cpp File Reference
#include "qeventdispatcher_glib_p.h"
#include "qeventdispatcher_unix_p.h"
#include <private/qmutexpool_p.h>
#include <private/qthread_p.h>
#include "qcoreapplication.h"
#include "qsocketnotifier.h"
#include <QtCore/qhash.h>
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>
#include <glib.h>

Go to the source code of this file.

Classes

struct  GIdleTimerSource
 
struct  GPollFDWithQSocketNotifier
 
struct  GPostEventSource
 
struct  GSocketNotifierSource
 
struct  GTimerSource
 

Functions

static gboolean idleTimerSourceCheck (GSource *source)
 
static gboolean idleTimerSourceDispatch (GSource *source, GSourceFunc, gpointer)
 
static gboolean idleTimerSourcePrepare (GSource *source, gint *timeout)
 
static gboolean postEventSourceCheck (GSource *source)
 
static gboolean postEventSourceDispatch (GSource *s, GSourceFunc, gpointer)
 
static gboolean postEventSourcePrepare (GSource *s, gint *timeout)
 
static gboolean socketNotifierSourceCheck (GSource *source)
 
static gboolean socketNotifierSourceDispatch (GSource *source, GSourceFunc, gpointer)
 
static gboolean socketNotifierSourcePrepare (GSource *, gint *timeout)
 
static gboolean timerSourceCheck (GSource *source)
 
static gboolean timerSourceCheckHelper (GTimerSource *src)
 
static gboolean timerSourceDispatch (GSource *source, GSourceFunc, gpointer)
 
static gboolean timerSourcePrepare (GSource *source, gint *timeout)
 
static gboolean timerSourcePrepareHelper (GTimerSource *src, gint *timeout)
 

Variables

static GSourceFuncs idleTimerSourceFuncs
 
static GSourceFuncs postEventSourceFuncs
 
static GSourceFuncs socketNotifierSourceFuncs
 
static GSourceFuncs timerSourceFuncs
 

Function Documentation

◆ idleTimerSourceCheck()

static gboolean idleTimerSourceCheck ( GSource *  source)
static

Definition at line 219 of file qeventdispatcher_glib.cpp.

220 {
221  GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);
222  GTimerSource *timerSource = idleTimerSource->timerSource;
223  if (!timerSource->runWithIdlePriority) {
224  // Yield to the normal priority timer source
225  return false;
226  }
227  return timerSourceCheckHelper(timerSource);
228 }
static gboolean timerSourceCheckHelper(GTimerSource *src)

◆ idleTimerSourceDispatch()

static gboolean idleTimerSourceDispatch ( GSource *  source,
GSourceFunc  ,
gpointer   
)
static

Definition at line 230 of file qeventdispatcher_glib.cpp.

231 {
232  GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource;
233  (void) timerSourceDispatch(&timerSource->source, 0, 0);
234  return true;
235 }
static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer)

◆ idleTimerSourcePrepare()

static gboolean idleTimerSourcePrepare ( GSource *  source,
gint *  timeout 
)
static

Definition at line 205 of file qeventdispatcher_glib.cpp.

206 {
207  GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);
208  GTimerSource *timerSource = idleTimerSource->timerSource;
209  if (!timerSource->runWithIdlePriority) {
210  // Yield to the normal priority timer source
211  if (timeout)
212  *timeout = -1;
213  return false;
214  }
215 
216  return timerSourcePrepareHelper(timerSource, timeout);
217 }
static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout)

◆ postEventSourceCheck()

static gboolean postEventSourceCheck ( GSource *  source)
static

Definition at line 271 of file qeventdispatcher_glib.cpp.

272 {
273  return postEventSourcePrepare(source, 0);
274 }
static gboolean postEventSourcePrepare(GSource *s, gint *timeout)

◆ postEventSourceDispatch()

static gboolean postEventSourceDispatch ( GSource *  s,
GSourceFunc  ,
gpointer   
)
static

Definition at line 276 of file qeventdispatcher_glib.cpp.

277 {
278  GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
279  source->lastSerialNumber = source->serialNumber;
282  return true; // i dunno, george...
283 }
QEventDispatcherGlibPrivate * d
static void sendPostedEvents()

◆ postEventSourcePrepare()

static gboolean postEventSourcePrepare ( GSource *  s,
gint *  timeout 
)
static

Definition at line 254 of file qeventdispatcher_glib.cpp.

Referenced by postEventSourceCheck().

255 {
257  if (!data)
258  return false;
259 
260  gint dummy;
261  if (!timeout)
262  timeout = &dummy;
263  const bool canWait = data->canWaitLocked();
264  *timeout = canWait ? -1 : 0;
265 
266  GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
267  return (!canWait
268  || (source->serialNumber != source->lastSerialNumber));
269 }
bool canWaitLocked()
Definition: qthread_p.h:226
static const char * data(const QByteArray &arr)
static QThreadData * current()

◆ socketNotifierSourceCheck()

static gboolean socketNotifierSourceCheck ( GSource *  source)
static

Definition at line 78 of file qeventdispatcher_glib.cpp.

79 {
80  GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
81 
82  bool pending = false;
83  for (int i = 0; !pending && i < src->pollfds.count(); ++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 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Type type() const
Returns the socket event type specified to the constructor.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
QList< GPollFDWithQSocketNotifier * > pollfds
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.

◆ socketNotifierSourceDispatch()

static gboolean socketNotifierSourceDispatch ( GSource *  source,
GSourceFunc  ,
gpointer   
)
static

Definition at line 101 of file qeventdispatcher_glib.cpp.

102 {
104 
105  GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
106  for (int i = 0; i < src->pollfds.count(); ++i) {
108 
109  if ((p->pollfd.revents & p->pollfd.events) != 0)
111  }
112 
113  return true; // ??? don't remove, right?
114 }
EventRef event
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QList< GPollFDWithQSocketNotifier * > pollfds
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ socketNotifierSourcePrepare()

static gboolean socketNotifierSourcePrepare ( GSource *  ,
gint *  timeout 
)
static

Definition at line 71 of file qeventdispatcher_glib.cpp.

72 {
73  if (timeout)
74  *timeout = -1;
75  return false;
76 }

◆ timerSourceCheck()

static gboolean timerSourceCheck ( GSource *  source)
static

Definition at line 172 of file qeventdispatcher_glib.cpp.

173 {
174  GTimerSource *src = reinterpret_cast<GTimerSource *>(source);
175  if (src->runWithIdlePriority)
176  return false;
177  return timerSourceCheckHelper(src);
178 }
static gboolean timerSourceCheckHelper(GTimerSource *src)

◆ timerSourceCheckHelper()

static gboolean timerSourceCheckHelper ( GTimerSource src)
static

Definition at line 144 of file qeventdispatcher_glib.cpp.

Referenced by idleTimerSourceCheck(), and timerSourceCheck().

145 {
146  if (src->timerList.isEmpty()
148  return false;
149 
150  if (src->timerList.updateCurrentTime() < src->timerList.first()->timeout)
151  return false;
152 
153  return true;
154 }
QEventLoop::ProcessEventsFlags processEventsFlags
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QTimerInfoList timerList

◆ timerSourceDispatch()

static gboolean timerSourceDispatch ( GSource *  source,
GSourceFunc  ,
gpointer   
)
static

Definition at line 180 of file qeventdispatcher_glib.cpp.

181 {
182  GTimerSource *timerSource = reinterpret_cast<GTimerSource *>(source);
184  return true;
185  timerSource->runWithIdlePriority = true;
186  (void) timerSource->timerList.activateTimers();
187  return true; // ??? don't remove, right again?
188 }
QEventLoop::ProcessEventsFlags processEventsFlags
QTimerInfoList timerList

◆ timerSourcePrepare()

static gboolean timerSourcePrepare ( GSource *  source,
gint *  timeout 
)
static

Definition at line 156 of file qeventdispatcher_glib.cpp.

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 }
static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout)

◆ timerSourcePrepareHelper()

static gboolean timerSourcePrepareHelper ( GTimerSource src,
gint *  timeout 
)
static

Definition at line 133 of file qeventdispatcher_glib.cpp.

Referenced by idleTimerSourcePrepare(), and timerSourcePrepare().

134 {
135  timeval tv = { 0l, 0l };
137  *timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
138  else
139  *timeout = -1;
140 
141  return (*timeout == 0);
142 }
QEventLoop::ProcessEventsFlags processEventsFlags
QTimerInfoList timerList
QFactoryLoader * l
bool timerWait(timeval &)

Variable Documentation

◆ idleTimerSourceFuncs

GSourceFuncs idleTimerSourceFuncs
static
Initial value:
= {
NULL,
NULL,
NULL
}
static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean idleTimerSourceCheck(GSource *source)
static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout)

Definition at line 237 of file qeventdispatcher_glib.cpp.

◆ postEventSourceFuncs

GSourceFuncs postEventSourceFuncs
static
Initial value:
= {
NULL,
NULL,
NULL
}
static gboolean postEventSourcePrepare(GSource *s, gint *timeout)
static gboolean postEventSourceCheck(GSource *source)
static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer)

Definition at line 285 of file qeventdispatcher_glib.cpp.

Referenced by QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate().

◆ socketNotifierSourceFuncs

GSourceFuncs socketNotifierSourceFuncs
static
Initial value:
= {
NULL,
NULL,
NULL
}
static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean socketNotifierSourceCheck(GSource *source)
static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout)

Definition at line 116 of file qeventdispatcher_glib.cpp.

Referenced by QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate().

◆ timerSourceFuncs

GSourceFuncs timerSourceFuncs
static
Initial value:
= {
NULL,
NULL,
NULL
}
static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean timerSourceCheck(GSource *source)
static gboolean timerSourcePrepare(GSource *source, gint *timeout)

Definition at line 190 of file qeventdispatcher_glib.cpp.