author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 28 Apr 2010 13:15:16 +0300 | |
branch | RCL_3 |
changeset 16 | b25b6dc3ff8b |
parent 4 | 3b1da2848fc7 |
child 29 | b72c6db6890b |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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_SYMBIAN_P_H |
|
43 |
#define QEVENTDISPATCHER_SYMBIAN_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 <qhash.h> |
|
57 |
#include <qset.h> |
|
58 |
#include <qshareddata.h> |
|
59 |
#include <qabstracteventdispatcher.h> |
|
60 |
#include <private/qabstracteventdispatcher_p.h> |
|
61 |
#include <qthread.h> |
|
62 |
#include <qmutex.h> |
|
63 |
#include <qwaitcondition.h> |
|
64 |
#include <qsocketnotifier.h> |
|
16
b25b6dc3ff8b
2010-17 8b4fb6db9a24f58dafbd4734d9c4a87a72f9ad8f
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
65 |
#include <qdatetime.h> |
0 | 66 |
|
67 |
#include <e32base.h> |
|
68 |
||
69 |
#include <sys/types.h> |
|
70 |
#include <sys/socket.h> |
|
71 |
#include <sys/select.h> |
|
72 |
||
73 |
QT_BEGIN_NAMESPACE |
|
74 |
||
75 |
||
76 |
class QEventDispatcherSymbian; |
|
77 |
class QTimerActiveObject; |
|
78 |
||
79 |
class QActiveObject : public CActive |
|
80 |
{ |
|
81 |
public: |
|
82 |
QActiveObject(TInt priority, QEventDispatcherSymbian *dispatcher); |
|
83 |
~QActiveObject(); |
|
84 |
||
85 |
bool okToRun(); |
|
86 |
||
87 |
void reactivateAndComplete(); |
|
88 |
||
89 |
protected: |
|
90 |
QEventDispatcherSymbian *m_dispatcher; |
|
91 |
||
92 |
private: |
|
93 |
bool m_hasAlreadyRun : 1; |
|
94 |
bool m_hasRunAgain : 1; |
|
95 |
int m_iterationCount; |
|
96 |
}; |
|
97 |
||
98 |
class QWakeUpActiveObject : public CActive |
|
99 |
{ |
|
100 |
public: |
|
101 |
QWakeUpActiveObject(QEventDispatcherSymbian *dispatcher); |
|
102 |
~QWakeUpActiveObject(); |
|
103 |
||
104 |
void Complete(); |
|
105 |
||
106 |
protected: |
|
107 |
void DoCancel(); |
|
108 |
void RunL(); |
|
109 |
||
110 |
private: |
|
111 |
QEventDispatcherSymbian *m_dispatcher; |
|
112 |
}; |
|
113 |
||
114 |
struct SymbianTimerInfo : public QSharedData |
|
115 |
{ |
|
116 |
SymbianTimerInfo(); |
|
117 |
~SymbianTimerInfo(); |
|
118 |
||
119 |
int timerId; |
|
120 |
int interval; |
|
121 |
int msLeft; |
|
122 |
bool inTimerEvent; |
|
123 |
QObject *receiver; |
|
124 |
QTimerActiveObject *timerAO; |
|
125 |
QEventDispatcherSymbian *dispatcher; |
|
126 |
}; |
|
127 |
||
128 |
typedef QExplicitlySharedDataPointer<SymbianTimerInfo> SymbianTimerInfoPtr; |
|
129 |
||
130 |
// This is a bit of a proxy class. See comments in SetActive and Start for details. |
|
131 |
class QTimerActiveObject : public QActiveObject |
|
132 |
{ |
|
133 |
public: |
|
134 |
QTimerActiveObject(QEventDispatcherSymbian *dispatcher, SymbianTimerInfo *timerInfo); |
|
135 |
~QTimerActiveObject(); |
|
136 |
||
137 |
void Start(); |
|
138 |
||
139 |
protected: |
|
140 |
void DoCancel(); |
|
141 |
void RunL(); |
|
142 |
||
143 |
private: |
|
144 |
void Run(); |
|
145 |
void StartTimer(); |
|
146 |
||
147 |
private: |
|
148 |
SymbianTimerInfo *m_timerInfo; |
|
149 |
RTimer m_rTimer; |
|
150 |
}; |
|
151 |
||
152 |
class QCompleteDeferredAOs : public CActive |
|
153 |
{ |
|
154 |
public: |
|
155 |
QCompleteDeferredAOs(QEventDispatcherSymbian *dispatcher); |
|
156 |
~QCompleteDeferredAOs(); |
|
157 |
||
158 |
void complete(); |
|
159 |
||
160 |
protected: |
|
161 |
void DoCancel(); |
|
162 |
void RunL(); |
|
163 |
||
164 |
private: |
|
165 |
QEventDispatcherSymbian *m_dispatcher; |
|
166 |
}; |
|
167 |
||
168 |
class QSocketActiveObject : public QActiveObject |
|
169 |
{ |
|
170 |
public: |
|
171 |
QSocketActiveObject(QEventDispatcherSymbian *dispatcher, QSocketNotifier *notifier); |
|
172 |
~QSocketActiveObject(); |
|
173 |
||
174 |
void deleteLater(); |
|
175 |
||
176 |
protected: |
|
177 |
void DoCancel(); |
|
178 |
void RunL(); |
|
179 |
||
180 |
private: |
|
181 |
QSocketNotifier *m_notifier; |
|
182 |
bool m_inSocketEvent; |
|
183 |
bool m_deleteLater; |
|
184 |
||
185 |
friend class QEventDispatcherSymbian; |
|
186 |
}; |
|
187 |
||
188 |
class QSelectThread : public QThread |
|
189 |
{ |
|
190 |
Q_DECLARE_PRIVATE(QThread) |
|
191 |
||
192 |
public: |
|
193 |
QSelectThread(); |
|
194 |
~QSelectThread(); |
|
195 |
||
196 |
void requestSocketEvents ( QSocketNotifier *notifier, TRequestStatus *status ); |
|
197 |
void cancelSocketEvents ( QSocketNotifier *notifier ); |
|
198 |
void restart(); |
|
199 |
void stop(); |
|
200 |
||
201 |
protected: |
|
202 |
void run(); |
|
203 |
||
204 |
private: |
|
205 |
int updateSocketSet(QSocketNotifier::Type type, fd_set *fds); |
|
206 |
void updateActivatedNotifiers(QSocketNotifier::Type type, fd_set *fds); |
|
207 |
||
208 |
private: |
|
209 |
int m_pipeEnds[2]; |
|
210 |
QHash<QSocketNotifier *, TRequestStatus *> m_AOStatuses; |
|
211 |
QMutex m_mutex; |
|
212 |
QWaitCondition m_waitCond; |
|
213 |
bool m_quit; |
|
214 |
}; |
|
215 |
||
216 |
class Q_CORE_EXPORT CQtActiveScheduler : public CActiveScheduler |
|
217 |
{ |
|
218 |
public: // from CActiveScheduler |
|
219 |
virtual void Error(TInt aError) const; |
|
220 |
}; |
|
221 |
||
222 |
class Q_CORE_EXPORT QEventDispatcherSymbian : public QAbstractEventDispatcher |
|
223 |
{ |
|
224 |
Q_DECLARE_PRIVATE(QAbstractEventDispatcher) |
|
225 |
||
226 |
public: |
|
227 |
QEventDispatcherSymbian(QObject *parent = 0); |
|
228 |
~QEventDispatcherSymbian(); |
|
229 |
||
230 |
void flush(); |
|
231 |
bool hasPendingEvents(); |
|
232 |
void interrupt(); |
|
233 |
bool processEvents ( QEventLoop::ProcessEventsFlags flags ); |
|
234 |
void registerSocketNotifier ( QSocketNotifier * notifier ); |
|
235 |
void registerTimer ( int timerId, int interval, QObject * object ); |
|
236 |
QList<TimerInfo> registeredTimers ( QObject * object ) const; |
|
237 |
void unregisterSocketNotifier ( QSocketNotifier * notifier ); |
|
238 |
bool unregisterTimer ( int timerId ); |
|
239 |
bool unregisterTimers ( QObject * object ); |
|
240 |
void wakeUp(); |
|
241 |
||
242 |
void startingUp(); |
|
243 |
void closingDown(); |
|
244 |
||
245 |
void timerFired(int timerId); |
|
246 |
void socketFired(QSocketActiveObject *socketAO); |
|
247 |
void wakeUpWasCalled(); |
|
248 |
void reactivateSocketNotifier(QSocketNotifier *notifier); |
|
249 |
||
250 |
void addDeferredActiveObject(QActiveObject *object); |
|
251 |
void removeDeferredActiveObject(QActiveObject *object); |
|
252 |
void reactivateDeferredActiveObjects(); |
|
253 |
||
254 |
inline int iterationCount() const { return m_iterationCount; } |
|
255 |
||
256 |
static void RequestComplete(TRequestStatus *&status, TInt reason); |
|
257 |
static void RequestComplete(RThread &threadHandle, TRequestStatus *&status, TInt reason); |
|
258 |
||
259 |
private: |
|
260 |
bool sendPostedEvents(); |
|
261 |
bool sendDeferredSocketEvents(); |
|
262 |
||
263 |
private: |
|
264 |
QSelectThread m_selectThread; |
|
265 |
||
266 |
CQtActiveScheduler *m_activeScheduler; |
|
267 |
||
268 |
QHash<int, SymbianTimerInfoPtr> m_timerList; |
|
269 |
QHash<QSocketNotifier *, QSocketActiveObject *> m_notifiers; |
|
270 |
||
271 |
QWakeUpActiveObject *m_wakeUpAO; |
|
272 |
QCompleteDeferredAOs *m_completeDeferredAOs; |
|
273 |
||
274 |
volatile bool m_interrupt; |
|
275 |
QAtomicInt m_wakeUpDone; |
|
276 |
||
277 |
unsigned char m_iterationCount; |
|
278 |
bool m_noSocketEvents; |
|
279 |
QList<QSocketActiveObject *> m_deferredSocketEvents; |
|
280 |
||
281 |
QList<QActiveObject *> m_deferredActiveObjects; |
|
282 |
||
16
b25b6dc3ff8b
2010-17 8b4fb6db9a24f58dafbd4734d9c4a87a72f9ad8f
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
283 |
int m_delay; |
b25b6dc3ff8b
2010-17 8b4fb6db9a24f58dafbd4734d9c4a87a72f9ad8f
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
284 |
int m_avgEventTime; |
b25b6dc3ff8b
2010-17 8b4fb6db9a24f58dafbd4734d9c4a87a72f9ad8f
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
285 |
QTime m_lastIdleRequestTimer; |
0 | 286 |
}; |
287 |
||
288 |
#ifdef QT_DEBUG |
|
289 |
# define VERIFY_PENDING_REQUEST_STATUS \ |
|
290 |
Q_ASSERT(status->Int() == KRequestPending); |
|
291 |
#else |
|
292 |
# define VERIFY_PENDING_REQUEST_STATUS |
|
293 |
#endif |
|
294 |
||
295 |
// Convenience functions for doing some sanity checking on our own complete code. |
|
296 |
// Unless QT_DEBUG is defined, it is exactly equivalent to the Symbian version. |
|
297 |
inline void QEventDispatcherSymbian::RequestComplete(TRequestStatus *&status, TInt reason) |
|
298 |
{ |
|
299 |
VERIFY_PENDING_REQUEST_STATUS |
|
300 |
User::RequestComplete(status, reason); |
|
301 |
} |
|
302 |
inline void QEventDispatcherSymbian::RequestComplete(RThread &threadHandle, TRequestStatus *&status, TInt reason) |
|
303 |
{ |
|
304 |
VERIFY_PENDING_REQUEST_STATUS |
|
305 |
threadHandle.RequestComplete(status, reason); |
|
306 |
} |
|
307 |
||
308 |
#undef VERIFY_PENDING_REQUEST_STATUS |
|
309 |
||
310 |
QT_END_NAMESPACE |
|
311 |
||
312 |
#endif // QEVENTDISPATCHER_SYMBIAN_P_H |