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); }
static void dispatch_event(struct wl_display *display, struct wl_event_queue *queue) { struct wl_closure *closure; struct wl_proxy *proxy; int opcode; bool proxy_destroyed; closure = container_of(queue->event_list.next, struct wl_closure, link); wl_list_remove(&closure->link); opcode = closure->opcode; /* Verify that the receiving object is still valid by checking if has * been destroyed by the application. */ decrease_closure_args_refcount(closure); proxy = closure->proxy; proxy_destroyed = !!(proxy->flags & WL_PROXY_FLAG_DESTROYED); proxy->refcount--; if (proxy_destroyed) { if (!proxy->refcount) free(proxy); wl_closure_destroy(closure); return; } pthread_mutex_unlock(&display->mutex); if (proxy->dispatcher) { if (wl_debug) wl_closure_print(closure, &proxy->object, false); wl_closure_dispatch(closure, proxy->dispatcher, &proxy->object, opcode); } else if (proxy->object.implementation) { if (wl_debug) wl_closure_print(closure, &proxy->object, false); wl_closure_invoke(closure, WL_CLOSURE_INVOKE_CLIENT, &proxy->object, opcode, proxy->user_data); } wl_closure_destroy(closure); pthread_mutex_lock(&display->mutex); }
static void marshal_helper(const char *format, void *handler, ...) { struct wl_closure *closure; static struct wl_object sender = { NULL, NULL, 1234 }, object; static const int opcode = 4444; struct wl_message message = { "test", format, NULL }; va_list ap; int done; va_start(ap, handler); closure = wl_closure_vmarshal(&sender, opcode, ap, &message); va_end(ap); assert(closure); done = 0; wl_closure_invoke(closure, &object, handler, &done); wl_closure_destroy(closure); assert(done); }
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); }