Qt 4.8
qeventdispatcher_unix_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QEVENTDISPATCHER_UNIX_P_H
43 #define QEVENTDISPATCHER_UNIX_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtCore/qabstracteventdispatcher.h"
57 #include "QtCore/qlist.h"
58 #include "private/qabstracteventdispatcher_p.h"
59 #include "private/qcore_unix_p.h"
60 #include "private/qpodlist_p.h"
61 #include "QtCore/qvarlengtharray.h"
62 
63 #if !defined(Q_OS_VXWORKS)
64 # include <sys/time.h>
65 # if (!defined(Q_OS_HPUX) || defined(__ia64)) && !defined(Q_OS_NACL)
66 # include <sys/select.h>
67 # endif
68 #endif
69 
71 
72 // internal timer info
73 struct QTimerInfo {
74  int id; // - timer identifier
75  timeval interval; // - timer interval
76  timeval timeout; // - when to sent event
77  QObject *obj; // - object to receive event
78  QTimerInfo **activateRef; // - ref from activateTimers
79 };
80 
81 class QTimerInfoList : public QList<QTimerInfo*>
82 {
83 #if ((_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC)) || defined(QT_BOOTSTRAPPED)
84  timeval previousTime;
85  clock_t previousTicks;
86  int ticksPerSecond;
87  int msPerTick;
88 
89  bool timeChanged(timeval *delta);
90 #endif
91 
92  // state variables used by activateTimers()
94 
95 public:
97 
98  timeval currentTime;
99  timeval updateCurrentTime();
100 
101  // must call updateCurrentTime() first!
102  void repairTimersIfNeeded();
103 
104  bool timerWait(timeval &);
105  void timerInsert(QTimerInfo *);
106  void timerRepair(const timeval &);
107 
108  void registerTimer(int timerId, int interval, QObject *object);
109  bool unregisterTimer(int timerId);
110  bool unregisterTimers(QObject *object);
111  QList<QPair<int, int> > registeredTimers(QObject *object) const;
112 
113  int activateTimers();
114 };
115 
116 struct QSockNot
117 {
119  int fd;
120  fd_set *queue;
121 };
122 
124 {
125 public:
126  QSockNotType();
127  ~QSockNotType();
128 
130 
131  List list;
132  fd_set select_fds;
133  fd_set enabled_fds;
134  fd_set pending_fds;
135 
136 };
137 
139 
141 {
142  Q_OBJECT
144 
145 public:
146  explicit QEventDispatcherUNIX(QObject *parent = 0);
148 
149  bool processEvents(QEventLoop::ProcessEventsFlags flags);
150  bool hasPendingEvents();
151 
152  void registerSocketNotifier(QSocketNotifier *notifier);
153  void unregisterSocketNotifier(QSocketNotifier *notifier);
154 
155  void registerTimer(int timerId, int interval, QObject *object);
156  bool unregisterTimer(int timerId);
157  bool unregisterTimers(QObject *object);
158  QList<TimerInfo> registeredTimers(QObject *object) const;
159 
160  void wakeUp();
161  void interrupt();
162  void flush();
163 
164 protected:
166 
167  void setSocketNotifierPending(QSocketNotifier *notifier);
168 
169  int activateTimers();
170  int activateSocketNotifiers();
171 
172  virtual int select(int nfds,
173  fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
174  timeval *timeout);
175 };
176 
178 {
180 
181 public:
184 
185  int doSelect(QEventLoop::ProcessEventsFlags flags, timeval *timeout);
186  virtual int initThreadWakeUp();
187  virtual int processThreadWakeUp(int nsel);
188 
190  int thread_pipe[2];
191 
192  // highest fd for all socket notifiers
194  // 3 socket notifier types - read, write and exception
195  QSockNotType sn_vec[3];
196 
198 
199  // pending socket notifiers list
201 
203  bool interrupt;
204 };
205 
207 
208 #endif // QEVENTDISPATCHER_UNIX_P_H
QSocketNotifier * obj
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
QTimerInfo * firstTimerInfo
QTimerInfo ** activateRef
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
Q_CORE_EXPORT QTextStream & flush(QTextStream &s)
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QPodList< QSockNot *, 32 > List
The QAbstractEventDispatcher class provides an interface to manage Qt&#39;s event queue.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62