[pulseaudio-discuss] [PATCH 3/3] message-handler: Send signal on handler events

Georg Chini georg at chini.tk
Mon Apr 9 18:27:47 UTC 2018


---
 src/pulsecore/message-handler.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/pulsecore/message-handler.c b/src/pulsecore/message-handler.c
index 75310667..a983e136 100644
--- a/src/pulsecore/message-handler.c
+++ b/src/pulsecore/message-handler.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 
 #include <pulse/xmalloc.h>
+#include <pulse/message-params.h>
 
 #include <pulsecore/core.h>
 #include <pulsecore/core-util.h>
@@ -64,6 +65,7 @@ static bool object_path_is_valid(const char *test_string) {
 /* Register message handler for the specified object. object_path must be a unique name starting with "/". */
 void pa_message_handler_register(pa_core *c, const char *object_path, const char *description, pa_message_handler_cb_t cb, void *userdata) {
     struct pa_message_handler *handler;
+    char *sig_param;
 
     pa_assert(c);
     pa_assert(object_path);
@@ -80,11 +82,17 @@ void pa_message_handler_register(pa_core *c, const char *object_path, const char
     handler->description = pa_xstrdup(description);
 
     pa_assert_se(pa_hashmap_put(c->message_handlers, handler->object_path, handler) == 0);
+
+    /* Notify clients that a handler was added. */
+    sig_param = pa_sprintf_malloc("{%s}", object_path);
+    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 *object_path) {
     struct pa_message_handler *handler;
+    char *sig_param;
 
     pa_assert(c);
     pa_assert(object_path);
@@ -94,6 +102,11 @@ void pa_message_handler_unregister(pa_core *c, const char *object_path) {
     pa_xfree(handler->object_path);
     pa_xfree(handler->description);
     pa_xfree(handler);
+
+    /* Notify clients that a handler was removed. */
+    sig_param = pa_sprintf_malloc("{%s}", object_path);
+    pa_signal_post(c, "message-api", 1, "handler-removed", sig_param);
+    pa_xfree(sig_param);
 }
 
 /* Send a message to an object identified by object_path */
@@ -134,6 +147,8 @@ int pa_message_handler_send_message(pa_core *c, const char *object_path, const c
 /* Set handler description */
 int pa_message_handler_set_description(pa_core *c, const char *object_path, const char *description) {
     struct pa_message_handler *handler;
+    char *sig_param;
+    pa_message_param *param;
 
     pa_assert(c);
     pa_assert(object_path);
@@ -141,9 +156,19 @@ int pa_message_handler_set_description(pa_core *c, const char *object_path, cons
     if (!(handler = pa_hashmap_get(c->message_handlers, object_path)))
         return -PA_ERR_NOENTITY;
 
+    param = pa_message_param_new();
+    pa_message_param_write_string(param, object_path, false);
+    pa_message_param_write_string(param, handler->description, true);
+    pa_message_param_write_string(param, description, true);
+    sig_param = pa_message_param_to_string(param);
+
     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



More information about the pulseaudio-discuss mailing list