Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qeventdispatcher_wasm_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QEVENTDISPATCHER_WASM_P_H
5#define QEVENTDISPATCHER_WASM_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19#include "private/qtimerinfo_unix_p.h"
20#include <QtCore/qloggingcategory.h>
21#include <QtCore/qwaitcondition.h>
22
23#include <chrono>
24#include <mutex>
25#include <optional>
26#include <tuple>
27
28#include <emscripten/proxying.h>
29
31
32Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher);
33Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcherTimers)
34
36{
38public:
41
42 bool processEvents(QEventLoop::ProcessEventsFlags flags) override;
43
44 void registerSocketNotifier(QSocketNotifier *notifier) override;
45 void unregisterSocketNotifier(QSocketNotifier *notifier) override;
46
47 void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType,
48 QObject *object) override final;
49 bool unregisterTimer(Qt::TimerId timerId) override final;
50 bool unregisterTimers(QObject *object) override final;
51 QList<TimerInfoV2> timersForObject(QObject *object) const override final;
52 Duration remainingTime(Qt::TimerId timerId) const override final;
53
54 void interrupt() override;
55 void wakeUp() override;
56
57 static void runOnMainThread(std::function<void(void)> fn);
58 static void socketSelect(int timeout, int socket, bool waitForRead, bool waitForWrite,
59 bool *selectForRead, bool *selectForWrite, bool *socketDisconnect);
60
61 static void registerStartupTask();
62 static void completeStarupTask();
63 static void callOnLoadedIfRequired();
64 virtual void onLoaded();
65
66protected:
67 virtual bool processPostedEvents();
68
69private:
70 bool isMainThreadEventDispatcher();
71 bool isSecondaryThreadEventDispatcher();
72 static bool isValidEventDispatcherPointer(QEventDispatcherWasm *eventDispatcher);
73
74 void handleApplicationExec();
75 void handleDialogExec();
76 bool wait(int timeout = -1);
77 bool wakeEventDispatcherThread();
78 static void callProcessPostedEvents(void *eventDispatcher);
79
80 void processTimers();
81 void updateNativeTimer();
82 static void callProcessTimers(void *eventDispatcher);
83
84 static void setEmscriptenSocketCallbacks();
85 static void clearEmscriptenSocketCallbacks();
86 static void socketError(int fd, int err, const char* msg, void *context);
87 static void socketOpen(int fd, void *context);
88 static void socketListen(int fd, void *context);
89 static void socketConnection(int fd, void *context);
90 static void socketMessage(int fd, void *context);
91 static void socketClose(int fd, void *context);
92
93 static void setSocketState(int socket, bool setReadyRead, bool setReadyWrite);
94 static void clearSocketState(int socket);
95 void waitForSocketState(int timeout, int socket, bool checkRead, bool checkWrite,
96 bool *selectForRead, bool *selectForWrite, bool *socketDisconnect);
97
98 static void run(std::function<void(void)> fn);
99 static void runAsync(std::function<void(void)> fn);
100 static void runOnMainThreadAsync(std::function<void(void)> fn);
101
102 static QEventDispatcherWasm *g_mainThreadEventDispatcher;
103
104 bool m_interrupted = false;
105 bool m_processTimers = false;
106 bool m_pendingProcessEvents = false;
107
108 QTimerInfoList *m_timerInfo = new QTimerInfoList();
109 long m_timerId = 0;
110 std::chrono::milliseconds m_timerTargetTime{};
111
112#if QT_CONFIG(thread)
113 std::mutex m_mutex;
114 bool m_wakeUpCalled = false;
115 std::condition_variable m_moreEvents;
116
117 static QVector<QEventDispatcherWasm *> g_secondaryThreadEventDispatchers;
118 static std::mutex g_staticDataMutex;
119 static emscripten::ProxyingQueue g_proxyingQueue;
120 static pthread_t g_mainThread;
121
122 // Note on mutex usage: the global g_staticDataMutex protects the global (g_ prefixed) data,
123 // while the per eventdispatcher m_mutex protects the state accociated with blocking and waking
124 // that eventdispatcher thread. The locking order is g_staticDataMutex first, then m_mutex.
125#endif
126
127 static std::multimap<int, QSocketNotifier *> g_socketNotifiers;
128
129 struct SocketReadyState {
130 QEventDispatcherWasm *waiter = nullptr;
131 bool waitForReadyRead = false;
132 bool waitForReadyWrite = false;
133 bool readyRead = false;
134 bool readyWrite = false;
135 };
136 static std::map<int, SocketReadyState> g_socketState;
137};
138
139#endif // QEVENTDISPATCHER_WASM_P_H
DarwinBluetooth::LECBManagerNotifier * notifier
std::chrono::nanoseconds Duration
A {std::chrono::duration} type that is used in various API in this class.
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
Combined button and popup list for selecting options.
TimerType
static void * context
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLbitfield GLuint64 timeout
[4]
GLbitfield flags
GLuint64 GLenum GLint fd
#define Q_OBJECT
device waitForReadyRead(deadline)
QTcpSocket * socket
[1]
socketLayer waitForWrite()