1/*
2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2011 Intel Corporation
4 * Copyright © 2013 Jason Ekstrand
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#ifndef WAYLAND_PRIVATE_H
29#define WAYLAND_PRIVATE_H
30
31#include <stdarg.h>
32#include <stdlib.h>
33#include <stdint.h>
34#include <stdbool.h>
35
36#define WL_HIDE_DEPRECATED 1
37
38#include "wayland-util.h"
39
40/* Invalid memory address */
41#define WL_ARRAY_POISON_PTR (void *) 4
42
43#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
44
45#define WL_MAP_SERVER_SIDE 0
46#define WL_MAP_CLIENT_SIDE 1
47#define WL_SERVER_ID_START 0xff000000
48#define WL_CLOSURE_MAX_ARGS 20
49
50struct wl_object {
51 const struct wl_interface *interface;
52 const void *implementation;
53 uint32_t id;
54};
55
56int
57wl_interface_equal(const struct wl_interface *iface1,
58 const struct wl_interface *iface2);
59
60/* Flags for wl_map_insert_new and wl_map_insert_at. Flags can be queried with
61 * wl_map_lookup_flags. The current implementation has room for 1 bit worth of
62 * flags. If more flags are ever added, the implementation of wl_map will have
63 * to change to allow for new flags */
64enum wl_map_entry_flags {
65 WL_MAP_ENTRY_LEGACY = (1 << 0), /* Server side only */
66 WL_MAP_ENTRY_ZOMBIE = (1 << 0) /* Client side only */
67};
68
69struct wl_map {
70 struct wl_array client_entries;
71 struct wl_array server_entries;
72 uint32_t side;
73 uint32_t free_list;
74};
75
76typedef enum wl_iterator_result (*wl_iterator_func_t)(void *element,
77 void *data,
78 uint32_t flags);
79
80void
81wl_map_init(struct wl_map *map, uint32_t side);
82
83void
84wl_map_release(struct wl_map *map);
85
86uint32_t
87wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data);
88
89int
90wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data);
91
92int
93wl_map_reserve_new(struct wl_map *map, uint32_t i);
94
95void
96wl_map_remove(struct wl_map *map, uint32_t i);
97
98void *
99wl_map_lookup(struct wl_map *map, uint32_t i);
100
101uint32_t
102wl_map_lookup_flags(struct wl_map *map, uint32_t i);
103
104void
105wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data);
106
107struct wl_connection *
108wl_connection_create(int fd);
109
110int
111wl_connection_destroy(struct wl_connection *connection);
112
113void
114wl_connection_copy(struct wl_connection *connection, void *data, size_t size);
115
116void
117wl_connection_consume(struct wl_connection *connection, size_t size);
118
119int
120wl_connection_flush(struct wl_connection *connection);
121
122uint32_t
123wl_connection_pending_input(struct wl_connection *connection);
124
125int
126wl_connection_read(struct wl_connection *connection);
127
128int
129wl_connection_write(struct wl_connection *connection,
130 const void *data, size_t count);
131
132int
133wl_connection_queue(struct wl_connection *connection,
134 const void *data, size_t count);
135
136int
137wl_connection_get_fd(struct wl_connection *connection);
138
139struct wl_closure {
140 int count;
141 const struct wl_message *message;
142 uint32_t opcode;
143 uint32_t sender_id;
144 union wl_argument args[WL_CLOSURE_MAX_ARGS];
145 struct wl_list link;
146 struct wl_proxy *proxy;
147 struct wl_array extra[0];
148};
149
150struct argument_details {
151 char type;
152 int nullable;
153};
154
155const char *
156get_next_argument(const char *signature, struct argument_details *details);
157
158int
159arg_count_for_signature(const char *signature);
160
161int
162wl_message_count_arrays(const struct wl_message *message);
163
164int
165wl_message_get_since(const struct wl_message *message);
166
167void
168wl_argument_from_va_list(const char *signature, union wl_argument *args,
169 int count, va_list ap);
170
171struct wl_closure *
172wl_closure_marshal(struct wl_object *sender,
173 uint32_t opcode, union wl_argument *args,
174 const struct wl_message *message);
175
176struct wl_closure *
177wl_closure_vmarshal(struct wl_object *sender,
178 uint32_t opcode, va_list ap,
179 const struct wl_message *message);
180
181struct wl_closure *
182wl_connection_demarshal(struct wl_connection *connection,
183 uint32_t size,
184 struct wl_map *objects,
185 const struct wl_message *message);
186
187bool
188wl_object_is_zombie(struct wl_map *map, uint32_t id);
189
190int
191wl_closure_lookup_objects(struct wl_closure *closure, struct wl_map *objects);
192
193enum wl_closure_invoke_flag {
194 WL_CLOSURE_INVOKE_CLIENT = (1 << 0),
195 WL_CLOSURE_INVOKE_SERVER = (1 << 1)
196};
197
198void
199wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
200 struct wl_object *target, uint32_t opcode, void *data);
201
202void
203wl_closure_dispatch(struct wl_closure *closure, wl_dispatcher_func_t dispatcher,
204 struct wl_object *target, uint32_t opcode);
205
206int
207wl_closure_send(struct wl_closure *closure, struct wl_connection *connection);
208
209int
210wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection);
211
212void
213wl_closure_print(struct wl_closure *closure,
214 struct wl_object *target, int send, int discarded,
215 uint32_t (*n_parse)(union wl_argument *arg));
216
217void
218wl_closure_destroy(struct wl_closure *closure);
219
220extern wl_log_func_t wl_log_handler;
221
222void wl_log(const char *fmt, ...);
223void wl_abort(const char *fmt, ...);
224
225struct wl_display;
226
227struct wl_array *
228wl_display_get_additional_shm_formats(struct wl_display *display);
229
230static inline void *
231zalloc(size_t s)
232{
233 return calloc(nmemb: 1, size: s);
234}
235
236void
237wl_connection_close_fds_in(struct wl_connection *connection, int max);
238
239#endif
240

source code of gtk/subprojects/wayland/src/wayland-private.h