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