1/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#ifndef WAYLAND_CLIENT_CORE_H
27#define WAYLAND_CLIENT_CORE_H
28
29#include "wayland-util.h"
30#include "wayland-version.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/** \class wl_proxy
37 *
38 * \brief Represents a protocol object on the client side.
39 *
40 * A wl_proxy acts as a client side proxy to an object existing in the
41 * compositor. The proxy is responsible for converting requests made by the
42 * clients with \ref wl_proxy_marshal() into Wayland's wire format. Events
43 * coming from the compositor are also handled by the proxy, which will in
44 * turn call the handler set with \ref wl_proxy_add_listener().
45 *
46 * \note With the exception of function \ref wl_proxy_set_queue(), functions
47 * accessing a wl_proxy are not normally used by client code. Clients
48 * should normally use the higher level interface generated by the scanner to
49 * interact with compositor objects.
50 *
51 */
52struct wl_proxy;
53
54/** \class wl_display
55 *
56 * \brief Represents a connection to the compositor and acts as a proxy to
57 * the wl_display singleton object.
58 *
59 * A wl_display object represents a client connection to a Wayland
60 * compositor. It is created with either \ref wl_display_connect() or
61 * \ref wl_display_connect_to_fd(). A connection is terminated using
62 * \ref wl_display_disconnect().
63 *
64 * A wl_display is also used as the \ref wl_proxy for the wl_display
65 * singleton object on the compositor side.
66 *
67 * A wl_display object handles all the data sent from and to the
68 * compositor. When a \ref wl_proxy marshals a request, it will write its wire
69 * representation to the display's write buffer. The data is sent to the
70 * compositor when the client calls \ref wl_display_flush().
71 *
72 * Incoming data is handled in two steps: queueing and dispatching. In the
73 * queue step, the data coming from the display fd is interpreted and
74 * added to a queue. On the dispatch step, the handler for the incoming
75 * event set by the client on the corresponding \ref wl_proxy is called.
76 *
77 * A wl_display has at least one event queue, called the <em>default
78 * queue</em>. Clients can create additional event queues with \ref
79 * wl_display_create_queue() and assign \ref wl_proxy's to it. Events
80 * occurring in a particular proxy are always queued in its assigned queue.
81 * A client can ensure that a certain assumption, such as holding a lock
82 * or running from a given thread, is true when a proxy event handler is
83 * called by assigning that proxy to an event queue and making sure that
84 * this queue is only dispatched when the assumption holds.
85 *
86 * The default queue is dispatched by calling \ref wl_display_dispatch().
87 * This will dispatch any events queued on the default queue and attempt
88 * to read from the display fd if it's empty. Events read are then queued
89 * on the appropriate queues according to the proxy assignment.
90 *
91 * A user created queue is dispatched with \ref wl_display_dispatch_queue().
92 * This function behaves exactly the same as wl_display_dispatch()
93 * but it dispatches given queue instead of the default queue.
94 *
95 * A real world example of event queue usage is Mesa's implementation of
96 * eglSwapBuffers() for the Wayland platform. This function might need
97 * to block until a frame callback is received, but dispatching the default
98 * queue could cause an event handler on the client to start drawing
99 * again. This problem is solved using another event queue, so that only
100 * the events handled by the EGL code are dispatched during the block.
101 *
102 * This creates a problem where a thread dispatches a non-default
103 * queue, reading all the data from the display fd. If the application
104 * would call \em poll(2) after that it would block, even though there
105 * might be events queued on the default queue. Those events should be
106 * dispatched with \ref wl_display_dispatch_pending() or \ref
107 * wl_display_dispatch_queue_pending() before flushing and blocking.
108 */
109struct wl_display;
110
111/** \class wl_event_queue
112 *
113 * \brief A queue for \ref wl_proxy object events.
114 *
115 * Event queues allows the events on a display to be handled in a thread-safe
116 * manner. See \ref wl_display for details.
117 *
118 */
119struct wl_event_queue;
120
121void
122wl_event_queue_destroy(struct wl_event_queue *queue);
123
124void
125wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
126
127void
128wl_proxy_marshal_array(struct wl_proxy *p, uint32_t opcode,
129 union wl_argument *args);
130
131struct wl_proxy *
132wl_proxy_create(struct wl_proxy *factory,
133 const struct wl_interface *interface);
134
135void *
136wl_proxy_create_wrapper(void *proxy);
137
138void
139wl_proxy_wrapper_destroy(void *proxy_wrapper);
140
141struct wl_proxy *
142wl_proxy_marshal_constructor(struct wl_proxy *proxy,
143 uint32_t opcode,
144 const struct wl_interface *interface,
145 ...);
146
147struct wl_proxy *
148wl_proxy_marshal_constructor_versioned(struct wl_proxy *proxy,
149 uint32_t opcode,
150 const struct wl_interface *interface,
151 uint32_t version,
152 ...);
153struct wl_proxy *
154wl_proxy_marshal_array_constructor(struct wl_proxy *proxy,
155 uint32_t opcode, union wl_argument *args,
156 const struct wl_interface *interface);
157struct wl_proxy *
158wl_proxy_marshal_array_constructor_versioned(struct wl_proxy *proxy,
159 uint32_t opcode,
160 union wl_argument *args,
161 const struct wl_interface *interface,
162 uint32_t version);
163
164void
165wl_proxy_destroy(struct wl_proxy *proxy);
166
167int
168wl_proxy_add_listener(struct wl_proxy *proxy,
169 void (**implementation)(void), void *data);
170
171const void *
172wl_proxy_get_listener(struct wl_proxy *proxy);
173
174int
175wl_proxy_add_dispatcher(struct wl_proxy *proxy,
176 wl_dispatcher_func_t dispatcher_func,
177 const void * dispatcher_data, void *data);
178
179void
180wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
181
182void *
183wl_proxy_get_user_data(struct wl_proxy *proxy);
184
185uint32_t
186wl_proxy_get_version(struct wl_proxy *proxy);
187
188uint32_t
189wl_proxy_get_id(struct wl_proxy *proxy);
190
191const char *
192wl_proxy_get_class(struct wl_proxy *proxy);
193
194void
195wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue);
196
197struct wl_display *
198wl_display_connect(const char *name);
199
200struct wl_display *
201wl_display_connect_to_fd(int fd);
202
203void
204wl_display_disconnect(struct wl_display *display);
205
206int
207wl_display_get_fd(struct wl_display *display);
208
209int
210wl_display_dispatch(struct wl_display *display);
211
212int
213wl_display_dispatch_queue(struct wl_display *display,
214 struct wl_event_queue *queue);
215
216int
217wl_display_dispatch_queue_pending(struct wl_display *display,
218 struct wl_event_queue *queue);
219
220int
221wl_display_dispatch_pending(struct wl_display *display);
222
223int
224wl_display_get_error(struct wl_display *display);
225
226uint32_t
227wl_display_get_protocol_error(struct wl_display *display,
228 const struct wl_interface **interface,
229 uint32_t *id);
230
231int
232wl_display_flush(struct wl_display *display);
233
234int
235wl_display_roundtrip_queue(struct wl_display *display,
236 struct wl_event_queue *queue);
237
238int
239wl_display_roundtrip(struct wl_display *display);
240
241struct wl_event_queue *
242wl_display_create_queue(struct wl_display *display);
243
244int
245wl_display_prepare_read_queue(struct wl_display *display,
246 struct wl_event_queue *queue);
247
248int
249wl_display_prepare_read(struct wl_display *display);
250
251void
252wl_display_cancel_read(struct wl_display *display);
253
254int
255wl_display_read_events(struct wl_display *display);
256
257void
258wl_log_set_handler_client(wl_log_func_t handler);
259
260#ifdef __cplusplus
261}
262#endif
263
264#endif
265