Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qeventdispatcher_unix_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
4
5#ifndef QEVENTDISPATCHER_UNIX_P_H
6#define QEVENTDISPATCHER_UNIX_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "QtCore/qabstracteventdispatcher.h"
20#include "QtCore/qlist.h"
21#include "private/qabstracteventdispatcher_p.h"
22#include "private/qcore_unix_p.h"
23#include "QtCore/qvarlengtharray.h"
24#include "QtCore/qhash.h"
25#include "private/qtimerinfo_unix_p.h"
26
28
29class QEventDispatcherUNIXPrivate;
30
31struct Q_CORE_EXPORT QSocketNotifierSetUNIX final
32{
33 inline QSocketNotifierSetUNIX() noexcept;
34
35 inline bool isEmpty() const noexcept;
36 inline short events() const noexcept;
37
38 QSocketNotifier *notifiers[3];
39};
40
41Q_DECLARE_TYPEINFO(QSocketNotifierSetUNIX, Q_PRIMITIVE_TYPE);
42
44{
46 ~QThreadPipe();
47
48 bool init();
49 pollfd prepare() const;
50
51 void wakeUp();
52 int check(const pollfd &pfd);
53
54 // note for eventfd(7) support:
55 // fds[0] stores the eventfd, fds[1] is unused
56 int fds[2] = { -1, -1 };
58
59#if defined(Q_OS_VXWORKS)
60 static constexpr int len_name = 20;
61 char name[len_name] = {};
62#endif
63};
64
65class Q_CORE_EXPORT QEventDispatcherUNIX : public QAbstractEventDispatcherV2
66{
67 Q_OBJECT
68 Q_DECLARE_PRIVATE(QEventDispatcherUNIX)
69
70public:
71 explicit QEventDispatcherUNIX(QObject *parent = nullptr);
72 ~QEventDispatcherUNIX();
73
74 bool processEvents(QEventLoop::ProcessEventsFlags flags) override;
75
76 void registerSocketNotifier(QSocketNotifier *notifier) final;
77 void unregisterSocketNotifier(QSocketNotifier *notifier) final;
78
79 void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType,
80 QObject *object) override final;
81 bool unregisterTimer(Qt::TimerId timerId) override final;
82 bool unregisterTimers(QObject *object) override final;
83 QList<TimerInfoV2> timersForObject(QObject *object) const override final;
84 Duration remainingTime(Qt::TimerId timerId) const override final;
85
86 void wakeUp() override;
87 void interrupt() final;
88
89protected:
90 QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent = nullptr);
91};
92
93class Q_CORE_EXPORT QEventDispatcherUNIXPrivate : public QAbstractEventDispatcherPrivate
94{
95 Q_DECLARE_PUBLIC(QEventDispatcherUNIX)
96
97public:
98 QEventDispatcherUNIXPrivate();
99 ~QEventDispatcherUNIXPrivate();
100
101 int activateTimers();
102
103 void markPendingSocketNotifiers();
104 int activateSocketNotifiers();
105 void setSocketNotifierPending(QSocketNotifier *notifier);
106
107 QThreadPipe threadPipe;
108 QList<pollfd> pollfds;
109
110 QHash<int, QSocketNotifierSetUNIX> socketNotifiers;
111 QList<QSocketNotifier *> pendingNotifiers;
112
113 QTimerInfoList timerList;
114 QAtomicInt interrupt; // bool
115};
116
117inline QSocketNotifierSetUNIX::QSocketNotifierSetUNIX() noexcept
118{
119 notifiers[0] = nullptr;
120 notifiers[1] = nullptr;
121 notifiers[2] = nullptr;
122}
123
124inline bool QSocketNotifierSetUNIX::isEmpty() const noexcept
125{
126 return !notifiers[0] && !notifiers[1] && !notifiers[2];
127}
128
129inline short QSocketNotifierSetUNIX::events() const noexcept
130{
131 short result = 0;
132
133 if (notifiers[0])
134 result |= POLLIN;
135
136 if (notifiers[1])
137 result |= POLLOUT;
138
139 if (notifiers[2])
140 result |= POLLPRI;
141
142 return result;
143}
144
145QT_END_NAMESPACE
146
147#endif // QEVENTDISPATCHER_UNIX_P_H
Combined button and popup list for selecting options.
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
#define __has_include(x)
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
int check(const pollfd &pfd)
pollfd prepare() const