[pulseaudio-discuss] [PATCH 4/4] core: add message handler
Georg Chini
georg at chini.tk
Fri Jul 21 19:25:51 UTC 2017
This patch adds a small message handler to the core which enables
clients to list available handlers via the list-handlers message.
Command: pacmd send-message /core list-handlers
pactl can be used with the same parameters.
---
src/pulsecore/core.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 3145caaf..0e3a078c 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -38,6 +38,7 @@
#include <pulsecore/random.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
+#include <pulsecore/strbuf.h>
#include "core.h"
@@ -61,6 +62,38 @@ static int core_process_msg(pa_msgobject *o, int code, void *userdata, int64_t o
static void core_free(pa_object *o);
+static int core_message_handler(const char *recipient, const char *message, const char *message_parameters, char **response, void *userdata) {
+ pa_core *c;
+ pa_strbuf *buf;
+ void *state = NULL;
+ pa_core_message_handler *handler;
+
+ pa_assert(c = (pa_core *) userdata);
+ pa_assert(message);
+ pa_assert(response);
+ pa_assert(pa_safe_streq(recipient, "/core"));
+
+ buf = pa_strbuf_new();
+
+ if (pa_streq(message, "list-handlers")) {
+ pa_strbuf_puts(buf, "Name\tShort_Name\tDescription");
+
+ while ((handler = pa_hashmap_iterate(c->message_handlers, &state, NULL))) {
+ pa_strbuf_puts(buf, "\n");
+ pa_strbuf_printf(buf, "\"%s\"", handler->recipient);
+ if (handler->short_name)
+ pa_strbuf_printf(buf, "\t\"%s\"", handler->short_name);
+ if (handler->description)
+ pa_strbuf_printf(buf, "\t\"%s\"", handler->description);
+ }
+
+ } else
+ pa_strbuf_puts(buf, "Message not implemented");
+
+ *response = pa_strbuf_to_string_free(buf);
+ return 0;
+}
+
pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t shm_size) {
pa_core* c;
pa_mempool *pool;
@@ -105,6 +138,8 @@ pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t
c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
c->message_handlers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+ pa_core_register_message_handler(c, "/core", "core", "Core message handler", core_message_handler, (void *) c);
+
c->default_source = NULL;
c->default_sink = NULL;
@@ -205,6 +240,8 @@ static void core_free(pa_object *o) {
pa_assert(pa_hashmap_isempty(c->shared));
pa_hashmap_free(c->shared);
+ pa_core_unregister_message_handler(c, "/core");
+
pa_assert(pa_hashmap_isempty(c->message_handlers));
pa_hashmap_free(c->message_handlers);
--
2.11.0
More information about the pulseaudio-discuss
mailing list