GCC Code Coverage Report


Directory: ./
File: src/client/event_queue.h
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /********************************************************************
2 Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #ifndef WAYLAND_EVENT_QUEUE_H
21 #define WAYLAND_EVENT_QUEUE_H
22
23 #include <QObject>
24 // STD
25 #include <memory>
26
27 #include <Wrapland/Client/wraplandclient_export.h>
28
29 struct wl_display;
30 struct wl_proxy;
31 struct wl_event_queue;
32
33 namespace Wrapland
34 {
35 namespace Client
36 {
37
38 class ConnectionThread;
39
40 /**
41 * @short Wrapper class for wl_event_queue interface.
42 *
43 * The EventQueue is needed if a different thread is used for the connection.
44 * If the interface wrappers are held in a different thread than the connection thread
45 * an EventQueue is needed for the thread which holds the interface wrappers. A common
46 * example is a dedicated connection thread while the interface wrappers are created
47 * in the main thread.
48 *
49 * All interface wrappers are set up to support the EventQueue in the most convenient
50 * way. The EventQueue needs only to be passed to the Registry. The EventQueue will then
51 * be passed to all created wrappers through the tree.
52 *
53 * @code
54 * ConnectionThread connection;
55 * EventQueue queue;
56 * Registry registry;
57 *
58 * connect(&connection, &ConnectionThread::connected, this, [&] {
59 * queue.setup(&connection);
60 * registry.setEventQueue(&queue);
61 * registry.setup(&connection);
62 * registry.create();
63 * });
64 *
65 * connection.initConnection();
66 * @endcode
67 *
68 * The EventQueue can be used as a drop-in replacement for any wl_event_queue
69 * pointer as it provides matching cast operators.
70 **/
71 class WRAPLANDCLIENT_EXPORT EventQueue : public QObject
72 {
73 Q_OBJECT
74 public:
75 explicit EventQueue(QObject* parent = nullptr);
76 virtual ~EventQueue();
77
78 /**
79 * Creates the event queue for the @p display.
80 *
81 * Note: this will not automatically setup the dispatcher.
82 * When using this method one needs to ensure that dispatch
83 * gets invoked whenever new events need to be dispatched.
84 * @see dispatch
85 **/
86 void setup(wl_display* display);
87 /**
88 * Creates the event queue for the @p connection.
89 *
90 * This method also connects the eventsRead signal of the ConnectionThread
91 * to the dispatch method. Events will be automatically dispatched without
92 * the need to call dispatch manually.
93 * @see dispatch
94 **/
95 void setup(ConnectionThread* connection);
96
97 /**
98 * @returns @c true if EventQueue is setup.
99 **/
100 bool isValid();
101 /**
102 * Releases the wl_event_queue interface.
103 * After the interface has been released the EventQueue instance is no
104 * longer valid and can be setup with another wl_event_queue interface.
105 **/
106 void release();
107
108 /**
109 * Adds the @p proxy to the EventQueue.
110 **/
111 void addProxy(wl_proxy* proxy);
112 /**
113 * Adds the @p proxy of type wl_interface (e.g. wl_compositor) to the EventQueue.
114 **/
115 template<typename wl_interface>
116 void addProxy(wl_interface* proxy);
117 /**
118 * Adds the @p proxy wrapper class of type T referencing the wl_interface to the EventQueue.
119 **/
120 template<typename wl_interface, typename T>
121 void addProxy(T* proxy);
122
123 operator wl_event_queue*();
124 operator wl_event_queue*() const;
125
126 public Q_SLOTS:
127 /**
128 * Dispatches all pending events on the EventQueue.
129 **/
130 void dispatch();
131
132 private:
133 class Private;
134 std::unique_ptr<Private> d;
135 };
136
137 template<typename wl_interface>
138 3279 inline void EventQueue::addProxy(wl_interface* proxy)
139 {
140 3279 addProxy(reinterpret_cast<wl_proxy*>(proxy));
141 3279 }
142
143 template<typename wl_interface, typename T>
144 inline void EventQueue::addProxy(T* proxy)
145 {
146 addProxy(reinterpret_cast<wl_proxy*>((wl_interface*)*(proxy)));
147 }
148
149 }
150 }
151
152 #endif
153