summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2011-11-18 21:59:36 -0500
committerKristian Høgsberg <krh@bitplanet.net>2011-11-22 14:04:11 -0500
commitbdbd6ef80b85f5d20608f702a6ffaa1f1f73e7a4 (patch)
tree27de0aa7a408ab5130987b87922dd560de2ba562
parent190492b97c9db43a910f17c576244492e19bc658 (diff)
Add support for server allocated object IDs
We set aside a range of the object ID space for use by the server. This allows the server to bind an object to an ID for a client and pass that object to the client. The client can use the object immediately and the server can emit events to the object immdiately.
-rw-r--r--src/wayland-client.c36
-rw-r--r--src/wayland-client.h7
-rw-r--r--src/wayland-private.h9
-rw-r--r--src/wayland-server.c12
-rw-r--r--src/wayland-util.c74
5 files changed, 108 insertions, 30 deletions
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 2597ab2..c8bbe8f 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -132,7 +132,27 @@ wl_proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
proxy->object.interface = interface;
proxy->object.implementation = NULL;
- proxy->object.id = wl_map_insert_new(&display->objects, proxy);
+ proxy->object.id = wl_map_insert_new(&display->objects,
+ WL_MAP_CLIENT_SIDE, proxy);
+ proxy->display = display;
+
+ return proxy;
+}
+
+WL_EXPORT struct wl_proxy *
+wl_proxy_create_for_id(struct wl_proxy *factory,
+ uint32_t id, const struct wl_interface *interface)
+{
+ struct wl_proxy *proxy;
+ struct wl_display *display = factory->display;
+
+ proxy = malloc(sizeof *proxy);
+ if (proxy == NULL)
+ return NULL;
+
+ proxy->object.interface = interface;
+ proxy->object.implementation = NULL;
+ proxy->object.id = wl_map_insert_at(&display->objects, id, proxy);
proxy->display = display;
return proxy;
@@ -141,8 +161,12 @@ wl_proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
WL_EXPORT void
wl_proxy_destroy(struct wl_proxy *proxy)
{
- wl_map_insert_at(&proxy->display->objects,
- proxy->object.id, WL_ZOMBIE_OBJECT);
+ if (proxy->object.id < WL_SERVER_ID_START)
+ wl_map_insert_at(&proxy->display->objects,
+ proxy->object.id, WL_ZOMBIE_OBJECT);
+ else
+ wl_map_insert_at(&proxy->display->objects,
+ proxy->object.id, NULL);
free(proxy);
}
@@ -336,10 +360,12 @@ wl_display_connect(const char *name)
wl_list_init(&display->global_listener_list);
wl_list_init(&display->global_list);
- wl_map_insert_new(&display->objects, NULL);
+ wl_map_insert_new(&display->objects, WL_MAP_CLIENT_SIDE, NULL);
display->proxy.object.interface = &wl_display_interface;
- display->proxy.object.id = wl_map_insert_new(&display->objects, display);
+ display->proxy.object.id =
+ wl_map_insert_new(&display->objects,
+ WL_MAP_CLIENT_SIDE, display);
display->proxy.display = display;
display->proxy.object.implementation = (void(**)(void)) &display_listener;
display->proxy.user_data = display;
diff --git a/src/wayland-client.h b/src/wayland-client.h
index 691912a..efeee4a 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -35,9 +35,10 @@ struct wl_display;
void wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
struct wl_proxy *wl_proxy_create(struct wl_proxy *factory,
const struct wl_interface *interface);
-struct wl_proxy *wl_proxy_create_for_id(struct wl_display *display,
- const struct wl_interface *interface,
- uint32_t id);
+struct wl_proxy *wl_proxy_create_for_id(struct wl_proxy *factory,
+ uint32_t id,
+ const struct wl_interface *interface);
+
void wl_proxy_destroy(struct wl_proxy *proxy);
int wl_proxy_add_listener(struct wl_proxy *proxy,
void (**implementation)(void), void *data);
diff --git a/src/wayland-private.h b/src/wayland-private.h
index e302300..fada571 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -29,14 +29,19 @@
#define WL_ZOMBIE_OBJECT ((void *) 2)
+#define WL_MAP_SERVER_SIDE 0
+#define WL_MAP_CLIENT_SIDE 1
+#define WL_SERVER_ID_START 0xff000000
+
struct wl_map {
- struct wl_array entries;
+ struct wl_array client_entries;
+ struct wl_array server_entries;
uint32_t free_list;
};
void wl_map_init(struct wl_map *map);
void wl_map_release(struct wl_map *map);
-uint32_t wl_map_insert_new(struct wl_map *map, void *data);
+uint32_t wl_map_insert_new(struct wl_map *map, uint32_t side, void *data);
int wl_map_insert_at(struct wl_map *map, uint32_t i, void *data);
void wl_map_remove(struct wl_map *map, uint32_t i);
void *wl_map_lookup(struct wl_map *map, uint32_t i);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index d2bc0c0..d2ca043 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -336,9 +336,15 @@ wl_resource_destroy(struct wl_resource *resource, uint32_t time)
{
struct wl_client *client = resource->client;
- wl_resource_queue_event(resource->client->display_resource,
- WL_DISPLAY_DELETE_ID, resource->object.id);
- wl_map_insert_at(&client->objects, resource->object.id, NULL);
+ if (resource->object.id < WL_SERVER_ID_START) {
+ wl_resource_queue_event(resource->client->display_resource,
+ WL_DISPLAY_DELETE_ID,
+ resource->object.id);
+ wl_map_insert_at(&client->objects, resource->object.id, NULL);
+ } else {
+ wl_map_remove(&client->objects, resource->object.id);
+ }
+
destroy_resource(resource, &time);
}
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 43b095e..647b861 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -148,26 +148,37 @@ wl_map_init(struct wl_map *map)
WL_EXPORT void
wl_map_release(struct wl_map *map)
{
- wl_array_release(&map->entries);
+ wl_array_release(&map->client_entries);
+ wl_array_release(&map->server_entries);
}
WL_EXPORT uint32_t
-wl_map_insert_new(struct wl_map *map, void *data)
+wl_map_insert_new(struct wl_map *map, uint32_t side, void *data)
{
union map_entry *start, *entry;
+ struct wl_array *entries;
+ uint32_t base;
+
+ if (side == WL_MAP_CLIENT_SIDE) {
+ entries = &map->client_entries;
+ base = 0;
+ } else {
+ entries = &map->server_entries;
+ base = WL_SERVER_ID_START;
+ }
if (map->free_list) {
- start = map->entries.data;
+ start = entries->data;
entry = &start[map->free_list >> 1];
map->free_list = entry->next;
} else {
- entry = wl_array_add(&map->entries, sizeof *entry);
- start = map->entries.data;
+ entry = wl_array_add(entries, sizeof *entry);
+ start = entries->data;
}
entry->data = data;
- return entry - start;
+ return (entry - start) + base;
}
WL_EXPORT int
@@ -175,17 +186,23 @@ wl_map_insert_at(struct wl_map *map, uint32_t i, void *data)
{
union map_entry *start;
uint32_t count;
+ struct wl_array *entries;
- /* assert(map->free_list == NULL */
- count = map->entries.size / sizeof *start;
+ if (i < WL_SERVER_ID_START) {
+ entries = &map->client_entries;
+ } else {
+ entries = &map->server_entries;
+ i -= WL_SERVER_ID_START;
+ }
+ count = entries->size / sizeof *start;
if (count < i)
return -1;
if (count == i)
- wl_array_add(&map->entries, sizeof *start);
+ wl_array_add(entries, sizeof *start);
- start = map->entries.data;
+ start = entries->data;
start[i].data = data;
return 0;
@@ -195,8 +212,16 @@ WL_EXPORT void
wl_map_remove(struct wl_map *map, uint32_t i)
{
union map_entry *start;
+ struct wl_array *entries;
- start = map->entries.data;
+ if (i < WL_SERVER_ID_START) {
+ entries = &map->client_entries;
+ } else {
+ entries = &map->server_entries;
+ i -= WL_SERVER_ID_START;
+ }
+
+ start = entries->data;
start[i].next = map->free_list;
map->free_list = (i << 1) | 1;
}
@@ -206,9 +231,17 @@ wl_map_lookup(struct wl_map *map, uint32_t i)
{
union map_entry *start;
uint32_t count;
+ struct wl_array *entries;
+
+ if (i < WL_SERVER_ID_START) {
+ entries = &map->client_entries;
+ } else {
+ entries = &map->server_entries;
+ i -= WL_SERVER_ID_START;
+ }
- start = map->entries.data;
- count = map->entries.size / sizeof *start;
+ start = entries->data;
+ count = entries->size / sizeof *start;
if (i < count && !(start[i].next & 1))
return start[i].data;
@@ -216,15 +249,22 @@ wl_map_lookup(struct wl_map *map, uint32_t i)
return NULL;
}
-WL_EXPORT void
-wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
+static void
+for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)
{
union map_entry *start, *end, *p;
- start = map->entries.data;
- end = (union map_entry *) ((char *) map->entries.data + map->entries.size);
+ start = entries->data;
+ end = (union map_entry *) ((char *) entries->data + entries->size);
for (p = start; p < end; p++)
if (p->data && !(p->next & 1))
func(p->data, data);
}
+
+WL_EXPORT void
+wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
+{
+ for_each_helper(&map->client_entries, func, data);
+ for_each_helper(&map->server_entries, func, data);
+}