Changeset View
Changeset View
Standalone View
Standalone View
src/client/remote_access.h
- This file was added.
1 | /**************************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Oleg Chernovskiy <kanedias@xaker.ru> | ||||
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 KWAYLAND_CLIENT_REMOTE_ACCESS_H | ||||
21 | #define KWAYLAND_CLIENT_REMOTE_ACCESS_H | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | | ||||
25 | #include <KWayland/Client/kwaylandclient_export.h> | ||||
26 | | ||||
27 | struct org_kde_kwin_remote_access_manager; | ||||
28 | struct org_kde_kwin_remote_buffer; | ||||
29 | | ||||
30 | namespace KWayland | ||||
31 | { | ||||
32 | namespace Client | ||||
33 | { | ||||
34 | | ||||
35 | class EventQueue; | ||||
36 | class RemoteBuffer; | ||||
37 | | ||||
38 | /** | ||||
39 | * @short Wrapper for the org_kde_kwin_remote_access_manager interface. | ||||
40 | * | ||||
41 | * This class provides a convenient wrapper for the org_kde_kwin_remote_access_manager interface. | ||||
42 | * | ||||
43 | * To use this class one needs to interact with the Registry. There are two | ||||
44 | * possible ways to create the RemoteAccessManager interface: | ||||
45 | * @code | ||||
46 | * RemoteAccessManager *c = registry->createRemoteAccessManager(name, version); | ||||
47 | * @endcode | ||||
48 | * | ||||
49 | * This creates the RemoteAccessManager and sets it up directly. As an alternative this | ||||
50 | * can also be done in a more low level way: | ||||
51 | * @code | ||||
52 | * RemoteAccessManager *c = new RemoteAccessManager; | ||||
53 | * c->setup(registry->bindRemoteAccessManager(name, version)); | ||||
54 | * @endcode | ||||
55 | * | ||||
56 | * The RemoteAccessManager can be used as a drop-in replacement for any org_kde_kwin_remote_access_manager | ||||
57 | * pointer as it provides matching cast operators. | ||||
58 | * | ||||
59 | * @see Registry | ||||
60 | **/ | ||||
61 | class KWAYLANDCLIENT_EXPORT RemoteAccessManager : public QObject | ||||
62 | { | ||||
63 | Q_OBJECT | ||||
64 | public: | ||||
65 | /** | ||||
66 | * Creates a new RemoteAccessManager. | ||||
67 | * Note: after constructing the RemoteAccessManager it is not yet valid and one needs | ||||
68 | * to call setup. In order to get a ready to use RemoteAccessManager prefer using | ||||
69 | * Registry::createRemoteAccessManager. | ||||
70 | **/ | ||||
71 | explicit RemoteAccessManager(QObject *parent = nullptr); | ||||
72 | virtual ~RemoteAccessManager(); | ||||
73 | | ||||
74 | /** | ||||
75 | * Setup this RemoteAccessManager to manage the @p remoteaccessmanager. | ||||
76 | * When using Registry::createRemoteAccessManager there is no need to call this | ||||
77 | * method. | ||||
78 | **/ | ||||
79 | void setup(org_kde_kwin_remote_access_manager *remoteaccessmanager); | ||||
80 | /** | ||||
81 | * @returns @c true if managing a org_kde_kwin_remote_access_manager. | ||||
82 | **/ | ||||
83 | bool isValid() const; | ||||
84 | /** | ||||
85 | * Releases the org_kde_kwin_remote_access_manager interface. | ||||
86 | * After the interface has been released the RemoteAccessManager instance is no | ||||
87 | * longer valid and can be setup with another org_kde_kwin_remote_access_manager interface. | ||||
88 | **/ | ||||
89 | void release(); | ||||
90 | /** | ||||
91 | * Destroys the data held by this RemoteAccessManager. | ||||
92 | * This method is supposed to be used when the connection to the Wayland | ||||
93 | * server goes away. If the connection is not valid anymore, it's not | ||||
94 | * possible to call release anymore as that calls into the Wayland | ||||
95 | * connection and the call would fail. This method cleans up the data, so | ||||
96 | * that the instance can be deleted or set up to a new org_kde_kwin_remote_access_manager interface | ||||
97 | * once there is a new connection available. | ||||
98 | * | ||||
99 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
100 | * @code | ||||
101 | * connect(connection, &ConnectionThread::connectionDied, remoteaccessmanager, &RemoteAccessManager::destroy); | ||||
102 | * @endcode | ||||
103 | * | ||||
104 | * @see release | ||||
105 | **/ | ||||
106 | void destroy(); | ||||
107 | | ||||
108 | /** | ||||
109 | * Sets the @p queue to use for creating objects with this RemoteAccessManager. | ||||
110 | **/ | ||||
111 | void setEventQueue(EventQueue *queue); | ||||
112 | /** | ||||
113 | * @returns The event queue to use for creating objects with this RemoteAccessManager. | ||||
114 | **/ | ||||
115 | EventQueue *eventQueue(); | ||||
116 | | ||||
117 | operator org_kde_kwin_remote_access_manager*(); | ||||
118 | operator org_kde_kwin_remote_access_manager*() const; | ||||
119 | | ||||
120 | Q_SIGNALS: | ||||
121 | /** | ||||
122 | * The corresponding global for this interface on the Registry got removed. | ||||
123 | * | ||||
124 | * This signal gets only emitted if the RemoteAccessManager got created by | ||||
125 | * Registry::createRemoteAccessManager | ||||
126 | **/ | ||||
127 | void removed(); | ||||
128 | | ||||
129 | /** | ||||
130 | * Buffer from server is ready to be delivered to this client | ||||
131 | * @param buffer_id internal buffer id to be created | ||||
132 | **/ | ||||
133 | void bufferReady(RemoteBuffer *rbuf); | ||||
134 | | ||||
135 | private: | ||||
136 | class Private; | ||||
137 | QScopedPointer<Private> d; | ||||
138 | }; | ||||
139 | | ||||
140 | /** | ||||
141 | * @short Wrapper for org_kde_kwin_remote_buffer interface. | ||||
142 | * The instances of this class are created by parent RemoteAccessManager. | ||||
143 | * Deletion (by noLongerNeeded call) is in responsibility of underlying system. | ||||
144 | */ | ||||
145 | class KWAYLANDCLIENT_EXPORT RemoteBuffer : public QObject | ||||
146 | { | ||||
147 | Q_OBJECT | ||||
148 | public: | ||||
149 | virtual ~RemoteBuffer(); | ||||
150 | /** | ||||
151 | * Setup this RemoteBuffer to manage the @p remotebuffer. | ||||
152 | **/ | ||||
153 | void setup(org_kde_kwin_remote_buffer *remotebuffer); | ||||
154 | /** | ||||
155 | * @returns @c true if managing a org_kde_kwin_remote_buffer. | ||||
156 | **/ | ||||
157 | bool isValid() const; | ||||
158 | /** | ||||
159 | * Releases the org_kde_kwin_remote_buffer interface. | ||||
160 | * After the interface has been released the RemoteBuffer instance is no | ||||
161 | * longer valid and can be setup with another org_kde_kwin_remote_buffer interface. | ||||
162 | **/ | ||||
163 | void release(); | ||||
164 | /** | ||||
165 | * Destroys the data held by this RemoteBuffer. | ||||
166 | * This method is supposed to be used when the connection to the Wayland | ||||
167 | * server goes away. If the connection is not valid anymore, it's not | ||||
168 | * possible to call release anymore as that calls into the Wayland | ||||
169 | * connection and the call would fail. This method cleans up the data, so | ||||
170 | * that the instance can be deleted or set up to a new org_kde_kwin_remote_buffer interface | ||||
171 | * once there is a new connection available. | ||||
172 | * | ||||
173 | * It is suggested to connect this method to ConnectionThread::connectionDied: | ||||
174 | * @code | ||||
175 | * connect(connection, &ConnectionThread::connectionDied, remotebuffer, &RemoteBuffer::destroy); | ||||
176 | * @endcode | ||||
177 | * | ||||
178 | * @see release | ||||
179 | **/ | ||||
180 | void destroy(); | ||||
181 | | ||||
182 | operator org_kde_kwin_remote_buffer*(); | ||||
183 | operator org_kde_kwin_remote_buffer*() const; | ||||
184 | | ||||
185 | qint32 fd(); | ||||
186 | quint32 width(); | ||||
187 | quint32 height(); | ||||
188 | quint32 stride(); | ||||
189 | quint32 format(); | ||||
190 | | ||||
191 | | ||||
192 | Q_SIGNALS: | ||||
193 | void parametersObtained(); | ||||
194 | | ||||
195 | private: | ||||
196 | | ||||
197 | friend class RemoteAccessManager; | ||||
198 | explicit RemoteBuffer(QObject *parent = nullptr); | ||||
199 | class Private; | ||||
200 | QScopedPointer<Private> d; | ||||
201 | }; | ||||
202 | | ||||
203 | | ||||
204 | } | ||||
205 | } | ||||
206 | | ||||
207 | #endif |