| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 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 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 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)) && !defined(Q_OS_NACL) |
| 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 |
| 80 |
QTimerInfo **activateRef; // - ref from activateTimers |
| 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() |
| 95 |
QTimerInfo *firstTimerInfo; |
| 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 |