Signals are used to notify clients when a messge handler was added/removed or when the description changed. --- src/pulsecore/message-handler.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pulsecore/message-handler.c b/src/pulsecore/message-handler.c index 8f8830d6..f0083adc 100644 --- a/src/pulsecore/message-handler.c +++ b/src/pulsecore/message-handler.c @@ -50,6 +50,7 @@ static bool string_is_valid(const char *test_string) { /* Register message handler. recipient_name must be a unique name starting with "/". */ void pa_message_handler_register(pa_core *c, const char *recipient_name, const char *description, pa_message_handler_cb_t cb, void *userdata) { struct pa_message_handler *handler; + char *sig_param; pa_assert(c); pa_assert(recipient_name); @@ -71,11 +72,17 @@ void pa_message_handler_register(pa_core *c, const char *recipient_name, const c handler->description = pa_xstrdup(description); pa_assert_se(pa_hashmap_put(c->message_handlers, handler->recipient, (void *) handler) == 0); + + /* Notify clients that a new handler was added. */ + sig_param = pa_sprintf_malloc("{%s}", recipient_name); + pa_signal_post(c, "message-api", 1, "handler-added", sig_param); + pa_xfree(sig_param); } /* Unregister a message handler */ void pa_message_handler_unregister(pa_core *c, const char *recipient_name) { struct pa_message_handler *handler; + char *sig_param; pa_assert(c); pa_assert(recipient_name); @@ -85,6 +92,11 @@ void pa_message_handler_unregister(pa_core *c, const char *recipient_name) { pa_xfree(handler->recipient); pa_xfree(handler->description); pa_xfree(handler); + + /* Notify clients that a handler was removed. */ + sig_param = pa_sprintf_malloc("{%s}", recipient_name); + pa_signal_post(c, "message-api", 1, "handler-removed", sig_param); + pa_xfree(sig_param); } /* Send a message to a recipient or recipient group */ @@ -109,6 +121,7 @@ int pa_message_handler_send_message(pa_core *c, const char *recipient_name, cons /* Set handler description */ int pa_message_handler_set_description(pa_core *c, const char *recipient_name, const char *description) { struct pa_message_handler *handler; + char *sig_param; pa_assert(c); pa_assert(recipient_name); @@ -121,9 +134,15 @@ int pa_message_handler_set_description(pa_core *c, const char *recipient_name, c return -PA_ERR_INVALID; } + sig_param = pa_sprintf_malloc("{%s} {%s} {%s}", recipient_name, (handler->description ? handler->description : ""), (description ? description : "") ); + pa_xfree(handler->description); handler->description = pa_xstrdup(description); + /* Notify clients that a handler description changed. */ + pa_signal_post(c, "message-api", 1, "handler-changed", sig_param); + pa_xfree(sig_param); + return PA_OK; } -- 2.14.1