Product SiteDocumentation Site

5.2. Server API

Following is the Wayland library classes for the Server (libwayland-server). Note that most of the procedures are related with IPC, which is the main responsibility of the library.
wl_list - doubly-linked list
The list head is of "struct wl_list" type, and must be initialized using wl_list_init(). All entries in the list must be of the same type. The item type must have a "struct wl_list" member. This member will be initialized by wl_list_insert(). There is no need to call wl_list_init() on the individual item. To query if the list is empty in O(1), use wl_list_empty().
Let's call the list reference "struct wl_list foo_list", the item type as "item_t", and the item member as "struct wl_list link".
The following code will initialize a list: struct wl_list foo_list; struct item_t { int foo; struct wl_list link; }; struct item_t item1, item2, item3; wl_list_init(&foo_list); wl_list_insert(&foo_list, &item1.link); Pushes item1 at the head wl_list_insert(&foo_list, &item2.link); Pushes item2 at the head wl_list_insert(&item2.link, &item3.link); Pushes item3 after item2
The list now looks like [item2, item3, item1]
Will iterate the list in ascending order: item_t *item; wl_list_for_each(item, foo_list, link) { Do_something_with_item(item);
wl_listener - A single listener for Wayland signals.
wl_listener provides the means to listen for wl_signal notifications. Many Wayland objects use wl_listener for notification of significant events like object destruction.
Clients should create wl_listener objects manually and can register them as listeners to signals using wl_signal_add, assuming the signal is directly accessible. For opaque structs like wl_event_loop, adding a listener should be done through provided accessor methods. A listener can only listen to one signal at a time.
structwl_listeneryour_listener; your_listener.notify=your_callback_method; /*Directaccess*/ wl_signal_add(&some_object->destroy_signal,&your_listener); /*Accessoraccess*/ wl_event_loop*loop=...; wl_event_loop_add_destroy_listener(loop,&your_listener);
If the listener is part of a larger struct, wl_container_of can be used to retrieve a pointer to it:
*voidyour_listener(structwl_listener*listener,void*data) *{ *structyour_data*data=NULL; * *your_data=wl_container_of(listener,data,your_member_name); *} *
If you need to remove a listener from a signal, use #wl_list_remove.
*wl_list_remove(&your_listener.link); *
wl_signal
wl_signal - A source of a type of observable event.
Signals are recognized points where significant events can be observed. Compositors as well as the server can provide signals. Observers are wl_listener's that are added through wl_signal_add. Signals are emitted using wl_signal_emit, which will invoke all listeners until that listener is removed by #wl_list_remove (or whenever the signal is destroyed).
wl_listener for more information on using wl_signal
Methods for the respective classes.
wl_signal_init - Initialize a new wl_signal for use.
static void wl_signal_init(struct wl_signal *signal)
signal
The signal that will be initialized
wl_signal_add - Add the specified listener to this signal.
static void wl_signal_add(struct wl_signal *signal, struct wl_listener *listener)
signal
The signal that will emit events to the listener
listener
The listener to add
wl_signal_get - Gets the listener struct for the specified callback.
static struct wl_listener * wl_signal_get(struct wl_signal *signal, wl_notify_func_t notify)
signal
The signal that contains the specified listener
notify
The listener that is the target of this search
Returns:
the list item that corresponds to the specified listener, or NULL if none was found
wl_signal_emit - Emits this signal, notifying all registered listeners.
static void wl_signal_emit(struct wl_signal *signal, void *data)
signal
The signal object that will emit the signal
data
The data that will be emitted with the signal
wl_resource_post_event_array -
void wl_resource_post_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
wl_resource_post_event -
void wl_resource_post_event(struct wl_resource *resource, uint32_t opcode,...)
wl_resource_queue_event_array -
void wl_resource_queue_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
wl_resource_queue_event -
void wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode,...)
wl_resource_post_error -
void wl_resource_post_error(struct wl_resource *resource, uint32_t code, const char *msg,...)
wl_client_flush -
void wl_client_flush(struct wl_client *client)
wl_client_get_display -
struct wl_display* wl_client_get_display(struct wl_client *client)
wl_client_create -
struct wl_client* wl_client_create(struct wl_display *display, int fd)
wl_client_get_credentials -
void wl_client_get_credentials(struct wl_client *client, pid_t *pid, uid_t *uid, gid_t *gid)
wl_client_get_object -
struct wl_resource* wl_client_get_object(struct wl_client *client, uint32_t id)
wl_client_post_no_memory -
void wl_client_post_no_memory(struct wl_client *client)
wl_resource_post_no_memory -
void wl_resource_post_no_memory(struct wl_resource *resource)
wl_resource_destroy -
void wl_resource_destroy(struct wl_resource *resource)
wl_resource_get_id -
uint32_t wl_resource_get_id(struct wl_resource *resource)
wl_resource_get_link -
struct wl_list* wl_resource_get_link(struct wl_resource *resource)
wl_resource_from_link -
struct wl_resource* wl_resource_from_link(struct wl_list *link)
wl_resource_find_for_client -
struct wl_resource* wl_resource_find_for_client(struct wl_list *list, struct wl_client *client)
wl_resource_get_client -
struct wl_client* wl_resource_get_client(struct wl_resource *resource)
wl_resource_set_user_data -
void wl_resource_set_user_data(struct wl_resource *resource, void *data)
wl_resource_get_user_data -
void* wl_resource_get_user_data(struct wl_resource *resource)
wl_resource_get_version -
int wl_resource_get_version(struct wl_resource *resource)
wl_resource_set_destructor -
void wl_resource_set_destructor(struct wl_resource *resource, wl_resource_destroy_func_t destroy)
wl_resource_instance_of -
int wl_resource_instance_of(struct wl_resource *resource, const struct wl_interface *interface, const void *implementation)
wl_resource_add_destroy_listener -
void wl_resource_add_destroy_listener(struct wl_resource *resource, struct wl_listener *listener)
wl_resource_get_destroy_listener -
struct wl_listener* wl_resource_get_destroy_listener(struct wl_resource *resource, wl_notify_func_t notify)
wl_client_add_destroy_listener -
void wl_client_add_destroy_listener(struct wl_client *client, struct wl_listener *listener)
wl_client_get_destroy_listener -
struct wl_listener* wl_client_get_destroy_listener(struct wl_client *client, wl_notify_func_t notify)
wl_client_destroy -
void wl_client_destroy(struct wl_client *client)
wl_display_create -
struct wl_display* wl_display_create(void)
wl_display_destroy -
void wl_display_destroy(struct wl_display *display)
wl_global_create -
struct wl_global* wl_global_create(struct wl_display *display, const struct wl_interface *interface, int version, void *data, wl_global_bind_func_t bind)
wl_global_destroy -
void wl_global_destroy(struct wl_global *global)
wl_display_get_serial -
uint32_t wl_display_get_serial(struct wl_display *display)
wl_display_next_serial -
uint32_t wl_display_next_serial(struct wl_display *display)
wl_display_get_event_loop -
struct wl_event_loop* wl_display_get_event_loop(struct wl_display *display)
wl_display_terminate -
void wl_display_terminate(struct wl_display *display)
wl_display_run -
void wl_display_run(struct wl_display *display)
wl_display_flush_clients -
void wl_display_flush_clients(struct wl_display *display)
wl_display_add_socket -
int wl_display_add_socket(struct wl_display *display, const char *name)
wl_display_add_destroy_listener -
void wl_display_add_destroy_listener(struct wl_display *display, struct wl_listener *listener)
wl_display_get_destroy_listener -
struct wl_listener* wl_display_get_destroy_listener(struct wl_display *display, wl_notify_func_t notify)
wl_resource_set_implementation -
void wl_resource_set_implementation(struct wl_resource *resource, const void *implementation, void *data, wl_resource_destroy_func_t destroy)
wl_resource_set_dispatcher -
void wl_resource_set_dispatcher(struct wl_resource *resource, wl_dispatcher_func_t dispatcher, const void *implementation, void *data, wl_resource_destroy_func_t destroy)
wl_resource_create -
struct wl_resource* wl_resource_create(struct wl_client *client, const struct wl_interface *interface, int version, uint32_t id)
wl_log_set_handler_server -
void wl_log_set_handler_server(wl_log_func_t handler)
wl_client_add_resource -
uint32_t wl_client_add_resource(struct wl_client *client, struct wl_resource *resource) WL_DEPRECATED
wl_client_add_object -
struct wl_resource * wl_client_add_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, uint32_t id, void *data) WL_DEPRECATED
wl_client_new_object -
struct wl_resource * wl_client_new_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, void *data) WL_DEPRECATED
wl_display_add_global -
struct wl_global * wl_display_add_global(struct wl_display *display, const struct wl_interface *interface, void *data, wl_global_bind_func_t bind) WL_DEPRECATED
wl_display_remove_global -
void wl_display_remove_global(struct wl_display *display, struct wl_global *global) WL_DEPRECATED
wl_display_add_shm_format -
void wl_display_add_shm_format(struct wl_display *display, uint32_t format)
wl_display_get_additional_shm_formats -
struct wl_array* wl_display_get_additional_shm_formats(struct wl_display *display)
wl_list_init -
void wl_list_init(struct wl_list *list)
wl_list_insert -
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
wl_list_remove -
void wl_list_remove(struct wl_list *elm)
wl_list_length -
int wl_list_length(const struct wl_list *list)
wl_list_empty -
int wl_list_empty(const struct wl_list *list)
wl_list_insert_list -
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
wl_array_init -
void wl_array_init(struct wl_array *array)
wl_array_release -
void wl_array_release(struct wl_array *array)
wl_array_add -
void* wl_array_add(struct wl_array *array, size_t size)
wl_array_copy -
int wl_array_copy(struct wl_array *array, struct wl_array *source)
wl_map_init -
void wl_map_init(struct wl_map *map, uint32_t side)
wl_map_release -
void wl_map_release(struct wl_map *map)
wl_map_insert_new -
uint32_t wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)
wl_map_insert_at -
int wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)
wl_map_reserve_new -
int wl_map_reserve_new(struct wl_map *map, uint32_t i)
wl_map_remove -
void wl_map_remove(struct wl_map *map, uint32_t i)
wl_map_lookup -
void* wl_map_lookup(struct wl_map *map, uint32_t i)
wl_map_lookup_flags -
uint32_t wl_map_lookup_flags(struct wl_map *map, uint32_t i)
wl_map_for_each -
void wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
wl_log -
void wl_log(const char *fmt,...)
wl_list_init -
void wl_list_init(struct wl_list *list)
wl_list_insert -
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
wl_list_remove -
void wl_list_remove(struct wl_list *elm)
wl_list_length -
int wl_list_length(const struct wl_list *list)
wl_list_empty -
int wl_list_empty(const struct wl_list *list)
wl_list_insert_list -
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
wl_array_init -
void wl_array_init(struct wl_array *array)
wl_array_release -
void wl_array_release(struct wl_array *array)
wl_array_add -
void* wl_array_add(struct wl_array *array, size_t size)
wl_array_copy -
int wl_array_copy(struct wl_array *array, struct wl_array *source)