xref: /aosp_15_r20/external/wayland/src/wayland-util.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 /** \file wayland-util.h
27*84e872a0SLloyd Pique  *
28*84e872a0SLloyd Pique  * \brief Utility classes, functions, and macros.
29*84e872a0SLloyd Pique  */
30*84e872a0SLloyd Pique 
31*84e872a0SLloyd Pique #ifndef WAYLAND_UTIL_H
32*84e872a0SLloyd Pique #define WAYLAND_UTIL_H
33*84e872a0SLloyd Pique 
34*84e872a0SLloyd Pique #include <math.h>
35*84e872a0SLloyd Pique #include <stddef.h>
36*84e872a0SLloyd Pique #include <inttypes.h>
37*84e872a0SLloyd Pique #include <stdarg.h>
38*84e872a0SLloyd Pique 
39*84e872a0SLloyd Pique #ifdef  __cplusplus
40*84e872a0SLloyd Pique extern "C" {
41*84e872a0SLloyd Pique #endif
42*84e872a0SLloyd Pique 
43*84e872a0SLloyd Pique /** Visibility attribute */
44*84e872a0SLloyd Pique #if defined(__GNUC__) && __GNUC__ >= 4
45*84e872a0SLloyd Pique #define WL_EXPORT __attribute__ ((visibility("default")))
46*84e872a0SLloyd Pique #else
47*84e872a0SLloyd Pique #define WL_EXPORT
48*84e872a0SLloyd Pique #endif
49*84e872a0SLloyd Pique 
50*84e872a0SLloyd Pique /** Deprecated attribute */
51*84e872a0SLloyd Pique #if defined(__GNUC__) && __GNUC__ >= 4
52*84e872a0SLloyd Pique #define WL_DEPRECATED __attribute__ ((deprecated))
53*84e872a0SLloyd Pique #else
54*84e872a0SLloyd Pique #define WL_DEPRECATED
55*84e872a0SLloyd Pique #endif
56*84e872a0SLloyd Pique 
57*84e872a0SLloyd Pique /**
58*84e872a0SLloyd Pique  * Printf-style argument attribute
59*84e872a0SLloyd Pique  *
60*84e872a0SLloyd Pique  * \param x Ordinality of the format string argument
61*84e872a0SLloyd Pique  * \param y Ordinality of the argument to check against the format string
62*84e872a0SLloyd Pique  *
63*84e872a0SLloyd Pique  * \sa https://gcc.gnu.org/onlinedocs/gcc-3.2.1/gcc/Function-Attributes.html
64*84e872a0SLloyd Pique  */
65*84e872a0SLloyd Pique #if defined(__GNUC__) && __GNUC__ >= 4
66*84e872a0SLloyd Pique #define WL_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
67*84e872a0SLloyd Pique #else
68*84e872a0SLloyd Pique #define WL_PRINTF(x, y)
69*84e872a0SLloyd Pique #endif
70*84e872a0SLloyd Pique 
71*84e872a0SLloyd Pique /** \class wl_object
72*84e872a0SLloyd Pique  *
73*84e872a0SLloyd Pique  * \brief A protocol object.
74*84e872a0SLloyd Pique  *
75*84e872a0SLloyd Pique  * A `wl_object` is an opaque struct identifying the protocol object
76*84e872a0SLloyd Pique  * underlying a `wl_proxy` or `wl_resource`.
77*84e872a0SLloyd Pique  *
78*84e872a0SLloyd Pique  * \note Functions accessing a `wl_object` are not normally used by client code.
79*84e872a0SLloyd Pique  * Clients should normally use the higher level interface generated by the
80*84e872a0SLloyd Pique  * scanner to interact with compositor objects.
81*84e872a0SLloyd Pique  *
82*84e872a0SLloyd Pique  */
83*84e872a0SLloyd Pique struct wl_object;
84*84e872a0SLloyd Pique 
85*84e872a0SLloyd Pique /**
86*84e872a0SLloyd Pique  * Protocol message signature
87*84e872a0SLloyd Pique  *
88*84e872a0SLloyd Pique  * A wl_message describes the signature of an actual protocol message, such as a
89*84e872a0SLloyd Pique  * request or event, that adheres to the Wayland protocol wire format. The
90*84e872a0SLloyd Pique  * protocol implementation uses a wl_message within its demarshal machinery for
91*84e872a0SLloyd Pique  * decoding messages between a compositor and its clients. In a sense, a
92*84e872a0SLloyd Pique  * wl_message is to a protocol message like a class is to an object.
93*84e872a0SLloyd Pique  *
94*84e872a0SLloyd Pique  * The `name` of a wl_message is the name of the corresponding protocol message.
95*84e872a0SLloyd Pique  *
96*84e872a0SLloyd Pique  * The `signature` is an ordered list of symbols representing the data types
97*84e872a0SLloyd Pique  * of message arguments and, optionally, a protocol version and indicators for
98*84e872a0SLloyd Pique  * nullability. A leading integer in the `signature` indicates the _since_
99*84e872a0SLloyd Pique  * version of the protocol message. A `?` preceding a data type symbol indicates
100*84e872a0SLloyd Pique  * that the following argument type is nullable. While it is a protocol violation
101*84e872a0SLloyd Pique  * to send messages with non-nullable arguments set to `NULL`, event handlers in
102*84e872a0SLloyd Pique  * clients might still get called with non-nullable object arguments set to
103*84e872a0SLloyd Pique  * `NULL`. This can happen when the client destroyed the object being used as
104*84e872a0SLloyd Pique  * argument on its side and an event referencing that object was sent before the
105*84e872a0SLloyd Pique  * server knew about its destruction. As this race cannot be prevented, clients
106*84e872a0SLloyd Pique  * should - as a general rule - program their event handlers such that they can
107*84e872a0SLloyd Pique  * handle object arguments declared non-nullable being `NULL` gracefully.
108*84e872a0SLloyd Pique  *
109*84e872a0SLloyd Pique  * When no arguments accompany a message, `signature` is an empty string.
110*84e872a0SLloyd Pique  *
111*84e872a0SLloyd Pique  * Symbols:
112*84e872a0SLloyd Pique  *
113*84e872a0SLloyd Pique  * * `i`: int
114*84e872a0SLloyd Pique  * * `u`: uint
115*84e872a0SLloyd Pique  * * `f`: fixed
116*84e872a0SLloyd Pique  * * `s`: string
117*84e872a0SLloyd Pique  * * `o`: object
118*84e872a0SLloyd Pique  * * `n`: new_id
119*84e872a0SLloyd Pique  * * `a`: array
120*84e872a0SLloyd Pique  * * `h`: fd
121*84e872a0SLloyd Pique  * * `?`: following argument (`o` or `s`) is nullable
122*84e872a0SLloyd Pique  *
123*84e872a0SLloyd Pique  * While demarshaling primitive arguments is straightforward, when demarshaling
124*84e872a0SLloyd Pique  * messages containing `object` or `new_id` arguments, the protocol
125*84e872a0SLloyd Pique  * implementation often must determine the type of the object. The `types` of a
126*84e872a0SLloyd Pique  * wl_message is an array of wl_interface references that correspond to `o` and
127*84e872a0SLloyd Pique  * `n` arguments in `signature`, with `NULL` placeholders for arguments with
128*84e872a0SLloyd Pique  * non-object types.
129*84e872a0SLloyd Pique  *
130*84e872a0SLloyd Pique  * Consider the protocol event wl_display `delete_id` that has a single `uint`
131*84e872a0SLloyd Pique  * argument. The wl_message is:
132*84e872a0SLloyd Pique  *
133*84e872a0SLloyd Pique  * \code
134*84e872a0SLloyd Pique  * { "delete_id", "u", [NULL] }
135*84e872a0SLloyd Pique  * \endcode
136*84e872a0SLloyd Pique  *
137*84e872a0SLloyd Pique  * Here, the message `name` is `"delete_id"`, the `signature` is `"u"`, and the
138*84e872a0SLloyd Pique  * argument `types` is `[NULL]`, indicating that the `uint` argument has no
139*84e872a0SLloyd Pique  * corresponding wl_interface since it is a primitive argument.
140*84e872a0SLloyd Pique  *
141*84e872a0SLloyd Pique  * In contrast, consider a `wl_foo` interface supporting protocol request `bar`
142*84e872a0SLloyd Pique  * that has existed since version 2, and has two arguments: a `uint` and an
143*84e872a0SLloyd Pique  * object of type `wl_baz_interface` that may be `NULL`. Such a `wl_message`
144*84e872a0SLloyd Pique  * might be:
145*84e872a0SLloyd Pique  *
146*84e872a0SLloyd Pique  * \code
147*84e872a0SLloyd Pique  * { "bar", "2u?o", [NULL, &wl_baz_interface] }
148*84e872a0SLloyd Pique  * \endcode
149*84e872a0SLloyd Pique  *
150*84e872a0SLloyd Pique  * Here, the message `name` is `"bar"`, and the `signature` is `"2u?o"`. Notice
151*84e872a0SLloyd Pique  * how the `2` indicates the protocol version, the `u` indicates the first
152*84e872a0SLloyd Pique  * argument type is `uint`, and the `?o` indicates that the second argument
153*84e872a0SLloyd Pique  * is an object that may be `NULL`. Lastly, the argument `types` array indicates
154*84e872a0SLloyd Pique  * that no wl_interface corresponds to the first argument, while the type
155*84e872a0SLloyd Pique  * `wl_baz_interface` corresponds to the second argument.
156*84e872a0SLloyd Pique  *
157*84e872a0SLloyd Pique  * \sa wl_argument
158*84e872a0SLloyd Pique  * \sa wl_interface
159*84e872a0SLloyd Pique  * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Wire-Format">Wire Format</a>
160*84e872a0SLloyd Pique  */
161*84e872a0SLloyd Pique struct wl_message {
162*84e872a0SLloyd Pique 	/** Message name */
163*84e872a0SLloyd Pique 	const char *name;
164*84e872a0SLloyd Pique 	/** Message signature */
165*84e872a0SLloyd Pique 	const char *signature;
166*84e872a0SLloyd Pique 	/** Object argument interfaces */
167*84e872a0SLloyd Pique 	const struct wl_interface **types;
168*84e872a0SLloyd Pique };
169*84e872a0SLloyd Pique 
170*84e872a0SLloyd Pique /**
171*84e872a0SLloyd Pique  * Protocol object interface
172*84e872a0SLloyd Pique  *
173*84e872a0SLloyd Pique  * A wl_interface describes the API of a protocol object defined in the Wayland
174*84e872a0SLloyd Pique  * protocol specification. The protocol implementation uses a wl_interface
175*84e872a0SLloyd Pique  * within its marshalling machinery for encoding client requests.
176*84e872a0SLloyd Pique  *
177*84e872a0SLloyd Pique  * The `name` of a wl_interface is the name of the corresponding protocol
178*84e872a0SLloyd Pique  * interface, and `version` represents the version of the interface. The members
179*84e872a0SLloyd Pique  * `method_count` and `event_count` represent the number of `methods` (requests)
180*84e872a0SLloyd Pique  * and `events` in the respective wl_message members.
181*84e872a0SLloyd Pique  *
182*84e872a0SLloyd Pique  * For example, consider a protocol interface `foo`, marked as version `1`, with
183*84e872a0SLloyd Pique  * two requests and one event.
184*84e872a0SLloyd Pique  *
185*84e872a0SLloyd Pique  * \code{.xml}
186*84e872a0SLloyd Pique  * <interface name="foo" version="1">
187*84e872a0SLloyd Pique  *   <request name="a"></request>
188*84e872a0SLloyd Pique  *   <request name="b"></request>
189*84e872a0SLloyd Pique  *   <event name="c"></event>
190*84e872a0SLloyd Pique  * </interface>
191*84e872a0SLloyd Pique  * \endcode
192*84e872a0SLloyd Pique  *
193*84e872a0SLloyd Pique  * Given two wl_message arrays `foo_requests` and `foo_events`, a wl_interface
194*84e872a0SLloyd Pique  * for `foo` might be:
195*84e872a0SLloyd Pique  *
196*84e872a0SLloyd Pique  * \code
197*84e872a0SLloyd Pique  * struct wl_interface foo_interface = {
198*84e872a0SLloyd Pique  *         "foo", 1,
199*84e872a0SLloyd Pique  *         2, foo_requests,
200*84e872a0SLloyd Pique  *         1, foo_events
201*84e872a0SLloyd Pique  * };
202*84e872a0SLloyd Pique  * \endcode
203*84e872a0SLloyd Pique  *
204*84e872a0SLloyd Pique  * \note The server side of the protocol may define interface <em>implementation
205*84e872a0SLloyd Pique  *       types</em> that incorporate the term `interface` in their name. Take
206*84e872a0SLloyd Pique  *       care to not confuse these server-side `struct`s with a wl_interface
207*84e872a0SLloyd Pique  *       variable whose name also ends in `interface`. For example, while the
208*84e872a0SLloyd Pique  *       server may define a type `struct wl_foo_interface`, the client may
209*84e872a0SLloyd Pique  *       define a `struct wl_interface wl_foo_interface`.
210*84e872a0SLloyd Pique  *
211*84e872a0SLloyd Pique  * \sa wl_message
212*84e872a0SLloyd Pique  * \sa wl_proxy
213*84e872a0SLloyd Pique  * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Interfaces">Interfaces</a>
214*84e872a0SLloyd Pique  * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Versioning">Versioning</a>
215*84e872a0SLloyd Pique  */
216*84e872a0SLloyd Pique struct wl_interface {
217*84e872a0SLloyd Pique 	/** Interface name */
218*84e872a0SLloyd Pique 	const char *name;
219*84e872a0SLloyd Pique 	/** Interface version */
220*84e872a0SLloyd Pique 	int version;
221*84e872a0SLloyd Pique 	/** Number of methods (requests) */
222*84e872a0SLloyd Pique 	int method_count;
223*84e872a0SLloyd Pique 	/** Method (request) signatures */
224*84e872a0SLloyd Pique 	const struct wl_message *methods;
225*84e872a0SLloyd Pique 	/** Number of events */
226*84e872a0SLloyd Pique 	int event_count;
227*84e872a0SLloyd Pique 	/** Event signatures */
228*84e872a0SLloyd Pique 	const struct wl_message *events;
229*84e872a0SLloyd Pique };
230*84e872a0SLloyd Pique 
231*84e872a0SLloyd Pique /** \class wl_list
232*84e872a0SLloyd Pique  *
233*84e872a0SLloyd Pique  * \brief Doubly-linked list
234*84e872a0SLloyd Pique  *
235*84e872a0SLloyd Pique  * On its own, an instance of `struct wl_list` represents the sentinel head of
236*84e872a0SLloyd Pique  * a doubly-linked list, and must be initialized using wl_list_init().
237*84e872a0SLloyd Pique  * When empty, the list head's `next` and `prev` members point to the list head
238*84e872a0SLloyd Pique  * itself, otherwise `next` references the first element in the list, and `prev`
239*84e872a0SLloyd Pique  * refers to the last element in the list.
240*84e872a0SLloyd Pique  *
241*84e872a0SLloyd Pique  * Use the `struct wl_list` type to represent both the list head and the links
242*84e872a0SLloyd Pique  * between elements within the list. Use wl_list_empty() to determine if the
243*84e872a0SLloyd Pique  * list is empty in O(1).
244*84e872a0SLloyd Pique  *
245*84e872a0SLloyd Pique  * All elements in the list must be of the same type. The element type must have
246*84e872a0SLloyd Pique  * a `struct wl_list` member, often named `link` by convention. Prior to
247*84e872a0SLloyd Pique  * insertion, there is no need to initialize an element's `link` - invoking
248*84e872a0SLloyd Pique  * wl_list_init() on an individual list element's `struct wl_list` member is
249*84e872a0SLloyd Pique  * unnecessary if the very next operation is wl_list_insert(). However, a
250*84e872a0SLloyd Pique  * common idiom is to initialize an element's `link` prior to removal - ensure
251*84e872a0SLloyd Pique  * safety by invoking wl_list_init() before wl_list_remove().
252*84e872a0SLloyd Pique  *
253*84e872a0SLloyd Pique  * Consider a list reference `struct wl_list foo_list`, an element type as
254*84e872a0SLloyd Pique  * `struct element`, and an element's link member as `struct wl_list link`.
255*84e872a0SLloyd Pique  *
256*84e872a0SLloyd Pique  * The following code initializes a list and adds three elements to it.
257*84e872a0SLloyd Pique  *
258*84e872a0SLloyd Pique  * \code
259*84e872a0SLloyd Pique  * struct wl_list foo_list;
260*84e872a0SLloyd Pique  *
261*84e872a0SLloyd Pique  * struct element {
262*84e872a0SLloyd Pique  *         int foo;
263*84e872a0SLloyd Pique  *         struct wl_list link;
264*84e872a0SLloyd Pique  * };
265*84e872a0SLloyd Pique  * struct element e1, e2, e3;
266*84e872a0SLloyd Pique  *
267*84e872a0SLloyd Pique  * wl_list_init(&foo_list);
268*84e872a0SLloyd Pique  * wl_list_insert(&foo_list, &e1.link);   // e1 is the first element
269*84e872a0SLloyd Pique  * wl_list_insert(&foo_list, &e2.link);   // e2 is now the first element
270*84e872a0SLloyd Pique  * wl_list_insert(&e2.link, &e3.link); // insert e3 after e2
271*84e872a0SLloyd Pique  * \endcode
272*84e872a0SLloyd Pique  *
273*84e872a0SLloyd Pique  * The list now looks like <em>[e2, e3, e1]</em>.
274*84e872a0SLloyd Pique  *
275*84e872a0SLloyd Pique  * The `wl_list` API provides some iterator macros. For example, to iterate
276*84e872a0SLloyd Pique  * a list in ascending order:
277*84e872a0SLloyd Pique  *
278*84e872a0SLloyd Pique  * \code
279*84e872a0SLloyd Pique  * struct element *e;
280*84e872a0SLloyd Pique  * wl_list_for_each(e, foo_list, link) {
281*84e872a0SLloyd Pique  *         do_something_with_element(e);
282*84e872a0SLloyd Pique  * }
283*84e872a0SLloyd Pique  * \endcode
284*84e872a0SLloyd Pique  *
285*84e872a0SLloyd Pique  * See the documentation of each iterator for details.
286*84e872a0SLloyd Pique  * \sa http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h
287*84e872a0SLloyd Pique  */
288*84e872a0SLloyd Pique struct wl_list {
289*84e872a0SLloyd Pique 	/** Previous list element */
290*84e872a0SLloyd Pique 	struct wl_list *prev;
291*84e872a0SLloyd Pique 	/** Next list element */
292*84e872a0SLloyd Pique 	struct wl_list *next;
293*84e872a0SLloyd Pique };
294*84e872a0SLloyd Pique 
295*84e872a0SLloyd Pique /**
296*84e872a0SLloyd Pique  * Initializes the list.
297*84e872a0SLloyd Pique  *
298*84e872a0SLloyd Pique  * \param list List to initialize
299*84e872a0SLloyd Pique  *
300*84e872a0SLloyd Pique  * \memberof wl_list
301*84e872a0SLloyd Pique  */
302*84e872a0SLloyd Pique void
303*84e872a0SLloyd Pique wl_list_init(struct wl_list *list);
304*84e872a0SLloyd Pique 
305*84e872a0SLloyd Pique /**
306*84e872a0SLloyd Pique  * Inserts an element into the list, after the element represented by \p list.
307*84e872a0SLloyd Pique  * When \p list is a reference to the list itself (the head), set the containing
308*84e872a0SLloyd Pique  * struct of \p elm as the first element in the list.
309*84e872a0SLloyd Pique  *
310*84e872a0SLloyd Pique  * \note If \p elm is already part of a list, inserting it again will lead to
311*84e872a0SLloyd Pique  *       list corruption.
312*84e872a0SLloyd Pique  *
313*84e872a0SLloyd Pique  * \param list List element after which the new element is inserted
314*84e872a0SLloyd Pique  * \param elm Link of the containing struct to insert into the list
315*84e872a0SLloyd Pique  *
316*84e872a0SLloyd Pique  * \memberof wl_list
317*84e872a0SLloyd Pique  */
318*84e872a0SLloyd Pique void
319*84e872a0SLloyd Pique wl_list_insert(struct wl_list *list, struct wl_list *elm);
320*84e872a0SLloyd Pique 
321*84e872a0SLloyd Pique /**
322*84e872a0SLloyd Pique  * Removes an element from the list.
323*84e872a0SLloyd Pique  *
324*84e872a0SLloyd Pique  * \note This operation leaves \p elm in an invalid state.
325*84e872a0SLloyd Pique  *
326*84e872a0SLloyd Pique  * \param elm Link of the containing struct to remove from the list
327*84e872a0SLloyd Pique  *
328*84e872a0SLloyd Pique  * \memberof wl_list
329*84e872a0SLloyd Pique  */
330*84e872a0SLloyd Pique void
331*84e872a0SLloyd Pique wl_list_remove(struct wl_list *elm);
332*84e872a0SLloyd Pique 
333*84e872a0SLloyd Pique /**
334*84e872a0SLloyd Pique  * Determines the length of the list.
335*84e872a0SLloyd Pique  *
336*84e872a0SLloyd Pique  * \note This is an O(n) operation.
337*84e872a0SLloyd Pique  *
338*84e872a0SLloyd Pique  * \param list List whose length is to be determined
339*84e872a0SLloyd Pique  *
340*84e872a0SLloyd Pique  * \return Number of elements in the list
341*84e872a0SLloyd Pique  *
342*84e872a0SLloyd Pique  * \memberof wl_list
343*84e872a0SLloyd Pique  */
344*84e872a0SLloyd Pique int
345*84e872a0SLloyd Pique wl_list_length(const struct wl_list *list);
346*84e872a0SLloyd Pique 
347*84e872a0SLloyd Pique /**
348*84e872a0SLloyd Pique  * Determines if the list is empty.
349*84e872a0SLloyd Pique  *
350*84e872a0SLloyd Pique  * \param list List whose emptiness is to be determined
351*84e872a0SLloyd Pique  *
352*84e872a0SLloyd Pique  * \return 1 if empty, or 0 if not empty
353*84e872a0SLloyd Pique  *
354*84e872a0SLloyd Pique  * \memberof wl_list
355*84e872a0SLloyd Pique  */
356*84e872a0SLloyd Pique int
357*84e872a0SLloyd Pique wl_list_empty(const struct wl_list *list);
358*84e872a0SLloyd Pique 
359*84e872a0SLloyd Pique /**
360*84e872a0SLloyd Pique  * Inserts all of the elements of one list into another, after the element
361*84e872a0SLloyd Pique  * represented by \p list.
362*84e872a0SLloyd Pique  *
363*84e872a0SLloyd Pique  * \note This leaves \p other in an invalid state.
364*84e872a0SLloyd Pique  *
365*84e872a0SLloyd Pique  * \param list List element after which the other list elements will be inserted
366*84e872a0SLloyd Pique  * \param other List of elements to insert
367*84e872a0SLloyd Pique  *
368*84e872a0SLloyd Pique  * \memberof wl_list
369*84e872a0SLloyd Pique  */
370*84e872a0SLloyd Pique void
371*84e872a0SLloyd Pique wl_list_insert_list(struct wl_list *list, struct wl_list *other);
372*84e872a0SLloyd Pique 
373*84e872a0SLloyd Pique /**
374*84e872a0SLloyd Pique  * Retrieves a pointer to a containing struct, given a member name.
375*84e872a0SLloyd Pique  *
376*84e872a0SLloyd Pique  * This macro allows "conversion" from a pointer to a member to its containing
377*84e872a0SLloyd Pique  * struct. This is useful if you have a contained item like a wl_list,
378*84e872a0SLloyd Pique  * wl_listener, or wl_signal, provided via a callback or other means, and would
379*84e872a0SLloyd Pique  * like to retrieve the struct that contains it.
380*84e872a0SLloyd Pique  *
381*84e872a0SLloyd Pique  * To demonstrate, the following example retrieves a pointer to
382*84e872a0SLloyd Pique  * `example_container` given only its `destroy_listener` member:
383*84e872a0SLloyd Pique  *
384*84e872a0SLloyd Pique  * \code
385*84e872a0SLloyd Pique  * struct example_container {
386*84e872a0SLloyd Pique  *         struct wl_listener destroy_listener;
387*84e872a0SLloyd Pique  *         // other members...
388*84e872a0SLloyd Pique  * };
389*84e872a0SLloyd Pique  *
390*84e872a0SLloyd Pique  * void example_container_destroy(struct wl_listener *listener, void *data)
391*84e872a0SLloyd Pique  * {
392*84e872a0SLloyd Pique  *         struct example_container *ctr;
393*84e872a0SLloyd Pique  *
394*84e872a0SLloyd Pique  *         ctr = wl_container_of(listener, ctr, destroy_listener);
395*84e872a0SLloyd Pique  *         // destroy ctr...
396*84e872a0SLloyd Pique  * }
397*84e872a0SLloyd Pique  * \endcode
398*84e872a0SLloyd Pique  *
399*84e872a0SLloyd Pique  * \note `sample` need not be a valid pointer. A null or uninitialised pointer
400*84e872a0SLloyd Pique  *       is sufficient.
401*84e872a0SLloyd Pique  *
402*84e872a0SLloyd Pique  * \param ptr Valid pointer to the contained member
403*84e872a0SLloyd Pique  * \param sample Pointer to a struct whose type contains \p ptr
404*84e872a0SLloyd Pique  * \param member Named location of \p ptr within the \p sample type
405*84e872a0SLloyd Pique  *
406*84e872a0SLloyd Pique  * \return The container for the specified pointer
407*84e872a0SLloyd Pique  */
408*84e872a0SLloyd Pique #define wl_container_of(ptr, sample, member)				\
409*84e872a0SLloyd Pique 	(__typeof__(sample))((char *)(ptr) -				\
410*84e872a0SLloyd Pique 			     offsetof(__typeof__(*sample), member))
411*84e872a0SLloyd Pique 
412*84e872a0SLloyd Pique /**
413*84e872a0SLloyd Pique  * Iterates over a list.
414*84e872a0SLloyd Pique  *
415*84e872a0SLloyd Pique  * This macro expresses a for-each iterator for wl_list. Given a list and
416*84e872a0SLloyd Pique  * wl_list link member name (often named `link` by convention), this macro
417*84e872a0SLloyd Pique  * assigns each element in the list to \p pos, which can then be referenced in
418*84e872a0SLloyd Pique  * a trailing code block. For example, given a wl_list of `struct message`
419*84e872a0SLloyd Pique  * elements:
420*84e872a0SLloyd Pique  *
421*84e872a0SLloyd Pique  * \code
422*84e872a0SLloyd Pique  * struct message {
423*84e872a0SLloyd Pique  *         char *contents;
424*84e872a0SLloyd Pique  *         wl_list link;
425*84e872a0SLloyd Pique  * };
426*84e872a0SLloyd Pique  *
427*84e872a0SLloyd Pique  * struct wl_list *message_list;
428*84e872a0SLloyd Pique  * // Assume message_list now "contains" many messages
429*84e872a0SLloyd Pique  *
430*84e872a0SLloyd Pique  * struct message *m;
431*84e872a0SLloyd Pique  * wl_list_for_each(m, message_list, link) {
432*84e872a0SLloyd Pique  *         do_something_with_message(m);
433*84e872a0SLloyd Pique  * }
434*84e872a0SLloyd Pique  * \endcode
435*84e872a0SLloyd Pique  *
436*84e872a0SLloyd Pique  * \param pos Cursor that each list element will be assigned to
437*84e872a0SLloyd Pique  * \param head Head of the list to iterate over
438*84e872a0SLloyd Pique  * \param member Name of the link member within the element struct
439*84e872a0SLloyd Pique  *
440*84e872a0SLloyd Pique  * \relates wl_list
441*84e872a0SLloyd Pique  */
442*84e872a0SLloyd Pique #define wl_list_for_each(pos, head, member)				\
443*84e872a0SLloyd Pique 	for (pos = wl_container_of((head)->next, pos, member);	\
444*84e872a0SLloyd Pique 	     &pos->member != (head);					\
445*84e872a0SLloyd Pique 	     pos = wl_container_of(pos->member.next, pos, member))
446*84e872a0SLloyd Pique 
447*84e872a0SLloyd Pique /**
448*84e872a0SLloyd Pique  * Iterates over a list, safe against removal of the list element.
449*84e872a0SLloyd Pique  *
450*84e872a0SLloyd Pique  * \note Only removal of the current element, \p pos, is safe. Removing
451*84e872a0SLloyd Pique  *       any other element during traversal may lead to a loop malfunction.
452*84e872a0SLloyd Pique  *
453*84e872a0SLloyd Pique  * \sa wl_list_for_each()
454*84e872a0SLloyd Pique  *
455*84e872a0SLloyd Pique  * \param pos Cursor that each list element will be assigned to
456*84e872a0SLloyd Pique  * \param tmp Temporary pointer of the same type as \p pos
457*84e872a0SLloyd Pique  * \param head Head of the list to iterate over
458*84e872a0SLloyd Pique  * \param member Name of the link member within the element struct
459*84e872a0SLloyd Pique  *
460*84e872a0SLloyd Pique  * \relates wl_list
461*84e872a0SLloyd Pique  */
462*84e872a0SLloyd Pique #define wl_list_for_each_safe(pos, tmp, head, member)			\
463*84e872a0SLloyd Pique 	for (pos = wl_container_of((head)->next, pos, member),		\
464*84e872a0SLloyd Pique 	     tmp = wl_container_of((pos)->member.next, tmp, member);	\
465*84e872a0SLloyd Pique 	     &pos->member != (head);					\
466*84e872a0SLloyd Pique 	     pos = tmp,							\
467*84e872a0SLloyd Pique 	     tmp = wl_container_of(pos->member.next, tmp, member))
468*84e872a0SLloyd Pique 
469*84e872a0SLloyd Pique /**
470*84e872a0SLloyd Pique  * Iterates backwards over a list.
471*84e872a0SLloyd Pique  *
472*84e872a0SLloyd Pique  * \sa wl_list_for_each()
473*84e872a0SLloyd Pique  *
474*84e872a0SLloyd Pique  * \param pos Cursor that each list element will be assigned to
475*84e872a0SLloyd Pique  * \param head Head of the list to iterate over
476*84e872a0SLloyd Pique  * \param member Name of the link member within the element struct
477*84e872a0SLloyd Pique  *
478*84e872a0SLloyd Pique  * \relates wl_list
479*84e872a0SLloyd Pique  */
480*84e872a0SLloyd Pique #define wl_list_for_each_reverse(pos, head, member)			\
481*84e872a0SLloyd Pique 	for (pos = wl_container_of((head)->prev, pos, member);	\
482*84e872a0SLloyd Pique 	     &pos->member != (head);					\
483*84e872a0SLloyd Pique 	     pos = wl_container_of(pos->member.prev, pos, member))
484*84e872a0SLloyd Pique 
485*84e872a0SLloyd Pique /**
486*84e872a0SLloyd Pique  * Iterates backwards over a list, safe against removal of the list element.
487*84e872a0SLloyd Pique  *
488*84e872a0SLloyd Pique  * \note Only removal of the current element, \p pos, is safe. Removing
489*84e872a0SLloyd Pique  *       any other element during traversal may lead to a loop malfunction.
490*84e872a0SLloyd Pique  *
491*84e872a0SLloyd Pique  * \sa wl_list_for_each()
492*84e872a0SLloyd Pique  *
493*84e872a0SLloyd Pique  * \param pos Cursor that each list element will be assigned to
494*84e872a0SLloyd Pique  * \param tmp Temporary pointer of the same type as \p pos
495*84e872a0SLloyd Pique  * \param head Head of the list to iterate over
496*84e872a0SLloyd Pique  * \param member Name of the link member within the element struct
497*84e872a0SLloyd Pique  *
498*84e872a0SLloyd Pique  * \relates wl_list
499*84e872a0SLloyd Pique  */
500*84e872a0SLloyd Pique #define wl_list_for_each_reverse_safe(pos, tmp, head, member)		\
501*84e872a0SLloyd Pique 	for (pos = wl_container_of((head)->prev, pos, member),	\
502*84e872a0SLloyd Pique 	     tmp = wl_container_of((pos)->member.prev, tmp, member);	\
503*84e872a0SLloyd Pique 	     &pos->member != (head);					\
504*84e872a0SLloyd Pique 	     pos = tmp,							\
505*84e872a0SLloyd Pique 	     tmp = wl_container_of(pos->member.prev, tmp, member))
506*84e872a0SLloyd Pique 
507*84e872a0SLloyd Pique /**
508*84e872a0SLloyd Pique  * \class wl_array
509*84e872a0SLloyd Pique  *
510*84e872a0SLloyd Pique  * Dynamic array
511*84e872a0SLloyd Pique  *
512*84e872a0SLloyd Pique  * A wl_array is a dynamic array that can only grow until released. It is
513*84e872a0SLloyd Pique  * intended for relatively small allocations whose size is variable or not known
514*84e872a0SLloyd Pique  * in advance. While construction of a wl_array does not require all elements to
515*84e872a0SLloyd Pique  * be of the same size, wl_array_for_each() does require all elements to have
516*84e872a0SLloyd Pique  * the same type and size.
517*84e872a0SLloyd Pique  *
518*84e872a0SLloyd Pique  */
519*84e872a0SLloyd Pique struct wl_array {
520*84e872a0SLloyd Pique 	/** Array size */
521*84e872a0SLloyd Pique 	size_t size;
522*84e872a0SLloyd Pique 	/** Allocated space */
523*84e872a0SLloyd Pique 	size_t alloc;
524*84e872a0SLloyd Pique 	/** Array data */
525*84e872a0SLloyd Pique 	void *data;
526*84e872a0SLloyd Pique };
527*84e872a0SLloyd Pique 
528*84e872a0SLloyd Pique /**
529*84e872a0SLloyd Pique  * Initializes the array.
530*84e872a0SLloyd Pique  *
531*84e872a0SLloyd Pique  * \param array Array to initialize
532*84e872a0SLloyd Pique  *
533*84e872a0SLloyd Pique  * \memberof wl_array
534*84e872a0SLloyd Pique  */
535*84e872a0SLloyd Pique void
536*84e872a0SLloyd Pique wl_array_init(struct wl_array *array);
537*84e872a0SLloyd Pique 
538*84e872a0SLloyd Pique /**
539*84e872a0SLloyd Pique  * Releases the array data.
540*84e872a0SLloyd Pique  *
541*84e872a0SLloyd Pique  * \note Leaves the array in an invalid state.
542*84e872a0SLloyd Pique  *
543*84e872a0SLloyd Pique  * \param array Array whose data is to be released
544*84e872a0SLloyd Pique  *
545*84e872a0SLloyd Pique  * \memberof wl_array
546*84e872a0SLloyd Pique  */
547*84e872a0SLloyd Pique void
548*84e872a0SLloyd Pique wl_array_release(struct wl_array *array);
549*84e872a0SLloyd Pique 
550*84e872a0SLloyd Pique /**
551*84e872a0SLloyd Pique  * Increases the size of the array by \p size bytes.
552*84e872a0SLloyd Pique  *
553*84e872a0SLloyd Pique  * \param array Array whose size is to be increased
554*84e872a0SLloyd Pique  * \param size Number of bytes to increase the size of the array by
555*84e872a0SLloyd Pique  *
556*84e872a0SLloyd Pique  * \return A pointer to the beginning of the newly appended space, or NULL when
557*84e872a0SLloyd Pique  *         resizing fails.
558*84e872a0SLloyd Pique  *
559*84e872a0SLloyd Pique  * \memberof wl_array
560*84e872a0SLloyd Pique  */
561*84e872a0SLloyd Pique void *
562*84e872a0SLloyd Pique wl_array_add(struct wl_array *array, size_t size);
563*84e872a0SLloyd Pique 
564*84e872a0SLloyd Pique /**
565*84e872a0SLloyd Pique  * Copies the contents of \p source to \p array.
566*84e872a0SLloyd Pique  *
567*84e872a0SLloyd Pique  * \param array Destination array to copy to
568*84e872a0SLloyd Pique  * \param source Source array to copy from
569*84e872a0SLloyd Pique  *
570*84e872a0SLloyd Pique  * \return 0 on success, or -1 on failure
571*84e872a0SLloyd Pique  *
572*84e872a0SLloyd Pique  * \memberof wl_array
573*84e872a0SLloyd Pique  */
574*84e872a0SLloyd Pique int
575*84e872a0SLloyd Pique wl_array_copy(struct wl_array *array, struct wl_array *source);
576*84e872a0SLloyd Pique 
577*84e872a0SLloyd Pique /**
578*84e872a0SLloyd Pique  * Iterates over an array.
579*84e872a0SLloyd Pique  *
580*84e872a0SLloyd Pique  * This macro expresses a for-each iterator for wl_array. It assigns each
581*84e872a0SLloyd Pique  * element in the array to \p pos, which can then be referenced in a trailing
582*84e872a0SLloyd Pique  * code block. \p pos must be a pointer to the array element type, and all
583*84e872a0SLloyd Pique  * array elements must be of the same type and size.
584*84e872a0SLloyd Pique  *
585*84e872a0SLloyd Pique  * \param pos Cursor that each array element will be assigned to
586*84e872a0SLloyd Pique  * \param array Array to iterate over
587*84e872a0SLloyd Pique  *
588*84e872a0SLloyd Pique  * \relates wl_array
589*84e872a0SLloyd Pique  * \sa wl_list_for_each()
590*84e872a0SLloyd Pique  */
591*84e872a0SLloyd Pique #define wl_array_for_each(pos, array)					\
592*84e872a0SLloyd Pique 	for (pos = (array)->data;					\
593*84e872a0SLloyd Pique 	     (const char *) pos < ((const char *) (array)->data + (array)->size); \
594*84e872a0SLloyd Pique 	     (pos)++)
595*84e872a0SLloyd Pique 
596*84e872a0SLloyd Pique /**
597*84e872a0SLloyd Pique  * Fixed-point number
598*84e872a0SLloyd Pique  *
599*84e872a0SLloyd Pique  * A `wl_fixed_t` is a 24.8 signed fixed-point number with a sign bit, 23 bits
600*84e872a0SLloyd Pique  * of integer precision and 8 bits of decimal precision. Consider `wl_fixed_t`
601*84e872a0SLloyd Pique  * as an opaque struct with methods that facilitate conversion to and from
602*84e872a0SLloyd Pique  * `double` and `int` types.
603*84e872a0SLloyd Pique  */
604*84e872a0SLloyd Pique typedef int32_t wl_fixed_t;
605*84e872a0SLloyd Pique 
606*84e872a0SLloyd Pique /**
607*84e872a0SLloyd Pique  * Converts a fixed-point number to a floating-point number.
608*84e872a0SLloyd Pique  *
609*84e872a0SLloyd Pique  * \param f Fixed-point number to convert
610*84e872a0SLloyd Pique  *
611*84e872a0SLloyd Pique  * \return Floating-point representation of the fixed-point argument
612*84e872a0SLloyd Pique  */
613*84e872a0SLloyd Pique static inline double
wl_fixed_to_double(wl_fixed_t f)614*84e872a0SLloyd Pique wl_fixed_to_double(wl_fixed_t f)
615*84e872a0SLloyd Pique {
616*84e872a0SLloyd Pique 	union {
617*84e872a0SLloyd Pique 		double d;
618*84e872a0SLloyd Pique 		int64_t i;
619*84e872a0SLloyd Pique 	} u;
620*84e872a0SLloyd Pique 
621*84e872a0SLloyd Pique 	u.i = ((1023LL + 44LL) << 52) + (1LL << 51) + f;
622*84e872a0SLloyd Pique 
623*84e872a0SLloyd Pique 	return u.d - (3LL << 43);
624*84e872a0SLloyd Pique }
625*84e872a0SLloyd Pique 
626*84e872a0SLloyd Pique /**
627*84e872a0SLloyd Pique  * Converts a floating-point number to a fixed-point number.
628*84e872a0SLloyd Pique  *
629*84e872a0SLloyd Pique  * \param d Floating-point number to convert
630*84e872a0SLloyd Pique  *
631*84e872a0SLloyd Pique  * \return Fixed-point representation of the floating-point argument
632*84e872a0SLloyd Pique  */
633*84e872a0SLloyd Pique static inline wl_fixed_t
wl_fixed_from_double(double d)634*84e872a0SLloyd Pique wl_fixed_from_double(double d)
635*84e872a0SLloyd Pique {
636*84e872a0SLloyd Pique 	union {
637*84e872a0SLloyd Pique 		double d;
638*84e872a0SLloyd Pique 		int64_t i;
639*84e872a0SLloyd Pique 	} u;
640*84e872a0SLloyd Pique 
641*84e872a0SLloyd Pique 	u.d = d + (3LL << (51 - 8));
642*84e872a0SLloyd Pique 
643*84e872a0SLloyd Pique 	return (wl_fixed_t)u.i;
644*84e872a0SLloyd Pique }
645*84e872a0SLloyd Pique 
646*84e872a0SLloyd Pique /**
647*84e872a0SLloyd Pique  * Converts a fixed-point number to an integer.
648*84e872a0SLloyd Pique  *
649*84e872a0SLloyd Pique  * \param f Fixed-point number to convert
650*84e872a0SLloyd Pique  *
651*84e872a0SLloyd Pique  * \return Integer component of the fixed-point argument
652*84e872a0SLloyd Pique  */
653*84e872a0SLloyd Pique static inline int
wl_fixed_to_int(wl_fixed_t f)654*84e872a0SLloyd Pique wl_fixed_to_int(wl_fixed_t f)
655*84e872a0SLloyd Pique {
656*84e872a0SLloyd Pique 	return f / 256;
657*84e872a0SLloyd Pique }
658*84e872a0SLloyd Pique 
659*84e872a0SLloyd Pique /**
660*84e872a0SLloyd Pique  * Converts an integer to a fixed-point number.
661*84e872a0SLloyd Pique  *
662*84e872a0SLloyd Pique  * \param i Integer to convert
663*84e872a0SLloyd Pique  *
664*84e872a0SLloyd Pique  * \return Fixed-point representation of the integer argument
665*84e872a0SLloyd Pique  */
666*84e872a0SLloyd Pique static inline wl_fixed_t
wl_fixed_from_int(int i)667*84e872a0SLloyd Pique wl_fixed_from_int(int i)
668*84e872a0SLloyd Pique {
669*84e872a0SLloyd Pique 	return i * 256;
670*84e872a0SLloyd Pique }
671*84e872a0SLloyd Pique 
672*84e872a0SLloyd Pique /**
673*84e872a0SLloyd Pique  * Protocol message argument data types
674*84e872a0SLloyd Pique  *
675*84e872a0SLloyd Pique  * This union represents all of the argument types in the Wayland protocol wire
676*84e872a0SLloyd Pique  * format. The protocol implementation uses wl_argument within its marshalling
677*84e872a0SLloyd Pique  * machinery for dispatching messages between a client and a compositor.
678*84e872a0SLloyd Pique  *
679*84e872a0SLloyd Pique  * \sa wl_message
680*84e872a0SLloyd Pique  * \sa wl_interface
681*84e872a0SLloyd Pique  * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-wire-Format">Wire Format</a>
682*84e872a0SLloyd Pique  */
683*84e872a0SLloyd Pique union wl_argument {
684*84e872a0SLloyd Pique 	int32_t i;           /**< `int`    */
685*84e872a0SLloyd Pique 	uint32_t u;          /**< `uint`   */
686*84e872a0SLloyd Pique 	wl_fixed_t f;        /**< `fixed`  */
687*84e872a0SLloyd Pique 	const char *s;       /**< `string` */
688*84e872a0SLloyd Pique 	struct wl_object *o; /**< `object` */
689*84e872a0SLloyd Pique 	uint32_t n;          /**< `new_id` */
690*84e872a0SLloyd Pique 	struct wl_array *a;  /**< `array`  */
691*84e872a0SLloyd Pique 	int32_t h;           /**< `fd`     */
692*84e872a0SLloyd Pique };
693*84e872a0SLloyd Pique 
694*84e872a0SLloyd Pique /**
695*84e872a0SLloyd Pique  * Dispatcher function type alias
696*84e872a0SLloyd Pique  *
697*84e872a0SLloyd Pique  * A dispatcher is a function that handles the emitting of callbacks in client
698*84e872a0SLloyd Pique  * code. For programs directly using the C library, this is done by using
699*84e872a0SLloyd Pique  * libffi to call function pointers. When binding to languages other than C,
700*84e872a0SLloyd Pique  * dispatchers provide a way to abstract the function calling process to be
701*84e872a0SLloyd Pique  * friendlier to other function calling systems.
702*84e872a0SLloyd Pique  *
703*84e872a0SLloyd Pique  * A dispatcher takes five arguments: The first is the dispatcher-specific
704*84e872a0SLloyd Pique  * implementation associated with the target object. The second is the object
705*84e872a0SLloyd Pique  * upon which the callback is being invoked (either wl_proxy or wl_resource).
706*84e872a0SLloyd Pique  * The third and fourth arguments are the opcode and the wl_message
707*84e872a0SLloyd Pique  * corresponding to the callback. The final argument is an array of arguments
708*84e872a0SLloyd Pique  * received from the other process via the wire protocol.
709*84e872a0SLloyd Pique  *
710*84e872a0SLloyd Pique  * \param user_data Dispatcher-specific implementation data
711*84e872a0SLloyd Pique  * \param target Callback invocation target (wl_proxy or `wl_resource`)
712*84e872a0SLloyd Pique  * \param opcode Callback opcode
713*84e872a0SLloyd Pique  * \param msg Callback message signature
714*84e872a0SLloyd Pique  * \param args Array of received arguments
715*84e872a0SLloyd Pique  *
716*84e872a0SLloyd Pique  * \return 0 on success, or -1 on failure
717*84e872a0SLloyd Pique  */
718*84e872a0SLloyd Pique typedef int (*wl_dispatcher_func_t)(const void *user_data, void *target,
719*84e872a0SLloyd Pique 				    uint32_t opcode, const struct wl_message *msg,
720*84e872a0SLloyd Pique 				    union wl_argument *args);
721*84e872a0SLloyd Pique 
722*84e872a0SLloyd Pique /**
723*84e872a0SLloyd Pique  * Log function type alias
724*84e872a0SLloyd Pique  *
725*84e872a0SLloyd Pique  * The C implementation of the Wayland protocol abstracts the details of
726*84e872a0SLloyd Pique  * logging. Users may customize the logging behavior, with a function conforming
727*84e872a0SLloyd Pique  * to the `wl_log_func_t` type, via `wl_log_set_handler_client` and
728*84e872a0SLloyd Pique  * `wl_log_set_handler_server`.
729*84e872a0SLloyd Pique  *
730*84e872a0SLloyd Pique  * A `wl_log_func_t` must conform to the expectations of `vprintf`, and
731*84e872a0SLloyd Pique  * expects two arguments: a string to write and a corresponding variable
732*84e872a0SLloyd Pique  * argument list. While the string to write may contain format specifiers and
733*84e872a0SLloyd Pique  * use values in the variable argument list, the behavior of any `wl_log_func_t`
734*84e872a0SLloyd Pique  * depends on the implementation.
735*84e872a0SLloyd Pique  *
736*84e872a0SLloyd Pique  * \note Take care to not confuse this with `wl_protocol_logger_func_t`, which
737*84e872a0SLloyd Pique  *       is a specific server-side logger for requests and events.
738*84e872a0SLloyd Pique  *
739*84e872a0SLloyd Pique  * \param fmt String to write to the log, containing optional format
740*84e872a0SLloyd Pique  *            specifiers
741*84e872a0SLloyd Pique  * \param args Variable argument list
742*84e872a0SLloyd Pique  *
743*84e872a0SLloyd Pique  * \sa wl_log_set_handler_client
744*84e872a0SLloyd Pique  * \sa wl_log_set_handler_server
745*84e872a0SLloyd Pique  */
746*84e872a0SLloyd Pique typedef void (*wl_log_func_t)(const char *fmt, va_list args) WL_PRINTF(1, 0);
747*84e872a0SLloyd Pique 
748*84e872a0SLloyd Pique /**
749*84e872a0SLloyd Pique  * Return value of an iterator function
750*84e872a0SLloyd Pique  *
751*84e872a0SLloyd Pique  * \sa wl_client_for_each_resource_iterator_func_t
752*84e872a0SLloyd Pique  * \sa wl_client_for_each_resource
753*84e872a0SLloyd Pique  */
754*84e872a0SLloyd Pique enum wl_iterator_result {
755*84e872a0SLloyd Pique 	/** Stop the iteration */
756*84e872a0SLloyd Pique 	WL_ITERATOR_STOP,
757*84e872a0SLloyd Pique 	/** Continue the iteration */
758*84e872a0SLloyd Pique 	WL_ITERATOR_CONTINUE
759*84e872a0SLloyd Pique };
760*84e872a0SLloyd Pique 
761*84e872a0SLloyd Pique #ifdef  __cplusplus
762*84e872a0SLloyd Pique }
763*84e872a0SLloyd Pique #endif
764*84e872a0SLloyd Pique 
765*84e872a0SLloyd Pique #endif
766