123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- #ifndef WAYLAND_UTIL_H
- #define WAYLAND_UTIL_H
- #include <math.h>
- #include <stddef.h>
- #include <inttypes.h>
- #include <stdarg.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define WL_EXPORT __attribute__ ((visibility("default")))
- #else
- #define WL_EXPORT
- #endif
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define WL_DEPRECATED __attribute__ ((deprecated))
- #else
- #define WL_DEPRECATED
- #endif
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define WL_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
- #else
- #define WL_PRINTF(x, y)
- #endif
- struct wl_message {
- const char *name;
- const char *signature;
- const struct wl_interface **types;
- };
- struct wl_interface {
- const char *name;
- int version;
- int method_count;
- const struct wl_message *methods;
- int event_count;
- const struct wl_message *events;
- };
- struct wl_list {
- struct wl_list *prev;
- struct wl_list *next;
- };
- void
- wl_list_init(struct wl_list *list);
- void
- wl_list_insert(struct wl_list *list, struct wl_list *elm);
- void
- wl_list_remove(struct wl_list *elm);
- int
- wl_list_length(const struct wl_list *list);
- int
- wl_list_empty(const struct wl_list *list);
- void
- wl_list_insert_list(struct wl_list *list, struct wl_list *other);
- #define wl_container_of(ptr, sample, member) \
- (__typeof__(sample))((char *)(ptr) - \
- offsetof(__typeof__(*sample), member))
- #define wl_list_for_each(pos, head, member) \
- for (pos = wl_container_of((head)->next, pos, member); \
- &pos->member != (head); \
- pos = wl_container_of(pos->member.next, pos, member))
- #define wl_list_for_each_safe(pos, tmp, head, member) \
- for (pos = wl_container_of((head)->next, pos, member), \
- tmp = wl_container_of((pos)->member.next, tmp, member); \
- &pos->member != (head); \
- pos = tmp, \
- tmp = wl_container_of(pos->member.next, tmp, member))
- #define wl_list_for_each_reverse(pos, head, member) \
- for (pos = wl_container_of((head)->prev, pos, member); \
- &pos->member != (head); \
- pos = wl_container_of(pos->member.prev, pos, member))
- #define wl_list_for_each_reverse_safe(pos, tmp, head, member) \
- for (pos = wl_container_of((head)->prev, pos, member), \
- tmp = wl_container_of((pos)->member.prev, tmp, member); \
- &pos->member != (head); \
- pos = tmp, \
- tmp = wl_container_of(pos->member.prev, tmp, member))
- struct wl_array {
- size_t size;
- size_t alloc;
- void *data;
- };
- #define wl_array_for_each(pos, array) \
- for (pos = (array)->data; \
- (const char *) pos < ((const char *) (array)->data + (array)->size); \
- (pos)++)
- void
- wl_array_init(struct wl_array *array);
- void
- wl_array_release(struct wl_array *array);
- void *
- wl_array_add(struct wl_array *array, size_t size);
- int
- wl_array_copy(struct wl_array *array, struct wl_array *source);
- typedef int32_t wl_fixed_t;
- static inline double
- wl_fixed_to_double (wl_fixed_t f)
- {
- union {
- double d;
- int64_t i;
- } u;
- u.i = ((1023LL + 44LL) << 52) + (1LL << 51) + f;
- return u.d - (3LL << 43);
- }
- static inline wl_fixed_t
- wl_fixed_from_double(double d)
- {
- union {
- double d;
- int64_t i;
- } u;
- u.d = d + (3LL << (51 - 8));
- return u.i;
- }
- static inline int
- wl_fixed_to_int(wl_fixed_t f)
- {
- return f / 256;
- }
- static inline wl_fixed_t
- wl_fixed_from_int(int i)
- {
- return i * 256;
- }
- union wl_argument {
- int32_t i;
- uint32_t u;
- wl_fixed_t f;
- const char *s;
- struct wl_object *o;
- uint32_t n;
- struct wl_array *a;
- int32_t h;
- };
- typedef int (*wl_dispatcher_func_t)(const void *, void *, uint32_t,
- const struct wl_message *,
- union wl_argument *);
- typedef void (*wl_log_func_t)(const char *, va_list) WL_PRINTF(1, 0);
- #ifdef __cplusplus
- }
- #endif
- #endif
|