Allocate client proxy automatically for new objects

When the server send a new object ID, the client used to have to allocate
the proxy manually and without type-safety.  We now allocate the proxy
in a client-side post-processing step on the incoming closure.
This commit is contained in:
Kristian Høgsberg 2012-06-28 22:01:58 -04:00
parent c30ad0d9da
commit 9de9e39f87
4 changed files with 57 additions and 4 deletions

View file

@ -462,6 +462,31 @@ wl_display_roundtrip(struct wl_display *display)
wl_display_iterate(display, WL_DISPLAY_READABLE);
}
static int
create_proxies(struct wl_display *display, struct wl_closure *closure)
{
struct wl_proxy *proxy;
const char *signature;
uint32_t id;
int i;
signature = closure->message->signature;
for (i = 0; signature[i]; i++) {
switch (signature[i]) {
case 'n':
id = **(uint32_t **) closure->args[i + 2];
proxy = wl_proxy_create_for_id(&display->proxy, id,
closure->message->types[i]);
if (proxy == NULL)
return -1;
*(void **) closure->args[i + 2] = proxy;
break;
}
}
return 0;
}
static void
handle_event(struct wl_display *display,
uint32_t id, uint32_t opcode, uint32_t size)
@ -484,7 +509,7 @@ handle_event(struct wl_display *display,
closure = wl_connection_demarshal(display->connection, size,
&display->objects, message);
if (closure == NULL) {
if (closure == NULL || create_proxies(display, closure) < 0) {
fprintf(stderr, "Error demarshalling event\n");
abort();
}