xref: /aosp_15_r20/external/wayland/src/wayland-server-core.h (revision 84e872a0dc482bffdb63672969dd03a827d67c73)
1*84e872a0SLloyd Pique /*
2*84e872a0SLloyd Pique  * Copyright © 2008 Kristian Høgsberg
3*84e872a0SLloyd Pique  *
4*84e872a0SLloyd Pique  * Permission is hereby granted, free of charge, to any person obtaining
5*84e872a0SLloyd Pique  * a copy of this software and associated documentation files (the
6*84e872a0SLloyd Pique  * "Software"), to deal in the Software without restriction, including
7*84e872a0SLloyd Pique  * without limitation the rights to use, copy, modify, merge, publish,
8*84e872a0SLloyd Pique  * distribute, sublicense, and/or sell copies of the Software, and to
9*84e872a0SLloyd Pique  * permit persons to whom the Software is furnished to do so, subject to
10*84e872a0SLloyd Pique  * the following conditions:
11*84e872a0SLloyd Pique  *
12*84e872a0SLloyd Pique  * The above copyright notice and this permission notice (including the
13*84e872a0SLloyd Pique  * next paragraph) shall be included in all copies or substantial
14*84e872a0SLloyd Pique  * portions of the Software.
15*84e872a0SLloyd Pique  *
16*84e872a0SLloyd Pique  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17*84e872a0SLloyd Pique  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18*84e872a0SLloyd Pique  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19*84e872a0SLloyd Pique  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20*84e872a0SLloyd Pique  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21*84e872a0SLloyd Pique  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22*84e872a0SLloyd Pique  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23*84e872a0SLloyd Pique  * SOFTWARE.
24*84e872a0SLloyd Pique  */
25*84e872a0SLloyd Pique 
26*84e872a0SLloyd Pique #ifndef WAYLAND_SERVER_CORE_H
27*84e872a0SLloyd Pique #define WAYLAND_SERVER_CORE_H
28*84e872a0SLloyd Pique 
29*84e872a0SLloyd Pique #include <sys/types.h>
30*84e872a0SLloyd Pique #include <stdint.h>
31*84e872a0SLloyd Pique #include <stdbool.h>
32*84e872a0SLloyd Pique #include "wayland-util.h"
33*84e872a0SLloyd Pique #include "wayland-version.h"
34*84e872a0SLloyd Pique 
35*84e872a0SLloyd Pique #ifdef  __cplusplus
36*84e872a0SLloyd Pique extern "C" {
37*84e872a0SLloyd Pique #endif
38*84e872a0SLloyd Pique 
39*84e872a0SLloyd Pique enum {
40*84e872a0SLloyd Pique 	WL_EVENT_READABLE = 0x01,
41*84e872a0SLloyd Pique 	WL_EVENT_WRITABLE = 0x02,
42*84e872a0SLloyd Pique 	WL_EVENT_HANGUP   = 0x04,
43*84e872a0SLloyd Pique 	WL_EVENT_ERROR    = 0x08
44*84e872a0SLloyd Pique };
45*84e872a0SLloyd Pique 
46*84e872a0SLloyd Pique /** File descriptor dispatch function type
47*84e872a0SLloyd Pique  *
48*84e872a0SLloyd Pique  * Functions of this type are used as callbacks for file descriptor events.
49*84e872a0SLloyd Pique  *
50*84e872a0SLloyd Pique  * \param fd The file descriptor delivering the event.
51*84e872a0SLloyd Pique  * \param mask Describes the kind of the event as a bitwise-or of:
52*84e872a0SLloyd Pique  * \c WL_EVENT_READABLE, \c WL_EVENT_WRITABLE, \c WL_EVENT_HANGUP,
53*84e872a0SLloyd Pique  * \c WL_EVENT_ERROR.
54*84e872a0SLloyd Pique  * \param data The user data argument of the related wl_event_loop_add_fd()
55*84e872a0SLloyd Pique  * call.
56*84e872a0SLloyd Pique  * \return If the event source is registered for re-check with
57*84e872a0SLloyd Pique  * wl_event_source_check(): 0 for all done, 1 for needing a re-check.
58*84e872a0SLloyd Pique  * If not registered, the return value is ignored and should be zero.
59*84e872a0SLloyd Pique  *
60*84e872a0SLloyd Pique  * \sa wl_event_loop_add_fd()
61*84e872a0SLloyd Pique  * \memberof wl_event_source
62*84e872a0SLloyd Pique  */
63*84e872a0SLloyd Pique typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
64*84e872a0SLloyd Pique 
65*84e872a0SLloyd Pique /** Timer dispatch function type
66*84e872a0SLloyd Pique  *
67*84e872a0SLloyd Pique  * Functions of this type are used as callbacks for timer expiry.
68*84e872a0SLloyd Pique  *
69*84e872a0SLloyd Pique  * \param data The user data argument of the related wl_event_loop_add_timer()
70*84e872a0SLloyd Pique  * call.
71*84e872a0SLloyd Pique  * \return If the event source is registered for re-check with
72*84e872a0SLloyd Pique  * wl_event_source_check(): 0 for all done, 1 for needing a re-check.
73*84e872a0SLloyd Pique  * If not registered, the return value is ignored and should be zero.
74*84e872a0SLloyd Pique  *
75*84e872a0SLloyd Pique  * \sa wl_event_loop_add_timer()
76*84e872a0SLloyd Pique  * \memberof wl_event_source
77*84e872a0SLloyd Pique  */
78*84e872a0SLloyd Pique typedef int (*wl_event_loop_timer_func_t)(void *data);
79*84e872a0SLloyd Pique 
80*84e872a0SLloyd Pique /** Signal dispatch function type
81*84e872a0SLloyd Pique  *
82*84e872a0SLloyd Pique  * Functions of this type are used as callbacks for (POSIX) signals.
83*84e872a0SLloyd Pique  *
84*84e872a0SLloyd Pique  * \param signal_number
85*84e872a0SLloyd Pique  * \param data The user data argument of the related wl_event_loop_add_signal()
86*84e872a0SLloyd Pique  * call.
87*84e872a0SLloyd Pique  * \return If the event source is registered for re-check with
88*84e872a0SLloyd Pique  * wl_event_source_check(): 0 for all done, 1 for needing a re-check.
89*84e872a0SLloyd Pique  * If not registered, the return value is ignored and should be zero.
90*84e872a0SLloyd Pique  *
91*84e872a0SLloyd Pique  * \sa wl_event_loop_add_signal()
92*84e872a0SLloyd Pique  * \memberof wl_event_source
93*84e872a0SLloyd Pique  */
94*84e872a0SLloyd Pique typedef int (*wl_event_loop_signal_func_t)(int signal_number, void *data);
95*84e872a0SLloyd Pique 
96*84e872a0SLloyd Pique /** Idle task function type
97*84e872a0SLloyd Pique  *
98*84e872a0SLloyd Pique  * Functions of this type are used as callbacks before blocking in
99*84e872a0SLloyd Pique  * wl_event_loop_dispatch().
100*84e872a0SLloyd Pique  *
101*84e872a0SLloyd Pique  * \param data The user data argument of the related wl_event_loop_add_idle()
102*84e872a0SLloyd Pique  * call.
103*84e872a0SLloyd Pique  *
104*84e872a0SLloyd Pique  * \sa wl_event_loop_add_idle() wl_event_loop_dispatch()
105*84e872a0SLloyd Pique  * \memberof wl_event_source
106*84e872a0SLloyd Pique  */
107*84e872a0SLloyd Pique typedef void (*wl_event_loop_idle_func_t)(void *data);
108*84e872a0SLloyd Pique 
109*84e872a0SLloyd Pique /** \struct wl_event_loop
110*84e872a0SLloyd Pique  *
111*84e872a0SLloyd Pique  * \brief An event loop context
112*84e872a0SLloyd Pique  *
113*84e872a0SLloyd Pique  * Usually you create an event loop context, add sources to it, and call
114*84e872a0SLloyd Pique  * wl_event_loop_dispatch() in a loop to process events.
115*84e872a0SLloyd Pique  *
116*84e872a0SLloyd Pique  * \sa wl_event_source
117*84e872a0SLloyd Pique  */
118*84e872a0SLloyd Pique 
119*84e872a0SLloyd Pique /** \struct wl_event_source
120*84e872a0SLloyd Pique  *
121*84e872a0SLloyd Pique  * \brief An abstract event source
122*84e872a0SLloyd Pique  *
123*84e872a0SLloyd Pique  * This is the generic type for fd, timer, signal, and idle sources.
124*84e872a0SLloyd Pique  * Functions that operate on specific source types must not be used with
125*84e872a0SLloyd Pique  * a different type, even if the function signature allows it.
126*84e872a0SLloyd Pique  */
127*84e872a0SLloyd Pique 
128*84e872a0SLloyd Pique struct wl_event_loop *
129*84e872a0SLloyd Pique wl_event_loop_create(void);
130*84e872a0SLloyd Pique 
131*84e872a0SLloyd Pique void
132*84e872a0SLloyd Pique wl_event_loop_destroy(struct wl_event_loop *loop);
133*84e872a0SLloyd Pique 
134*84e872a0SLloyd Pique struct wl_event_source *
135*84e872a0SLloyd Pique wl_event_loop_add_fd(struct wl_event_loop *loop,
136*84e872a0SLloyd Pique 		     int fd, uint32_t mask,
137*84e872a0SLloyd Pique 		     wl_event_loop_fd_func_t func,
138*84e872a0SLloyd Pique 		     void *data);
139*84e872a0SLloyd Pique 
140*84e872a0SLloyd Pique int
141*84e872a0SLloyd Pique wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask);
142*84e872a0SLloyd Pique 
143*84e872a0SLloyd Pique struct wl_event_source *
144*84e872a0SLloyd Pique wl_event_loop_add_timer(struct wl_event_loop *loop,
145*84e872a0SLloyd Pique 			wl_event_loop_timer_func_t func,
146*84e872a0SLloyd Pique 			void *data);
147*84e872a0SLloyd Pique 
148*84e872a0SLloyd Pique struct wl_event_source *
149*84e872a0SLloyd Pique wl_event_loop_add_signal(struct wl_event_loop *loop,
150*84e872a0SLloyd Pique 			 int signal_number,
151*84e872a0SLloyd Pique 			 wl_event_loop_signal_func_t func,
152*84e872a0SLloyd Pique 			 void *data);
153*84e872a0SLloyd Pique 
154*84e872a0SLloyd Pique int
155*84e872a0SLloyd Pique wl_event_source_timer_update(struct wl_event_source *source,
156*84e872a0SLloyd Pique 			     int ms_delay);
157*84e872a0SLloyd Pique 
158*84e872a0SLloyd Pique int
159*84e872a0SLloyd Pique wl_event_source_remove(struct wl_event_source *source);
160*84e872a0SLloyd Pique 
161*84e872a0SLloyd Pique void
162*84e872a0SLloyd Pique wl_event_source_check(struct wl_event_source *source);
163*84e872a0SLloyd Pique 
164*84e872a0SLloyd Pique int
165*84e872a0SLloyd Pique wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout);
166*84e872a0SLloyd Pique 
167*84e872a0SLloyd Pique void
168*84e872a0SLloyd Pique wl_event_loop_dispatch_idle(struct wl_event_loop *loop);
169*84e872a0SLloyd Pique 
170*84e872a0SLloyd Pique struct wl_event_source *
171*84e872a0SLloyd Pique wl_event_loop_add_idle(struct wl_event_loop *loop,
172*84e872a0SLloyd Pique 		       wl_event_loop_idle_func_t func,
173*84e872a0SLloyd Pique 		       void *data);
174*84e872a0SLloyd Pique 
175*84e872a0SLloyd Pique int
176*84e872a0SLloyd Pique wl_event_loop_get_fd(struct wl_event_loop *loop);
177*84e872a0SLloyd Pique 
178*84e872a0SLloyd Pique struct wl_listener;
179*84e872a0SLloyd Pique 
180*84e872a0SLloyd Pique typedef void (*wl_notify_func_t)(struct wl_listener *listener, void *data);
181*84e872a0SLloyd Pique 
182*84e872a0SLloyd Pique void
183*84e872a0SLloyd Pique wl_event_loop_add_destroy_listener(struct wl_event_loop *loop,
184*84e872a0SLloyd Pique 				   struct wl_listener *listener);
185*84e872a0SLloyd Pique 
186*84e872a0SLloyd Pique struct wl_listener *
187*84e872a0SLloyd Pique wl_event_loop_get_destroy_listener(struct wl_event_loop *loop,
188*84e872a0SLloyd Pique 				   wl_notify_func_t notify);
189*84e872a0SLloyd Pique 
190*84e872a0SLloyd Pique struct wl_display *
191*84e872a0SLloyd Pique wl_display_create(void);
192*84e872a0SLloyd Pique 
193*84e872a0SLloyd Pique void
194*84e872a0SLloyd Pique wl_display_destroy(struct wl_display *display);
195*84e872a0SLloyd Pique 
196*84e872a0SLloyd Pique struct wl_event_loop *
197*84e872a0SLloyd Pique wl_display_get_event_loop(struct wl_display *display);
198*84e872a0SLloyd Pique 
199*84e872a0SLloyd Pique int
200*84e872a0SLloyd Pique wl_display_add_socket(struct wl_display *display, const char *name);
201*84e872a0SLloyd Pique 
202*84e872a0SLloyd Pique const char *
203*84e872a0SLloyd Pique wl_display_add_socket_auto(struct wl_display *display);
204*84e872a0SLloyd Pique 
205*84e872a0SLloyd Pique int
206*84e872a0SLloyd Pique wl_display_add_socket_fd(struct wl_display *display, int sock_fd);
207*84e872a0SLloyd Pique 
208*84e872a0SLloyd Pique void
209*84e872a0SLloyd Pique wl_display_terminate(struct wl_display *display);
210*84e872a0SLloyd Pique 
211*84e872a0SLloyd Pique void
212*84e872a0SLloyd Pique wl_display_run(struct wl_display *display);
213*84e872a0SLloyd Pique 
214*84e872a0SLloyd Pique void
215*84e872a0SLloyd Pique wl_display_flush_clients(struct wl_display *display);
216*84e872a0SLloyd Pique 
217*84e872a0SLloyd Pique void
218*84e872a0SLloyd Pique wl_display_destroy_clients(struct wl_display *display);
219*84e872a0SLloyd Pique 
220*84e872a0SLloyd Pique struct wl_client;
221*84e872a0SLloyd Pique 
222*84e872a0SLloyd Pique typedef void (*wl_global_bind_func_t)(struct wl_client *client, void *data,
223*84e872a0SLloyd Pique 				      uint32_t version, uint32_t id);
224*84e872a0SLloyd Pique 
225*84e872a0SLloyd Pique uint32_t
226*84e872a0SLloyd Pique wl_display_get_serial(struct wl_display *display);
227*84e872a0SLloyd Pique 
228*84e872a0SLloyd Pique uint32_t
229*84e872a0SLloyd Pique wl_display_next_serial(struct wl_display *display);
230*84e872a0SLloyd Pique 
231*84e872a0SLloyd Pique void
232*84e872a0SLloyd Pique wl_display_add_destroy_listener(struct wl_display *display,
233*84e872a0SLloyd Pique 				struct wl_listener *listener);
234*84e872a0SLloyd Pique 
235*84e872a0SLloyd Pique void
236*84e872a0SLloyd Pique wl_display_add_client_created_listener(struct wl_display *display,
237*84e872a0SLloyd Pique 					struct wl_listener *listener);
238*84e872a0SLloyd Pique 
239*84e872a0SLloyd Pique struct wl_listener *
240*84e872a0SLloyd Pique wl_display_get_destroy_listener(struct wl_display *display,
241*84e872a0SLloyd Pique 				wl_notify_func_t notify);
242*84e872a0SLloyd Pique 
243*84e872a0SLloyd Pique struct wl_global *
244*84e872a0SLloyd Pique wl_global_create(struct wl_display *display,
245*84e872a0SLloyd Pique 		 const struct wl_interface *interface,
246*84e872a0SLloyd Pique 		 int version,
247*84e872a0SLloyd Pique 		 void *data, wl_global_bind_func_t bind);
248*84e872a0SLloyd Pique 
249*84e872a0SLloyd Pique void
250*84e872a0SLloyd Pique wl_global_remove(struct wl_global *global);
251*84e872a0SLloyd Pique 
252*84e872a0SLloyd Pique void
253*84e872a0SLloyd Pique wl_global_destroy(struct wl_global *global);
254*84e872a0SLloyd Pique 
255*84e872a0SLloyd Pique /** A filter function for wl_global objects
256*84e872a0SLloyd Pique  *
257*84e872a0SLloyd Pique  * \param client The client object
258*84e872a0SLloyd Pique  * \param global The global object to show or hide
259*84e872a0SLloyd Pique  * \param data   The user data pointer
260*84e872a0SLloyd Pique  *
261*84e872a0SLloyd Pique  * A filter function enables the server to decide which globals to
262*84e872a0SLloyd Pique  * advertise to each client.
263*84e872a0SLloyd Pique  *
264*84e872a0SLloyd Pique  * When a wl_global filter is set, the given callback function will be
265*84e872a0SLloyd Pique  * called during wl_global advertisement and binding.
266*84e872a0SLloyd Pique  *
267*84e872a0SLloyd Pique  * This function should return true if the global object should be made
268*84e872a0SLloyd Pique  * visible to the client or false otherwise.
269*84e872a0SLloyd Pique  */
270*84e872a0SLloyd Pique typedef bool (*wl_display_global_filter_func_t)(const struct wl_client *client,
271*84e872a0SLloyd Pique 						const struct wl_global *global,
272*84e872a0SLloyd Pique 						void *data);
273*84e872a0SLloyd Pique 
274*84e872a0SLloyd Pique void
275*84e872a0SLloyd Pique wl_display_set_global_filter(struct wl_display *display,
276*84e872a0SLloyd Pique 			     wl_display_global_filter_func_t filter,
277*84e872a0SLloyd Pique 			     void *data);
278*84e872a0SLloyd Pique 
279*84e872a0SLloyd Pique const struct wl_interface *
280*84e872a0SLloyd Pique wl_global_get_interface(const struct wl_global *global);
281*84e872a0SLloyd Pique 
282*84e872a0SLloyd Pique uint32_t
283*84e872a0SLloyd Pique wl_global_get_name(const struct wl_global *global,
284*84e872a0SLloyd Pique                    const struct wl_client *client);
285*84e872a0SLloyd Pique 
286*84e872a0SLloyd Pique uint32_t
287*84e872a0SLloyd Pique wl_global_get_version(const struct wl_global *global);
288*84e872a0SLloyd Pique 
289*84e872a0SLloyd Pique struct wl_display *
290*84e872a0SLloyd Pique wl_global_get_display(const struct wl_global *global);
291*84e872a0SLloyd Pique 
292*84e872a0SLloyd Pique void *
293*84e872a0SLloyd Pique wl_global_get_user_data(const struct wl_global *global);
294*84e872a0SLloyd Pique 
295*84e872a0SLloyd Pique void
296*84e872a0SLloyd Pique wl_global_set_user_data(struct wl_global *global, void *data);
297*84e872a0SLloyd Pique 
298*84e872a0SLloyd Pique struct wl_client *
299*84e872a0SLloyd Pique wl_client_create(struct wl_display *display, int fd);
300*84e872a0SLloyd Pique 
301*84e872a0SLloyd Pique struct wl_list *
302*84e872a0SLloyd Pique wl_display_get_client_list(struct wl_display *display);
303*84e872a0SLloyd Pique 
304*84e872a0SLloyd Pique struct wl_list *
305*84e872a0SLloyd Pique wl_client_get_link(struct wl_client *client);
306*84e872a0SLloyd Pique 
307*84e872a0SLloyd Pique struct wl_client *
308*84e872a0SLloyd Pique wl_client_from_link(struct wl_list *link);
309*84e872a0SLloyd Pique 
310*84e872a0SLloyd Pique /** Iterate over a list of clients. */
311*84e872a0SLloyd Pique #define wl_client_for_each(client, list)				\
312*84e872a0SLloyd Pique 	for (client = wl_client_from_link((list)->next);	\
313*84e872a0SLloyd Pique 	     wl_client_get_link(client) != (list);			\
314*84e872a0SLloyd Pique 	     client = wl_client_from_link(wl_client_get_link(client)->next))
315*84e872a0SLloyd Pique 
316*84e872a0SLloyd Pique void
317*84e872a0SLloyd Pique wl_client_destroy(struct wl_client *client);
318*84e872a0SLloyd Pique 
319*84e872a0SLloyd Pique void
320*84e872a0SLloyd Pique wl_client_flush(struct wl_client *client);
321*84e872a0SLloyd Pique 
322*84e872a0SLloyd Pique void
323*84e872a0SLloyd Pique wl_client_get_credentials(struct wl_client *client,
324*84e872a0SLloyd Pique 			  pid_t *pid, uid_t *uid, gid_t *gid);
325*84e872a0SLloyd Pique 
326*84e872a0SLloyd Pique int
327*84e872a0SLloyd Pique wl_client_get_fd(struct wl_client *client);
328*84e872a0SLloyd Pique 
329*84e872a0SLloyd Pique void
330*84e872a0SLloyd Pique wl_client_add_destroy_listener(struct wl_client *client,
331*84e872a0SLloyd Pique 			       struct wl_listener *listener);
332*84e872a0SLloyd Pique 
333*84e872a0SLloyd Pique struct wl_listener *
334*84e872a0SLloyd Pique wl_client_get_destroy_listener(struct wl_client *client,
335*84e872a0SLloyd Pique 			       wl_notify_func_t notify);
336*84e872a0SLloyd Pique 
337*84e872a0SLloyd Pique void
338*84e872a0SLloyd Pique wl_client_add_destroy_late_listener(struct wl_client *client,
339*84e872a0SLloyd Pique 				    struct wl_listener *listener);
340*84e872a0SLloyd Pique 
341*84e872a0SLloyd Pique struct wl_listener *
342*84e872a0SLloyd Pique wl_client_get_destroy_late_listener(struct wl_client *client,
343*84e872a0SLloyd Pique 				    wl_notify_func_t notify);
344*84e872a0SLloyd Pique 
345*84e872a0SLloyd Pique struct wl_resource *
346*84e872a0SLloyd Pique wl_client_get_object(struct wl_client *client, uint32_t id);
347*84e872a0SLloyd Pique 
348*84e872a0SLloyd Pique void
349*84e872a0SLloyd Pique wl_client_post_no_memory(struct wl_client *client);
350*84e872a0SLloyd Pique 
351*84e872a0SLloyd Pique void
352*84e872a0SLloyd Pique wl_client_post_implementation_error(struct wl_client *client,
353*84e872a0SLloyd Pique                                     const char* msg, ...) WL_PRINTF(2,3);
354*84e872a0SLloyd Pique 
355*84e872a0SLloyd Pique void
356*84e872a0SLloyd Pique wl_client_add_resource_created_listener(struct wl_client *client,
357*84e872a0SLloyd Pique                                         struct wl_listener *listener);
358*84e872a0SLloyd Pique 
359*84e872a0SLloyd Pique typedef enum wl_iterator_result (*wl_client_for_each_resource_iterator_func_t)(
360*84e872a0SLloyd Pique 						struct wl_resource *resource,
361*84e872a0SLloyd Pique 						void *user_data);
362*84e872a0SLloyd Pique 
363*84e872a0SLloyd Pique void
364*84e872a0SLloyd Pique wl_client_for_each_resource(struct wl_client *client,
365*84e872a0SLloyd Pique                             wl_client_for_each_resource_iterator_func_t iterator,
366*84e872a0SLloyd Pique                             void *user_data);
367*84e872a0SLloyd Pique 
368*84e872a0SLloyd Pique /** \class wl_listener
369*84e872a0SLloyd Pique  *
370*84e872a0SLloyd Pique  * \brief A single listener for Wayland signals
371*84e872a0SLloyd Pique  *
372*84e872a0SLloyd Pique  * wl_listener provides the means to listen for wl_signal notifications. Many
373*84e872a0SLloyd Pique  * Wayland objects use wl_listener for notification of significant events like
374*84e872a0SLloyd Pique  * object destruction.
375*84e872a0SLloyd Pique  *
376*84e872a0SLloyd Pique  * Clients should create wl_listener objects manually and can register them as
377*84e872a0SLloyd Pique  * listeners to signals using #wl_signal_add, assuming the signal is
378*84e872a0SLloyd Pique  * directly accessible. For opaque structs like wl_event_loop, adding a
379*84e872a0SLloyd Pique  * listener should be done through provided accessor methods. A listener can
380*84e872a0SLloyd Pique  * only listen to one signal at a time.
381*84e872a0SLloyd Pique  *
382*84e872a0SLloyd Pique  * \code
383*84e872a0SLloyd Pique  * struct wl_listener your_listener;
384*84e872a0SLloyd Pique  *
385*84e872a0SLloyd Pique  * your_listener.notify = your_callback_method;
386*84e872a0SLloyd Pique  *
387*84e872a0SLloyd Pique  * // Direct access
388*84e872a0SLloyd Pique  * wl_signal_add(&some_object->destroy_signal, &your_listener);
389*84e872a0SLloyd Pique  *
390*84e872a0SLloyd Pique  * // Accessor access
391*84e872a0SLloyd Pique  * wl_event_loop *loop = ...;
392*84e872a0SLloyd Pique  * wl_event_loop_add_destroy_listener(loop, &your_listener);
393*84e872a0SLloyd Pique  * \endcode
394*84e872a0SLloyd Pique  *
395*84e872a0SLloyd Pique  * If the listener is part of a larger struct, #wl_container_of can be used
396*84e872a0SLloyd Pique  * to retrieve a pointer to it:
397*84e872a0SLloyd Pique  *
398*84e872a0SLloyd Pique  * \code
399*84e872a0SLloyd Pique  * void your_listener(struct wl_listener *listener, void *data)
400*84e872a0SLloyd Pique  * {
401*84e872a0SLloyd Pique  * 	struct your_data *data;
402*84e872a0SLloyd Pique  *
403*84e872a0SLloyd Pique  * 	your_data = wl_container_of(listener, data, your_member_name);
404*84e872a0SLloyd Pique  * }
405*84e872a0SLloyd Pique  * \endcode
406*84e872a0SLloyd Pique  *
407*84e872a0SLloyd Pique  * If you need to remove a listener from a signal, use wl_list_remove().
408*84e872a0SLloyd Pique  *
409*84e872a0SLloyd Pique  * \code
410*84e872a0SLloyd Pique  * wl_list_remove(&your_listener.link);
411*84e872a0SLloyd Pique  * \endcode
412*84e872a0SLloyd Pique  *
413*84e872a0SLloyd Pique  * \sa wl_signal
414*84e872a0SLloyd Pique  */
415*84e872a0SLloyd Pique struct wl_listener {
416*84e872a0SLloyd Pique 	struct wl_list link;
417*84e872a0SLloyd Pique 	wl_notify_func_t notify;
418*84e872a0SLloyd Pique };
419*84e872a0SLloyd Pique 
420*84e872a0SLloyd Pique /** \class wl_signal
421*84e872a0SLloyd Pique  *
422*84e872a0SLloyd Pique  * \brief A source of a type of observable event
423*84e872a0SLloyd Pique  *
424*84e872a0SLloyd Pique  * Signals are recognized points where significant events can be observed.
425*84e872a0SLloyd Pique  * Compositors as well as the server can provide signals. Observers are
426*84e872a0SLloyd Pique  * wl_listener's that are added through #wl_signal_add. Signals are emitted
427*84e872a0SLloyd Pique  * using #wl_signal_emit, which will invoke all listeners until that
428*84e872a0SLloyd Pique  * listener is removed by wl_list_remove() (or whenever the signal is
429*84e872a0SLloyd Pique  * destroyed).
430*84e872a0SLloyd Pique  *
431*84e872a0SLloyd Pique  * \sa wl_listener for more information on using wl_signal
432*84e872a0SLloyd Pique  */
433*84e872a0SLloyd Pique struct wl_signal {
434*84e872a0SLloyd Pique 	struct wl_list listener_list;
435*84e872a0SLloyd Pique };
436*84e872a0SLloyd Pique 
437*84e872a0SLloyd Pique /** Initialize a new \ref wl_signal for use.
438*84e872a0SLloyd Pique  *
439*84e872a0SLloyd Pique  * \param signal The signal that will be initialized
440*84e872a0SLloyd Pique  *
441*84e872a0SLloyd Pique  * \memberof wl_signal
442*84e872a0SLloyd Pique  */
443*84e872a0SLloyd Pique static inline void
wl_signal_init(struct wl_signal * signal)444*84e872a0SLloyd Pique wl_signal_init(struct wl_signal *signal)
445*84e872a0SLloyd Pique {
446*84e872a0SLloyd Pique 	wl_list_init(&signal->listener_list);
447*84e872a0SLloyd Pique }
448*84e872a0SLloyd Pique 
449*84e872a0SLloyd Pique /** Add the specified listener to this signal.
450*84e872a0SLloyd Pique  *
451*84e872a0SLloyd Pique  * \param signal The signal that will emit events to the listener
452*84e872a0SLloyd Pique  * \param listener The listener to add
453*84e872a0SLloyd Pique  *
454*84e872a0SLloyd Pique  * \memberof wl_signal
455*84e872a0SLloyd Pique  */
456*84e872a0SLloyd Pique static inline void
wl_signal_add(struct wl_signal * signal,struct wl_listener * listener)457*84e872a0SLloyd Pique wl_signal_add(struct wl_signal *signal, struct wl_listener *listener)
458*84e872a0SLloyd Pique {
459*84e872a0SLloyd Pique 	wl_list_insert(signal->listener_list.prev, &listener->link);
460*84e872a0SLloyd Pique }
461*84e872a0SLloyd Pique 
462*84e872a0SLloyd Pique /** Gets the listener struct for the specified callback.
463*84e872a0SLloyd Pique  *
464*84e872a0SLloyd Pique  * \param signal The signal that contains the specified listener
465*84e872a0SLloyd Pique  * \param notify The listener that is the target of this search
466*84e872a0SLloyd Pique  * \return the list item that corresponds to the specified listener, or NULL
467*84e872a0SLloyd Pique  * if none was found
468*84e872a0SLloyd Pique  *
469*84e872a0SLloyd Pique  * \memberof wl_signal
470*84e872a0SLloyd Pique  */
471*84e872a0SLloyd Pique static inline struct wl_listener *
wl_signal_get(struct wl_signal * signal,wl_notify_func_t notify)472*84e872a0SLloyd Pique wl_signal_get(struct wl_signal *signal, wl_notify_func_t notify)
473*84e872a0SLloyd Pique {
474*84e872a0SLloyd Pique 	struct wl_listener *l;
475*84e872a0SLloyd Pique 
476*84e872a0SLloyd Pique 	wl_list_for_each(l, &signal->listener_list, link)
477*84e872a0SLloyd Pique 		if (l->notify == notify)
478*84e872a0SLloyd Pique 			return l;
479*84e872a0SLloyd Pique 
480*84e872a0SLloyd Pique 	return NULL;
481*84e872a0SLloyd Pique }
482*84e872a0SLloyd Pique 
483*84e872a0SLloyd Pique /** Emits this signal, notifying all registered listeners.
484*84e872a0SLloyd Pique  *
485*84e872a0SLloyd Pique  * \param signal The signal object that will emit the signal
486*84e872a0SLloyd Pique  * \param data The data that will be emitted with the signal
487*84e872a0SLloyd Pique  *
488*84e872a0SLloyd Pique  * \memberof wl_signal
489*84e872a0SLloyd Pique  */
490*84e872a0SLloyd Pique static inline void
wl_signal_emit(struct wl_signal * signal,void * data)491*84e872a0SLloyd Pique wl_signal_emit(struct wl_signal *signal, void *data)
492*84e872a0SLloyd Pique {
493*84e872a0SLloyd Pique 	struct wl_listener *l, *next;
494*84e872a0SLloyd Pique 
495*84e872a0SLloyd Pique 	wl_list_for_each_safe(l, next, &signal->listener_list, link)
496*84e872a0SLloyd Pique 		l->notify(l, data);
497*84e872a0SLloyd Pique }
498*84e872a0SLloyd Pique 
499*84e872a0SLloyd Pique void
500*84e872a0SLloyd Pique wl_signal_emit_mutable(struct wl_signal *signal, void *data);
501*84e872a0SLloyd Pique 
502*84e872a0SLloyd Pique typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource);
503*84e872a0SLloyd Pique 
504*84e872a0SLloyd Pique /*
505*84e872a0SLloyd Pique  * Post an event to the client's object referred to by 'resource'.
506*84e872a0SLloyd Pique  * 'opcode' is the event number generated from the protocol XML
507*84e872a0SLloyd Pique  * description (the event name). The variable arguments are the event
508*84e872a0SLloyd Pique  * parameters, in the order they appear in the protocol XML specification.
509*84e872a0SLloyd Pique  *
510*84e872a0SLloyd Pique  * The variable arguments' types are:
511*84e872a0SLloyd Pique  * - type=uint:	uint32_t
512*84e872a0SLloyd Pique  * - type=int:		int32_t
513*84e872a0SLloyd Pique  * - type=fixed:	wl_fixed_t
514*84e872a0SLloyd Pique  * - type=string:	(const char *) to a nil-terminated string
515*84e872a0SLloyd Pique  * - type=array:	(struct wl_array *)
516*84e872a0SLloyd Pique  * - type=fd:		int, that is an open file descriptor
517*84e872a0SLloyd Pique  * - type=new_id:	(struct wl_object *) or (struct wl_resource *)
518*84e872a0SLloyd Pique  * - type=object:	(struct wl_object *) or (struct wl_resource *)
519*84e872a0SLloyd Pique  */
520*84e872a0SLloyd Pique void
521*84e872a0SLloyd Pique wl_resource_post_event(struct wl_resource *resource,
522*84e872a0SLloyd Pique 		       uint32_t opcode, ...);
523*84e872a0SLloyd Pique 
524*84e872a0SLloyd Pique void
525*84e872a0SLloyd Pique wl_resource_post_event_array(struct wl_resource *resource,
526*84e872a0SLloyd Pique 			     uint32_t opcode, union wl_argument *args);
527*84e872a0SLloyd Pique 
528*84e872a0SLloyd Pique void
529*84e872a0SLloyd Pique wl_resource_queue_event(struct wl_resource *resource,
530*84e872a0SLloyd Pique 			uint32_t opcode, ...);
531*84e872a0SLloyd Pique 
532*84e872a0SLloyd Pique void
533*84e872a0SLloyd Pique wl_resource_queue_event_array(struct wl_resource *resource,
534*84e872a0SLloyd Pique 			      uint32_t opcode, union wl_argument *args);
535*84e872a0SLloyd Pique 
536*84e872a0SLloyd Pique /* msg is a printf format string, variable args are its args. */
537*84e872a0SLloyd Pique void
538*84e872a0SLloyd Pique wl_resource_post_error(struct wl_resource *resource,
539*84e872a0SLloyd Pique 		       uint32_t code, const char *msg, ...) WL_PRINTF(3, 4);
540*84e872a0SLloyd Pique 
541*84e872a0SLloyd Pique void
542*84e872a0SLloyd Pique wl_resource_post_no_memory(struct wl_resource *resource);
543*84e872a0SLloyd Pique 
544*84e872a0SLloyd Pique struct wl_display *
545*84e872a0SLloyd Pique wl_client_get_display(struct wl_client *client);
546*84e872a0SLloyd Pique 
547*84e872a0SLloyd Pique struct wl_resource *
548*84e872a0SLloyd Pique wl_resource_create(struct wl_client *client,
549*84e872a0SLloyd Pique 		   const struct wl_interface *interface,
550*84e872a0SLloyd Pique 		   int version, uint32_t id);
551*84e872a0SLloyd Pique 
552*84e872a0SLloyd Pique void
553*84e872a0SLloyd Pique wl_resource_set_implementation(struct wl_resource *resource,
554*84e872a0SLloyd Pique 			       const void *implementation,
555*84e872a0SLloyd Pique 			       void *data,
556*84e872a0SLloyd Pique 			       wl_resource_destroy_func_t destroy);
557*84e872a0SLloyd Pique 
558*84e872a0SLloyd Pique void
559*84e872a0SLloyd Pique wl_resource_set_dispatcher(struct wl_resource *resource,
560*84e872a0SLloyd Pique 			   wl_dispatcher_func_t dispatcher,
561*84e872a0SLloyd Pique 			   const void *implementation,
562*84e872a0SLloyd Pique 			   void *data,
563*84e872a0SLloyd Pique 			   wl_resource_destroy_func_t destroy);
564*84e872a0SLloyd Pique 
565*84e872a0SLloyd Pique void
566*84e872a0SLloyd Pique wl_resource_destroy(struct wl_resource *resource);
567*84e872a0SLloyd Pique 
568*84e872a0SLloyd Pique uint32_t
569*84e872a0SLloyd Pique wl_resource_get_id(struct wl_resource *resource);
570*84e872a0SLloyd Pique 
571*84e872a0SLloyd Pique struct wl_list *
572*84e872a0SLloyd Pique wl_resource_get_link(struct wl_resource *resource);
573*84e872a0SLloyd Pique 
574*84e872a0SLloyd Pique struct wl_resource *
575*84e872a0SLloyd Pique wl_resource_from_link(struct wl_list *resource);
576*84e872a0SLloyd Pique 
577*84e872a0SLloyd Pique struct wl_resource *
578*84e872a0SLloyd Pique wl_resource_find_for_client(struct wl_list *list, struct wl_client *client);
579*84e872a0SLloyd Pique 
580*84e872a0SLloyd Pique struct wl_client *
581*84e872a0SLloyd Pique wl_resource_get_client(struct wl_resource *resource);
582*84e872a0SLloyd Pique 
583*84e872a0SLloyd Pique void
584*84e872a0SLloyd Pique wl_resource_set_user_data(struct wl_resource *resource, void *data);
585*84e872a0SLloyd Pique 
586*84e872a0SLloyd Pique void *
587*84e872a0SLloyd Pique wl_resource_get_user_data(struct wl_resource *resource);
588*84e872a0SLloyd Pique 
589*84e872a0SLloyd Pique int
590*84e872a0SLloyd Pique wl_resource_get_version(struct wl_resource *resource);
591*84e872a0SLloyd Pique 
592*84e872a0SLloyd Pique void
593*84e872a0SLloyd Pique wl_resource_set_destructor(struct wl_resource *resource,
594*84e872a0SLloyd Pique 			   wl_resource_destroy_func_t destroy);
595*84e872a0SLloyd Pique 
596*84e872a0SLloyd Pique int
597*84e872a0SLloyd Pique wl_resource_instance_of(struct wl_resource *resource,
598*84e872a0SLloyd Pique 			const struct wl_interface *interface,
599*84e872a0SLloyd Pique 			const void *implementation);
600*84e872a0SLloyd Pique const char *
601*84e872a0SLloyd Pique wl_resource_get_class(struct wl_resource *resource);
602*84e872a0SLloyd Pique 
603*84e872a0SLloyd Pique void
604*84e872a0SLloyd Pique wl_resource_add_destroy_listener(struct wl_resource *resource,
605*84e872a0SLloyd Pique 				 struct wl_listener *listener);
606*84e872a0SLloyd Pique 
607*84e872a0SLloyd Pique struct wl_listener *
608*84e872a0SLloyd Pique wl_resource_get_destroy_listener(struct wl_resource *resource,
609*84e872a0SLloyd Pique 				 wl_notify_func_t notify);
610*84e872a0SLloyd Pique 
611*84e872a0SLloyd Pique struct wl_resource *
612*84e872a0SLloyd Pique wl_resource_from_object(struct wl_object *object);
613*84e872a0SLloyd Pique 
614*84e872a0SLloyd Pique #define wl_resource_for_each(resource, list)					\
615*84e872a0SLloyd Pique 	for (resource = 0, resource = wl_resource_from_link((list)->next);	\
616*84e872a0SLloyd Pique 	     wl_resource_get_link(resource) != (list);				\
617*84e872a0SLloyd Pique 	     resource = wl_resource_from_link(wl_resource_get_link(resource)->next))
618*84e872a0SLloyd Pique 
619*84e872a0SLloyd Pique #define wl_resource_for_each_safe(resource, tmp, list)					\
620*84e872a0SLloyd Pique 	for (resource = 0, tmp = 0,							\
621*84e872a0SLloyd Pique 	     resource = wl_resource_from_link((list)->next),	\
622*84e872a0SLloyd Pique 	     tmp = wl_resource_from_link((list)->next->next);	\
623*84e872a0SLloyd Pique 	     wl_resource_get_link(resource) != (list);				\
624*84e872a0SLloyd Pique 	     resource = tmp,							\
625*84e872a0SLloyd Pique 	     tmp = wl_resource_from_link(wl_resource_get_link(resource)->next))
626*84e872a0SLloyd Pique 
627*84e872a0SLloyd Pique struct wl_shm_buffer *
628*84e872a0SLloyd Pique wl_shm_buffer_get(struct wl_resource *resource);
629*84e872a0SLloyd Pique 
630*84e872a0SLloyd Pique void
631*84e872a0SLloyd Pique wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer);
632*84e872a0SLloyd Pique 
633*84e872a0SLloyd Pique void
634*84e872a0SLloyd Pique wl_shm_buffer_end_access(struct wl_shm_buffer *buffer);
635*84e872a0SLloyd Pique 
636*84e872a0SLloyd Pique void *
637*84e872a0SLloyd Pique wl_shm_buffer_get_data(struct wl_shm_buffer *buffer);
638*84e872a0SLloyd Pique 
639*84e872a0SLloyd Pique int32_t
640*84e872a0SLloyd Pique wl_shm_buffer_get_stride(struct wl_shm_buffer *buffer);
641*84e872a0SLloyd Pique 
642*84e872a0SLloyd Pique uint32_t
643*84e872a0SLloyd Pique wl_shm_buffer_get_format(struct wl_shm_buffer *buffer);
644*84e872a0SLloyd Pique 
645*84e872a0SLloyd Pique int32_t
646*84e872a0SLloyd Pique wl_shm_buffer_get_width(struct wl_shm_buffer *buffer);
647*84e872a0SLloyd Pique 
648*84e872a0SLloyd Pique int32_t
649*84e872a0SLloyd Pique wl_shm_buffer_get_height(struct wl_shm_buffer *buffer);
650*84e872a0SLloyd Pique 
651*84e872a0SLloyd Pique struct wl_shm_pool *
652*84e872a0SLloyd Pique wl_shm_buffer_ref_pool(struct wl_shm_buffer *buffer);
653*84e872a0SLloyd Pique 
654*84e872a0SLloyd Pique void
655*84e872a0SLloyd Pique wl_shm_pool_unref(struct wl_shm_pool *pool);
656*84e872a0SLloyd Pique 
657*84e872a0SLloyd Pique int
658*84e872a0SLloyd Pique wl_display_init_shm(struct wl_display *display);
659*84e872a0SLloyd Pique 
660*84e872a0SLloyd Pique uint32_t *
661*84e872a0SLloyd Pique wl_display_add_shm_format(struct wl_display *display, uint32_t format);
662*84e872a0SLloyd Pique 
663*84e872a0SLloyd Pique struct wl_shm_buffer *
664*84e872a0SLloyd Pique wl_shm_buffer_create(struct wl_client *client,
665*84e872a0SLloyd Pique 		     uint32_t id, int32_t width, int32_t height,
666*84e872a0SLloyd Pique 		     int32_t stride, uint32_t format) WL_DEPRECATED;
667*84e872a0SLloyd Pique 
668*84e872a0SLloyd Pique void
669*84e872a0SLloyd Pique wl_log_set_handler_server(wl_log_func_t handler);
670*84e872a0SLloyd Pique 
671*84e872a0SLloyd Pique enum wl_protocol_logger_type {
672*84e872a0SLloyd Pique 	WL_PROTOCOL_LOGGER_REQUEST,
673*84e872a0SLloyd Pique 	WL_PROTOCOL_LOGGER_EVENT,
674*84e872a0SLloyd Pique };
675*84e872a0SLloyd Pique 
676*84e872a0SLloyd Pique struct wl_protocol_logger_message {
677*84e872a0SLloyd Pique 	struct wl_resource *resource;
678*84e872a0SLloyd Pique 	int message_opcode;
679*84e872a0SLloyd Pique 	const struct wl_message *message;
680*84e872a0SLloyd Pique 	int arguments_count;
681*84e872a0SLloyd Pique 	const union wl_argument *arguments;
682*84e872a0SLloyd Pique };
683*84e872a0SLloyd Pique 
684*84e872a0SLloyd Pique typedef void (*wl_protocol_logger_func_t)(void *user_data,
685*84e872a0SLloyd Pique 					  enum wl_protocol_logger_type direction,
686*84e872a0SLloyd Pique 					  const struct wl_protocol_logger_message *message);
687*84e872a0SLloyd Pique 
688*84e872a0SLloyd Pique struct wl_protocol_logger *
689*84e872a0SLloyd Pique wl_display_add_protocol_logger(struct wl_display *display,
690*84e872a0SLloyd Pique 			       wl_protocol_logger_func_t, void *user_data);
691*84e872a0SLloyd Pique 
692*84e872a0SLloyd Pique void
693*84e872a0SLloyd Pique wl_protocol_logger_destroy(struct wl_protocol_logger *logger);
694*84e872a0SLloyd Pique 
695*84e872a0SLloyd Pique #ifdef  __cplusplus
696*84e872a0SLloyd Pique }
697*84e872a0SLloyd Pique #endif
698*84e872a0SLloyd Pique 
699*84e872a0SLloyd Pique #endif
700