static void marshal_demarshal(struct marshal_data *data, void (*func)(void), int size, const char *format, ...) { struct wl_closure *closure; static const int opcode = 4444; static struct wl_object sender = { NULL, NULL, 1234 }; struct wl_message message = { "test", format, NULL }; struct wl_map objects; struct wl_object object = { NULL, &func, 0 }; va_list ap; uint32_t msg[1] = { 1234 }; va_start(ap, format); closure = wl_closure_vmarshal(&sender, opcode, ap, &message); va_end(ap); assert(closure); assert(wl_closure_send(closure, data->write_connection) == 0); wl_closure_destroy(closure); assert(wl_connection_flush(data->write_connection) == size); assert(wl_connection_read(data->read_connection) == size); wl_map_init(&objects, WL_MAP_SERVER_SIDE); object.id = msg[0]; closure = wl_connection_demarshal(data->read_connection, size, &objects, &message); assert(closure); wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, &object, 0, data); wl_closure_destroy(closure); }
/** Connect to Wayland display on an already open fd * * \param fd The fd to use for the connection * \return A \ref wl_display object or \c NULL on failure * * The wl_display takes ownership of the fd and will close it when the * display is destroyed. The fd will also be closed in case of * failure. * * \memberof wl_display */ WL_EXPORT struct wl_display * wl_display_connect_to_fd(int fd) { struct wl_display *display; const char *debug; debug = getenv("WAYLAND_DEBUG"); if (debug && (strstr(debug, "client") || strstr(debug, "1"))) debug_client = 1; display = malloc(sizeof *display); if (display == NULL) { close(fd); return NULL; } memset(display, 0, sizeof *display); display->fd = fd; wl_map_init(&display->objects, WL_MAP_CLIENT_SIDE); wl_event_queue_init(&display->default_queue, display); wl_event_queue_init(&display->display_queue, display); wl_list_init(&display->event_queue_list); pthread_mutex_init(&display->mutex, NULL); pthread_cond_init(&display->reader_cond, NULL); display->reader_count = 0; wl_map_insert_new(&display->objects, 0, NULL); display->proxy.object.interface = &wl_display_interface; display->proxy.object.id = wl_map_insert_new(&display->objects, 0, display); display->proxy.display = display; display->proxy.object.implementation = (void(**)(void)) &display_listener; display->proxy.user_data = display; display->proxy.queue = &display->default_queue; display->proxy.flags = 0; display->proxy.refcount = 1; display->connection = wl_connection_create(display->fd); if (display->connection == NULL) goto err_connection; printf("<< %s:%u\n", __func__, __LINE__); return display; err_connection: pthread_mutex_destroy(&display->mutex); pthread_cond_destroy(&display->reader_cond); wl_map_release(&display->objects); close(display->fd); free(display); return NULL; }
static void expected_fail_demarshal(struct marshal_data *data, const char *format, const uint32_t *msg, int expected_error) { struct wl_message message = { "test", format, NULL }; struct wl_closure *closure; struct wl_map objects; int size = (msg[1] >> 16); assert(write(data->s[1], msg, size) == size); assert(wl_connection_read(data->read_connection) == size); wl_map_init(&objects, WL_MAP_SERVER_SIDE); closure = wl_connection_demarshal(data->read_connection, size, &objects, &message); assert(closure == NULL); assert(errno == expected_error); }
static void demarshal(struct marshal_data *data, const char *format, uint32_t *msg, void (*func)(void)) { struct wl_message message = { "test", format, NULL }; struct wl_closure *closure; struct wl_map objects; struct wl_object object = { NULL, &func, 0 }; int size = msg[1]; assert(write(data->s[1], msg, size) == size); assert(wl_connection_read(data->read_connection) == size); wl_map_init(&objects, WL_MAP_SERVER_SIDE); object.id = msg[0]; closure = wl_connection_demarshal(data->read_connection, size, &objects, &message); assert(closure); wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, &object, 0, data); wl_closure_destroy(closure); }
static void demarshal(struct marshal_data *data, const char *format, uint32_t *msg, void (*func)(void)) { struct wl_message message = { "test", format, NULL }; struct wl_closure *closure; struct wl_map objects; struct wl_object object; int size = msg[1]; assert(write(data->s[1], msg, size) == size); assert(wl_connection_data(data->read_connection, WL_CONNECTION_READABLE) == size); wl_map_init(&objects); object.id = msg[0]; closure = wl_connection_demarshal(data->read_connection, size, &objects, &message); assert(closure); wl_closure_invoke(closure, &object, func, data); wl_closure_destroy(closure); }
static void marshal_demarshal(struct marshal_data *data, void (*func)(void), int size, const char *format, ...) { struct wl_closure *closure; static const int opcode = 4444; static struct wl_object sender = { NULL, NULL, 1234 }; struct wl_message message = { "test", format, NULL }; struct wl_map objects; struct wl_object object; va_list ap; uint32_t msg[1] = { 1234 }; va_start(ap, format); closure = wl_closure_vmarshal(&sender, opcode, ap, &message); va_end(ap); assert(closure); assert(wl_closure_send(closure, data->write_connection) == 0); wl_closure_destroy(closure); assert(data->write_mask == (WL_CONNECTION_WRITABLE | WL_CONNECTION_READABLE)); assert(wl_connection_data(data->write_connection, WL_CONNECTION_WRITABLE) == 0); assert(data->write_mask == WL_CONNECTION_READABLE); assert(wl_connection_data(data->read_connection, WL_CONNECTION_READABLE) == size); wl_map_init(&objects); object.id = msg[0]; closure = wl_connection_demarshal(data->read_connection, size, &objects, &message); wl_closure_invoke(closure, &object, func, data); wl_closure_destroy(closure); }