Bind globals to client provided object IDs
authorKristian Høgsberg <krh@bitplanet.net>
Fri, 19 Aug 2011 17:44:01 +0000 (13:44 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Sat, 27 Aug 2011 16:06:11 +0000 (12:06 -0400)
protocol/wayland.xml
src/scanner.c
src/wayland-client.c
src/wayland-client.h
src/wayland-server.c
src/wayland-server.h

index f1dd78e..ac1e2e5 100644 (file)
        It is used for internal wayland protocol features. -->
   <interface name="wl_display" version="1">
     <request name="bind">
-      <arg name="id" type="uint"/>
+      <arg name="name" type="uint"/>
       <arg name="interface" type="string"/>
       <arg name="version" type="uint"/>
+      <arg name="id" type="new_id" interface="wl_object"/>
     </request>
 
     <!-- sync is an just an echo, which will reply with a key event.
index b114fbf..d6e8969 100644 (file)
@@ -347,19 +347,6 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
        if (strcmp(interface->name, "wl_display") == 0)
                return;
 
-       printf("static inline struct %s *\n"
-              "%s_create(struct wl_display *display, uint32_t id, uint32_t version)\n"
-              "{\n"
-              "\twl_display_bind(display, id, \"%s\", version);\n\n"
-              "\treturn (struct %s *)\n"
-              "\t\twl_proxy_create_for_id(display, &%s_interface, id);\n"
-              "}\n\n",
-              interface->name,
-              interface->name,
-              interface->name,
-              interface->name,
-              interface->name);
-
        printf("static inline void\n"
               "%s_set_user_data(struct %s *%s, void *user_data)\n"
               "{\n"
index ec62885..f4920d7 100644 (file)
@@ -122,10 +122,10 @@ wl_display_remove_global_listener(struct wl_display *display,
 }
 
 WL_EXPORT struct wl_proxy *
-wl_proxy_create_for_id(struct wl_display *display,
-                      const struct wl_interface *interface, uint32_t id)
+wl_proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
 {
        struct wl_proxy *proxy;
+       struct wl_display *display = factory->display;
 
        proxy = malloc(sizeof *proxy);
        if (proxy == NULL)
@@ -133,21 +133,13 @@ wl_proxy_create_for_id(struct wl_display *display,
 
        proxy->object.interface = interface;
        proxy->object.implementation = NULL;
-       proxy->object.id = id;
+       proxy->object.id = wl_display_allocate_id(display);
        proxy->display = display;
        wl_hash_table_insert(display->objects, proxy->object.id, proxy);
 
        return proxy;
 }
 
-WL_EXPORT struct wl_proxy *
-wl_proxy_create(struct wl_proxy *factory,
-               const struct wl_interface *interface)
-{
-       return wl_proxy_create_for_id(factory->display, interface,
-                                     wl_display_allocate_id(factory->display));
-}
-
 WL_EXPORT void
 wl_proxy_destroy(struct wl_proxy *proxy)
 {
@@ -367,8 +359,6 @@ wl_display_connect(const char *name)
                return NULL;
        }
 
-       wl_display_bind(display, 1, "wl_display", 1);
-
        return display;
 }
 
@@ -524,12 +514,20 @@ wl_display_allocate_id(struct wl_display *display)
        return display->id++;
 }
 
-WL_EXPORT void
+WL_EXPORT void *
 wl_display_bind(struct wl_display *display,
-               uint32_t id, const char *interface, uint32_t version)
+               uint32_t name, const struct wl_interface *interface)
 {
-       wl_proxy_marshal(&display->proxy,
-                        WL_DISPLAY_BIND, id, interface, version);
+       struct wl_proxy *proxy;
+
+       proxy = wl_proxy_create(&display->proxy, interface);
+       if (proxy == NULL)
+               return NULL;
+
+       wl_proxy_marshal(&display->proxy, WL_DISPLAY_BIND,
+                        name, interface->name, interface->version, proxy);
+
+       return proxy;
 }
 
 WL_EXPORT struct wl_callback *
index dc5aa5f..53b323d 100644 (file)
@@ -44,8 +44,9 @@ int wl_proxy_add_listener(struct wl_proxy *proxy,
 void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
 void *wl_proxy_get_user_data(struct wl_proxy *proxy);
 
-void wl_display_bind(struct wl_display *display,
-                    uint32_t id, const char *interface, uint32_t version);
+void *wl_display_bind(struct wl_display *display,
+                     uint32_t name, const struct wl_interface *interface);
+
 struct wl_callback *wl_display_sync(struct wl_display *display);
 
 #include "wayland-client-protocol.h"
index 275e6de..337ac0b 100644 (file)
@@ -544,26 +544,24 @@ wl_input_device_update_grab(struct wl_input_device *device,
 
 static void
 display_bind(struct wl_client *client,
-            struct wl_resource *resource, uint32_t id,
-            const char *interface, uint32_t version)
+            struct wl_resource *resource, uint32_t name,
+            const char *interface, uint32_t version, uint32_t id)
 {
        struct wl_global *global;
        struct wl_display *display = resource->data;
 
        wl_list_for_each(global, &display->global_list, link)
-               if (global->object->id == id)
+               if (global->object->id == name)
                        break;
 
        if (&global->link == &display->global_list)
                wl_client_post_error(client, &client->display->resource.object,
                                     WL_DISPLAY_ERROR_INVALID_OBJECT,
-                                    "invalid object %d", id);
+                                    "invalid global %d", name);
        else if (global->bind)
-               global->bind(client, global->object, version);
+               global->bind(client, global->object, version, id);
 
-       wl_hash_table_insert(client->objects,
-                            global->object->id, global->object);
-               
+       wl_hash_table_insert(client->objects, id, global->object);
 }
 
 static void
@@ -849,12 +847,14 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 
 static void
 compositor_bind(struct wl_client *client,
-               struct wl_object *global, uint32_t version)
+               struct wl_object *global, uint32_t version, uint32_t id)
 {
        struct wl_compositor *compositor =
                container_of(global, struct wl_compositor, resource.object);
 
        compositor->resource.client = client;
+       compositor->resource.object.id = id;
+
        wl_resource_post_event(&compositor->resource,
                               WL_COMPOSITOR_TOKEN_VISUAL,
                               &compositor->argb_visual.object,
index 2077a1c..2ef4899 100644 (file)
@@ -87,7 +87,7 @@ void wl_display_add_object(struct wl_display *display,
 
 typedef void (*wl_global_bind_func_t)(struct wl_client *client,
                                      struct wl_object *global,
-                                     uint32_t version);
+                                     uint32_t version, uint32_t id);
 
 int wl_display_add_global(struct wl_display *display,
                          struct wl_object *object,