source: trunk/src/corelib/kernel/qeventdispatcher_symbian_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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>
65#include <qdatetime.h>
66
67#include <e32base.h>
68
69#include <sys/types.h>
70#include <sys/socket.h>
71#include <sys/select.h>
72
73QT_BEGIN_NAMESPACE
74
75
76class QEventDispatcherSymbian;
77class QTimerActiveObject;
78
79class QActiveObject : public CActive
80{
81public:
82 QActiveObject(TInt priority, QEventDispatcherSymbian *dispatcher);
83 ~QActiveObject();
84
85 bool maybeQueueForLater();
86
87 void reactivateAndComplete();
88
89protected:
90 QEventDispatcherSymbian *m_dispatcher;
91
92private:
93 bool m_hasAlreadyRun : 1;
94 bool m_hasRunAgain : 1;
95 int m_iterationCount;
96};
97
98class QWakeUpActiveObject : public QActiveObject
99{
100public:
101 QWakeUpActiveObject(QEventDispatcherSymbian *dispatcher);
102 ~QWakeUpActiveObject();
103
104 void Complete();
105
106protected:
107 void DoCancel();
108 void RunL();
109};
110
111struct SymbianTimerInfo : public QSharedData
112{
113 SymbianTimerInfo();
114 ~SymbianTimerInfo();
115
116 int timerId;
117 int interval;
118 int msLeft;
119 bool inTimerEvent;
120 QObject *receiver;
121 QTimerActiveObject *timerAO;
122 QEventDispatcherSymbian *dispatcher;
123};
124
125typedef QExplicitlySharedDataPointer<SymbianTimerInfo> SymbianTimerInfoPtr;
126
127// This is a bit of a proxy class. See comments in SetActive and Start for details.
128class QTimerActiveObject : public QActiveObject
129{
130public:
131 QTimerActiveObject(QEventDispatcherSymbian *dispatcher, SymbianTimerInfo *timerInfo);
132 ~QTimerActiveObject();
133
134 void Start();
135
136protected:
137 void DoCancel();
138 void RunL();
139
140private:
141 void Run();
142 void StartTimer();
143
144private:
145 SymbianTimerInfo *m_timerInfo;
146 RTimer m_rTimer;
147};
148
149class QCompleteDeferredAOs : public CActive
150{
151public:
152 QCompleteDeferredAOs(QEventDispatcherSymbian *dispatcher);
153 ~QCompleteDeferredAOs();
154
155 void complete();
156
157protected:
158 void DoCancel();
159 void RunL();
160
161private:
162 QEventDispatcherSymbian *m_dispatcher;
163};
164
165class QSocketActiveObject : public QActiveObject
166{
167public:
168 QSocketActiveObject(QEventDispatcherSymbian *dispatcher, QSocketNotifier *notifier);
169 ~QSocketActiveObject();
170
171 void deleteLater();
172
173protected:
174 void DoCancel();
175 void RunL();
176
177private:
178 QSocketNotifier *m_notifier;
179 bool m_inSocketEvent;
180 bool m_deleteLater;
181
182 friend class QEventDispatcherSymbian;
183};
184
185class QSelectThread : public QThread
186{
187 Q_DECLARE_PRIVATE(QThread)
188
189public:
190 QSelectThread();
191 ~QSelectThread();
192
193 void requestSocketEvents ( QSocketNotifier *notifier, TRequestStatus *status );
194 void cancelSocketEvents ( QSocketNotifier *notifier );
195 void restart();
196 void stop();
197
198protected:
199 void run();
200
201private:
202 int updateSocketSet(QSocketNotifier::Type type, fd_set *fds);
203 void updateActivatedNotifiers(QSocketNotifier::Type type, fd_set *fds);
204
205private:
206 int m_pipeEnds[2];
207 QHash<QSocketNotifier *, TRequestStatus *> m_AOStatuses;
208 QMutex m_mutex;
209 QWaitCondition m_waitCond;
210 bool m_quit;
211};
212
213class Q_CORE_EXPORT CQtActiveScheduler : public CActiveScheduler
214{
215public: // from CActiveScheduler
216 virtual void Error(TInt aError) const;
217};
218
219class Q_CORE_EXPORT QEventDispatcherSymbian : public QAbstractEventDispatcher
220{
221 Q_OBJECT
222 Q_DECLARE_PRIVATE(QAbstractEventDispatcher)
223
224public:
225 QEventDispatcherSymbian(QObject *parent = 0);
226 ~QEventDispatcherSymbian();
227
228 void flush();
229 bool hasPendingEvents();
230 void interrupt();
231 bool processEvents ( QEventLoop::ProcessEventsFlags flags );
232 void registerSocketNotifier ( QSocketNotifier * notifier );
233 void registerTimer ( int timerId, int interval, QObject * object );
234 QList<TimerInfo> registeredTimers ( QObject * object ) const;
235 void unregisterSocketNotifier ( QSocketNotifier * notifier );
236 bool unregisterTimer ( int timerId );
237 bool unregisterTimers ( QObject * object );
238 void wakeUp();
239
240 void startingUp();
241 void closingDown();
242
243 void timerFired(int timerId);
244 void socketFired(QSocketActiveObject *socketAO);
245 void wakeUpWasCalled();
246 void reactivateSocketNotifier(QSocketNotifier *notifier);
247
248 void addDeferredActiveObject(QActiveObject *object);
249 void removeDeferredActiveObject(QActiveObject *object);
250 void queueDeferredActiveObjectsCompletion();
251 // Can be overridden to activate local active objects too, but do call baseclass!
252 virtual 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
259private:
260 bool sendPostedEvents();
261 bool sendDeferredSocketEvents();
262
263 QSelectThread& selectThread();
264private:
265 QSelectThread *m_selectThread;
266
267 CQtActiveScheduler *m_activeScheduler;
268
269 QHash<int, SymbianTimerInfoPtr> m_timerList;
270 QHash<QSocketNotifier *, QSocketActiveObject *> m_notifiers;
271
272 QWakeUpActiveObject *m_wakeUpAO;
273 QCompleteDeferredAOs *m_completeDeferredAOs;
274
275 volatile bool m_interrupt;
276 QAtomicInt m_wakeUpDone;
277
278 unsigned char m_iterationCount;
279 bool m_insideTimerEvent;
280 bool m_noSocketEvents;
281 QList<QSocketActiveObject *> m_deferredSocketEvents;
282
283 QList<QActiveObject *> m_deferredActiveObjects;
284
285 int m_delay;
286 int m_avgEventTime;
287 QTime m_lastIdleRequestTimer;
288};
289
290#ifdef QT_DEBUG
291# define VERIFY_PENDING_REQUEST_STATUS \
292 Q_ASSERT(status->Int() == KRequestPending);
293#else
294# define VERIFY_PENDING_REQUEST_STATUS
295#endif
296
297// Convenience functions for doing some sanity checking on our own complete code.
298// Unless QT_DEBUG is defined, it is exactly equivalent to the Symbian version.
299inline void QEventDispatcherSymbian::RequestComplete(TRequestStatus *&status, TInt reason)
300{
301 VERIFY_PENDING_REQUEST_STATUS
302 User::RequestComplete(status, reason);
303}
304inline void QEventDispatcherSymbian::RequestComplete(RThread &threadHandle, TRequestStatus *&status, TInt reason)
305{
306 VERIFY_PENDING_REQUEST_STATUS
307 threadHandle.RequestComplete(status, reason);
308}
309
310#undef VERIFY_PENDING_REQUEST_STATUS
311
312QT_END_NAMESPACE
313
314#endif // QEVENTDISPATCHER_SYMBIAN_P_H
Note: See TracBrowser for help on using the repository browser.