aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSebastian Wick <sebastian@sebastianwick.net>2021-10-25 04:34:49 +0200
committerDaniel Stone <daniels@collabora.com>2024-02-15 10:53:21 +0000
commit9c4213ed3eb3942766712df936775d827b846d0b (patch)
tree8e78708e916547e5dbaa247386e6d0b7f959ad5c /tests
parentevent-loop: use wl_priv_signal for the destroy signal (diff)
downloadwayland-9c4213ed3eb3942766712df936775d827b846d0b.tar
wayland-9c4213ed3eb3942766712df936775d827b846d0b.tar.gz
wayland-9c4213ed3eb3942766712df936775d827b846d0b.tar.bz2
wayland-9c4213ed3eb3942766712df936775d827b846d0b.tar.lz
wayland-9c4213ed3eb3942766712df936775d827b846d0b.tar.xz
wayland-9c4213ed3eb3942766712df936775d827b846d0b.tar.zst
wayland-9c4213ed3eb3942766712df936775d827b846d0b.zip
server: add wl_client_get_user_data/wl_client_set_user_data
The only way to attach some data to a wl_client seems to be setting up a destroy listener and use wl_container_of. Let's make it straight forward to attach some data. Having an explicit destroy callback for the user data makes managing the user data lifetime much more convenient. All other callbacks, be they wl_resource request listeners, destroy listeners or destructors, or wl_client destroy listeners, can assume that the wl_client user data still exists if it was set. Otherwise making that guarantee would be complicated. Co-authored-by: Pekka Paalanen <pekka.paalanen@collabora.com> Signed-off-by: Sebastian Wick <sebastian@sebastianwick.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/client-test.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/client-test.c b/tests/client-test.c
index 47be83f..659bac1 100644
--- a/tests/client-test.c
+++ b/tests/client-test.c
@@ -80,12 +80,21 @@ client_late_destroy_notify(struct wl_listener *l, void *data)
listener->late_done = true;
}
+static void
+client_user_data_destroy(void *data)
+{
+ bool *user_data_destroyed = data;
+
+ *user_data_destroyed = true;
+}
+
TEST(client_destroy_listener)
{
struct wl_display *display;
struct wl_client *client;
struct wl_resource *resource;
struct client_destroy_listener a, b;
+ bool user_data_destroyed = false;
int s[2];
assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
@@ -94,6 +103,9 @@ TEST(client_destroy_listener)
client = wl_client_create(display, s[0]);
assert(client);
+ wl_client_set_user_data(client, &user_data_destroyed, client_user_data_destroy);
+ assert(wl_client_get_user_data(client) == &user_data_destroyed);
+
resource = wl_resource_create(client, &wl_callback_interface, 1, 0);
assert(resource);
@@ -128,6 +140,8 @@ TEST(client_destroy_listener)
wl_list_remove(&a.resource_listener.link);
wl_list_remove(&a.late_listener.link);
+ assert(!user_data_destroyed);
+
wl_client_destroy(client);
assert(!a.done);
@@ -136,6 +150,7 @@ TEST(client_destroy_listener)
assert(b.done);
assert(b.resource_done);
assert(b.late_done);
+ assert(user_data_destroyed);
close(s[0]);
close(s[1]);