diff --git a/src/modules/module-protocol-pulse/internal.h b/src/modules/module-protocol-pulse/internal.h index ca6b74926..fe8070f7c 100644 --- a/src/modules/module-protocol-pulse/internal.h +++ b/src/modules/module-protocol-pulse/internal.h @@ -36,6 +36,7 @@ #include #include "format.h" +#include "server.h" struct pw_loop; struct pw_context; @@ -72,6 +73,7 @@ struct impl { struct ratelimit rate_limit; + struct spa_hook_list hooks; struct spa_list servers; struct pw_work_queue *work_queue; @@ -85,6 +87,19 @@ struct impl { struct stats stat; }; +struct impl_events { +#define VERSION_IMPL_EVENTS 0 + uint32_t version; + + void (*server_started) (void *data, struct server *server); + + void (*server_stopped) (void *data, struct server *server); +}; + +void impl_add_listener(struct impl *impl, + struct spa_hook *listener, + const struct impl_events *events, void *data); + extern bool debug_messages; void broadcast_subscribe_event(struct impl *impl, uint32_t mask, uint32_t event, uint32_t id); diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 07f664ba1..cb89c7419 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -5461,6 +5461,8 @@ static void impl_clear(struct impl *impl) pw_map_for_each(&impl->samples, impl_free_sample, impl); pw_map_clear(&impl->samples); + spa_hook_list_clean(&impl->hooks); + #ifdef HAVE_DBUS if (impl->dbus_name) { dbus_release_name(impl->dbus_name); @@ -5599,6 +5601,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, impl->work_queue = pw_context_get_work_queue(context); + spa_hook_list_init(&impl->hooks); spa_list_init(&impl->servers); impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC; impl->rate_limit.burst = 1; @@ -5650,6 +5653,13 @@ error_exit: return NULL; } +void impl_add_listener(struct impl *impl, + struct spa_hook *listener, + const struct impl_events *events, void *data) +{ + spa_hook_list_append(&impl->hooks, listener, events, data); +} + void *pw_protocol_pulse_get_user_data(struct pw_protocol_pulse *pulse) { return SPA_PTROFF(pulse, sizeof(struct impl), void); diff --git a/src/modules/module-protocol-pulse/server.c b/src/modules/module-protocol-pulse/server.c index 89f343a12..5f2fdaba3 100644 --- a/src/modules/module-protocol-pulse/server.c +++ b/src/modules/module-protocol-pulse/server.c @@ -899,7 +899,7 @@ static struct server *server_new(struct impl *impl) static int server_start(struct server *server, const struct sockaddr_storage *addr) { - const struct impl * const impl = server->impl; + struct impl * const impl = server->impl; int res = 0, fd; switch (addr->ss_family) { @@ -924,6 +924,8 @@ static int server_start(struct server *server, const struct sockaddr_storage *ad res = -errno; pw_log_error("server %p: can't create server source: %m", impl); } + if (res >= 0) + spa_hook_list_call(&impl->hooks, struct impl_events, server_started, 0, server); return res; } @@ -1069,6 +1071,8 @@ void server_free(struct server *server) client_unref(c); } + spa_hook_list_call(&impl->hooks, struct impl_events, server_stopped, 0, server); + if (server->source) pw_loop_destroy_source(impl->loop, server->source);