author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
#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/times.h> |
|
65 |
#else |
|
66 |
# include <sys/time.h> |
|
67 |
# if !defined(Q_OS_HPUX) || defined(__ia64) |
|
68 |
# include <sys/select.h> |
|
69 |
# endif |
|
70 |
#endif |
|
71 |
||
72 |
QT_BEGIN_NAMESPACE |
|
73 |
||
74 |
// internal timer info |
|
75 |
struct QTimerInfo { |
|
76 |
int id; // - timer identifier |
|
77 |
timeval interval; // - timer interval |
|
78 |
timeval timeout; // - when to sent event |
|
79 |
QObject *obj; // - object to receive event |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
80 |
QTimerInfo **activateRef; // - ref from activateTimers |
0 | 81 |
}; |
82 |
||
83 |
class QTimerInfoList : public QList<QTimerInfo*> |
|
84 |
{ |
|
85 |
#if ((_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC)) || defined(QT_BOOTSTRAPPED) |
|
86 |
timeval previousTime; |
|
87 |
clock_t previousTicks; |
|
88 |
int ticksPerSecond; |
|
89 |
int msPerTick; |
|
90 |
||
91 |
bool timeChanged(timeval *delta); |
|
92 |
#endif |
|
93 |
||
94 |
// state variables used by activateTimers() |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
95 |
QTimerInfo *firstTimerInfo; |
0 | 96 |
|
97 |
public: |
|
98 |
QTimerInfoList(); |
|
99 |
||
100 |
timeval currentTime; |
|
101 |
timeval updateCurrentTime(); |
|
102 |
||
103 |
// must call updateCurrentTime() first! |
|
104 |
void repairTimersIfNeeded(); |
|
105 |
||
106 |
bool timerWait(timeval &); |
|
107 |
void timerInsert(QTimerInfo *); |
|
108 |
void timerRepair(const timeval &); |
|
109 |
||
110 |
void registerTimer(int timerId, int interval, QObject *object); |
|
111 |
bool unregisterTimer(int timerId); |
|
112 |
bool unregisterTimers(QObject *object); |
|
113 |
QList<QPair<int, int> > registeredTimers(QObject *object) const; |
|
114 |
||
115 |
int activateTimers(); |
|
116 |
}; |
|
117 |
||
118 |
struct QSockNot |
|
119 |
{ |
|
120 |
QSocketNotifier *obj; |
|
121 |
int fd; |
|
122 |
fd_set *queue; |
|
123 |
}; |
|
124 |
||
125 |
class QSockNotType |
|
126 |
{ |
|
127 |
public: |
|
128 |
QSockNotType(); |
|
129 |
~QSockNotType(); |
|
130 |
||
131 |
typedef QPodList<QSockNot*, 32> List; |
|
132 |
||
133 |
List list; |
|
134 |
fd_set select_fds; |
|
135 |
fd_set enabled_fds; |
|
136 |
fd_set pending_fds; |
|
137 |
||
138 |
}; |
|
139 |
||
140 |
class QEventDispatcherUNIXPrivate; |
|
141 |
||
142 |
class Q_CORE_EXPORT QEventDispatcherUNIX : public QAbstractEventDispatcher |
|
143 |
{ |
|
144 |
Q_OBJECT |
|
145 |
Q_DECLARE_PRIVATE(QEventDispatcherUNIX) |
|
146 |
||
147 |
public: |
|
148 |
explicit QEventDispatcherUNIX(QObject *parent = 0); |
|
149 |
~QEventDispatcherUNIX(); |
|
150 |
||
151 |
bool processEvents(QEventLoop::ProcessEventsFlags flags); |
|
152 |
bool hasPendingEvents(); |
|
153 |
||
154 |
void registerSocketNotifier(QSocketNotifier *notifier); |
|
155 |
void unregisterSocketNotifier(QSocketNotifier *notifier); |
|
156 |
||
157 |
void registerTimer(int timerId, int interval, QObject *object); |
|
158 |
bool unregisterTimer(int timerId); |
|
159 |
bool unregisterTimers(QObject *object); |
|
160 |
QList<TimerInfo> registeredTimers(QObject *object) const; |
|
161 |
||
162 |
void wakeUp(); |
|
163 |
void interrupt(); |
|
164 |
void flush(); |
|
165 |
||
166 |
protected: |
|
167 |
QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent = 0); |
|
168 |
||
169 |
void setSocketNotifierPending(QSocketNotifier *notifier); |
|
170 |
||
171 |
int activateTimers(); |
|
172 |
int activateSocketNotifiers(); |
|
173 |
||
174 |
virtual int select(int nfds, |
|
175 |
fd_set *readfds, fd_set *writefds, fd_set *exceptfds, |
|
176 |
timeval *timeout); |
|
177 |
}; |
|
178 |
||
179 |
class Q_CORE_EXPORT QEventDispatcherUNIXPrivate : public QAbstractEventDispatcherPrivate |
|
180 |
{ |
|
181 |
Q_DECLARE_PUBLIC(QEventDispatcherUNIX) |
|
182 |
||
183 |
public: |
|
184 |
QEventDispatcherUNIXPrivate(); |
|
185 |
~QEventDispatcherUNIXPrivate(); |
|
186 |
||
187 |
int doSelect(QEventLoop::ProcessEventsFlags flags, timeval *timeout); |
|
188 |
||
189 |
bool mainThread; |
|
190 |
int thread_pipe[2]; |
|
191 |
||
192 |
// highest fd for all socket notifiers |
|
193 |
int sn_highest; |
|
194 |
// 3 socket notifier types - read, write and exception |
|
195 |
QSockNotType sn_vec[3]; |
|
196 |
||
197 |
QTimerInfoList timerList; |
|
198 |
||
199 |
// pending socket notifiers list |
|
200 |
QSockNotType::List sn_pending_list; |
|
201 |
||
202 |
QAtomicInt wakeUps; |
|
203 |
bool interrupt; |
|
204 |
}; |
|
205 |
||
206 |
QT_END_NAMESPACE |
|
207 |
||
208 |
#endif // QEVENTDISPATCHER_UNIX_P_H |