diff --git a/src/modules/module-protocol-pulse/client.c b/src/modules/module-protocol-pulse/client.c index d64803d67..62e1717ea 100644 --- a/src/modules/module-protocol-pulse/client.c +++ b/src/modules/module-protocol-pulse/client.c @@ -49,6 +49,8 @@ #include "server.h" #include "stream.h" +#define client_emit_disconnect(c) spa_hook_list_call(&(c)->listener_list, struct client_events, disconnect, 0) + struct client *client_new(struct server *server) { struct client *client = calloc(1, sizeof(*client)); @@ -65,6 +67,7 @@ struct client *client_new(struct server *server) spa_list_init(&client->operations); spa_list_init(&client->pending_samples); spa_list_init(&client->pending_streams); + spa_hook_list_init(&client->listener_list); spa_list_append(&server->clients, &client->link); server->n_clients++; @@ -116,6 +119,8 @@ void client_disconnect(struct client *client) if (client->disconnect) return; + client_emit_disconnect(client); + /* the client must be detached from the server to disconnect */ spa_assert(client->server == NULL); @@ -171,6 +176,8 @@ void client_free(struct client *client) pw_properties_free(client->props); pw_properties_free(client->routes); + spa_hook_list_clean(&client->listener_list); + free(client); } diff --git a/src/modules/module-protocol-pulse/client.h b/src/modules/module-protocol-pulse/client.h index 1dbf1fa97..616980950 100644 --- a/src/modules/module-protocol-pulse/client.h +++ b/src/modules/module-protocol-pulse/client.h @@ -100,6 +100,15 @@ struct client { struct pw_manager_object *prev_default_sink; struct pw_manager_object *prev_default_source; + + struct spa_hook_list listener_list; +}; + +struct client_events { +#define VERSION_CLIENT_EVENTS 0 + uint32_t version; + + void (*disconnect) (void *data); }; struct client *client_new(struct server *server); @@ -116,4 +125,10 @@ static inline void client_unref(struct client *client) client_free(client); } +static inline void client_add_listener(struct client *client, struct spa_hook *listener, + const struct client_events *events, void *data) +{ + spa_hook_list_append(&client->listener_list, listener, events, data); +} + #endif /* PULSER_SERVER_CLIENT_H */