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

2018-04-09 Thread Georg Chini
---
 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 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -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

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2017-10-30 Thread Georg Chini
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

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2017-10-30 Thread Georg Chini
Signals are used to notify clients when a messge handler was added/removed
or when the description changes.
---
 src/pulsecore/message-handler.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/pulsecore/message-handler.c b/src/pulsecore/message-handler.c
index 8f8830d6..b6505dc9 100644
--- a/src/pulsecore/message-handler.c
+++ b/src/pulsecore/message-handler.c
@@ -71,6 +71,9 @@ 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. */
+pa_signal_post(c, "message-api", 1, "handler-added", recipient_name);
 }
 
 /* Unregister a message handler */
@@ -85,6 +88,9 @@ 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. */
+pa_signal_post(c, "message-api", 1, "handler-removed", recipient_name);
 }
 
 /* Send a message to a recipient or recipient group */
@@ -124,6 +130,9 @@ int pa_message_handler_set_description(pa_core *c, const 
char *recipient_name, c
 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", recipient_name);
+
 return PA_OK;
 }
 
-- 
2.14.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss