1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QABSTRACTEVENTDISPATCHER_H
5#define QABSTRACTEVENTDISPATCHER_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qeventloop.h>
9
10QT_BEGIN_NAMESPACE
11
12class QAbstractNativeEventFilter;
13class QAbstractEventDispatcherPrivate;
14class QSocketNotifier;
15
16class Q_CORE_EXPORT QAbstractEventDispatcher : public QObject
17{
18 Q_OBJECT
19 Q_DECLARE_PRIVATE(QAbstractEventDispatcher)
20
21public:
22 struct TimerInfo
23 {
24 int timerId;
25 int interval;
26 Qt::TimerType timerType;
27
28 inline TimerInfo(int id, int i, Qt::TimerType t)
29 : timerId(id), interval(i), timerType(t) { }
30 };
31
32 explicit QAbstractEventDispatcher(QObject *parent = nullptr);
33 ~QAbstractEventDispatcher();
34
35 static QAbstractEventDispatcher *instance(QThread *thread = nullptr);
36
37 virtual bool processEvents(QEventLoop::ProcessEventsFlags flags) = 0;
38
39 virtual void registerSocketNotifier(QSocketNotifier *notifier) = 0;
40 virtual void unregisterSocketNotifier(QSocketNotifier *notifier) = 0;
41
42 int registerTimer(qint64 interval, Qt::TimerType timerType, QObject *object);
43 virtual void registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object) = 0;
44 virtual bool unregisterTimer(int timerId) = 0;
45 virtual bool unregisterTimers(QObject *object) = 0;
46 virtual QList<TimerInfo> registeredTimers(QObject *object) const = 0;
47
48 virtual int remainingTime(int timerId) = 0;
49
50 virtual void wakeUp() = 0;
51 virtual void interrupt() = 0;
52
53 virtual void startingUp();
54 virtual void closingDown();
55
56 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
57 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
58 bool filterNativeEvent(const QByteArray &eventType, void *message, qintptr *result);
59
60Q_SIGNALS:
61 void aboutToBlock();
62 void awake();
63
64protected:
65 QAbstractEventDispatcher(QAbstractEventDispatcherPrivate &,
66 QObject *parent);
67};
68
69Q_DECLARE_TYPEINFO(QAbstractEventDispatcher::TimerInfo, Q_PRIMITIVE_TYPE);
70
71QT_END_NAMESPACE
72
73#endif // QABSTRACTEVENTDISPATCHER_H
74

source code of qtbase/src/corelib/kernel/qabstracteventdispatcher.h