Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright  2008-2011 Kristian Hgsberg
      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 
     35 #define WL_HIDE_DEPRECATED 1
     36 
     37 #include "wayland-util.h"
     38 
     39 /* Invalid memory address */
     40 #define WL_ARRAY_POISON_PTR (void *) 4
     41 
     42 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
     43 
     44 #define container_of(ptr, type, member) ({				\
     45 	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
     46 	(type *)( (char *)__mptr - offsetof(type,member) );})
     47 
     48 #define WL_MAP_SERVER_SIDE 0
     49 #define WL_MAP_CLIENT_SIDE 1
     50 #define WL_SERVER_ID_START 0xff000000
     51 #define WL_CLOSURE_MAX_ARGS 20
     52 
     53 struct wl_object {
     54 	const struct wl_interface *interface;
     55 	const void *implementation;
     56 	uint32_t id;
     57 };
     58 
     59 extern struct wl_object global_zombie_object;
     60 #define WL_ZOMBIE_OBJECT ((void*)&global_zombie_object)
     61 
     62 int
     63 wl_interface_equal(const struct wl_interface *iface1,
     64 		   const struct wl_interface *iface2);
     65 
     66 /* Flags for wl_map_insert_new and wl_map_insert_at.  Flags can be queried with
     67  * wl_map_lookup_flags.  The current implementation has room for 1 bit worth of
     68  * flags.  If more flags are ever added, the implementation of wl_map will have
     69  * to change to allow for new flags */
     70 enum wl_map_entry_flags {
     71 	WL_MAP_ENTRY_LEGACY = (1 << 0)
     72 };
     73 
     74 struct wl_map {
     75 	struct wl_array client_entries;
     76 	struct wl_array server_entries;
     77 	uint32_t side;
     78 	uint32_t free_list;
     79 };
     80 
     81 typedef enum wl_iterator_result (*wl_iterator_func_t)(void *element,
     82 						      void *data);
     83 
     84 void
     85 wl_map_init(struct wl_map *map, uint32_t side);
     86 
     87 void
     88 wl_map_release(struct wl_map *map);
     89 
     90 uint32_t
     91 wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data);
     92 
     93 int
     94 wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data);
     95 
     96 int
     97 wl_map_reserve_new(struct wl_map *map, uint32_t i);
     98 
     99 void
    100 wl_map_remove(struct wl_map *map, uint32_t i);
    101 
    102 void *
    103 wl_map_lookup(struct wl_map *map, uint32_t i);
    104 
    105 uint32_t
    106 wl_map_lookup_flags(struct wl_map *map, uint32_t i);
    107 
    108 void
    109 wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data);
    110 
    111 struct wl_connection *
    112 wl_connection_create(int fd);
    113 
    114 int
    115 wl_connection_destroy(struct wl_connection *connection);
    116 
    117 void
    118 wl_connection_copy(struct wl_connection *connection, void *data, size_t size);
    119 
    120 void
    121 wl_connection_consume(struct wl_connection *connection, size_t size);
    122 
    123 int
    124 wl_connection_flush(struct wl_connection *connection);
    125 
    126 uint32_t
    127 wl_connection_pending_input(struct wl_connection *connection);
    128 
    129 int
    130 wl_connection_read(struct wl_connection *connection);
    131 
    132 int
    133 wl_connection_write(struct wl_connection *connection,
    134 		    const void *data, size_t count);
    135 
    136 int
    137 wl_connection_queue(struct wl_connection *connection,
    138 		    const void *data, size_t count);
    139 
    140 int
    141 wl_connection_get_fd(struct wl_connection *connection);
    142 
    143 struct wl_closure {
    144 	int count;
    145 	const struct wl_message *message;
    146 	uint32_t opcode;
    147 	uint32_t sender_id;
    148 	union wl_argument args[WL_CLOSURE_MAX_ARGS];
    149 	struct wl_list link;
    150 	struct wl_proxy *proxy;
    151 	struct wl_array extra[0];
    152 };
    153 
    154 struct argument_details {
    155 	char type;
    156 	int nullable;
    157 };
    158 
    159 const char *
    160 get_next_argument(const char *signature, struct argument_details *details);
    161 
    162 int
    163 arg_count_for_signature(const char *signature);
    164 
    165 int
    166 wl_message_count_arrays(const struct wl_message *message);
    167 
    168 int
    169 wl_message_get_since(const struct wl_message *message);
    170 
    171 void
    172 wl_argument_from_va_list(const char *signature, union wl_argument *args,
    173 			 int count, va_list ap);
    174 
    175 struct wl_closure *
    176 wl_closure_marshal(struct wl_object *sender,
    177 		    uint32_t opcode, union wl_argument *args,
    178 		    const struct wl_message *message);
    179 
    180 struct wl_closure *
    181 wl_closure_vmarshal(struct wl_object *sender,
    182 		    uint32_t opcode, va_list ap,
    183 		    const struct wl_message *message);
    184 
    185 struct wl_closure *
    186 wl_connection_demarshal(struct wl_connection *connection,
    187 			uint32_t size,
    188 			struct wl_map *objects,
    189 			const struct wl_message *message);
    190 
    191 int
    192 wl_closure_lookup_objects(struct wl_closure *closure, struct wl_map *objects);
    193 
    194 enum wl_closure_invoke_flag {
    195 	WL_CLOSURE_INVOKE_CLIENT = (1 << 0),
    196 	WL_CLOSURE_INVOKE_SERVER = (1 << 1)
    197 };
    198 
    199 void
    200 wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
    201 		  struct wl_object *target, uint32_t opcode, void *data);
    202 
    203 void
    204 wl_closure_dispatch(struct wl_closure *closure, wl_dispatcher_func_t dispatcher,
    205 		    struct wl_object *target, uint32_t opcode);
    206 
    207 int
    208 wl_closure_send(struct wl_closure *closure, struct wl_connection *connection);
    209 
    210 int
    211 wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection);
    212 
    213 void
    214 wl_closure_print(struct wl_closure *closure,
    215 		 struct wl_object *target, int send);
    216 
    217 void
    218 wl_closure_destroy(struct wl_closure *closure);
    219 
    220 extern wl_log_func_t wl_log_handler;
    221 
    222 void wl_log(const char *fmt, ...);
    223 void wl_abort(const char *fmt, ...);
    224 
    225 struct wl_display;
    226 
    227 struct wl_array *
    228 wl_display_get_additional_shm_formats(struct wl_display *display);
    229 
    230 static inline void *
    231 zalloc(size_t s)
    232 {
    233 	return calloc(1, s);
    234 }
    235 
    236 #endif
    237