From b43a45d1847f2eff096cc69f70efedd2b94c3aaa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jan 2009 22:02:28 +0100 Subject: [PATCH] allow setting properties for modules, too --- PROTOCOL | 8 ++++++-- src/pulse/introspect.c | 7 ++++++- src/pulse/introspect.h | 1 + src/pulse/proplist.h | 4 ++++ src/pulsecore/cli-command.c | 1 + src/pulsecore/cli-text.c | 6 ++++++ src/pulsecore/module.c | 24 ++++++++++++++++++++++++ src/pulsecore/module.h | 5 ++++- src/pulsecore/protocol-native.c | 14 +++++++++----- 9 files changed, 61 insertions(+), 9 deletions(-) diff --git a/PROTOCOL b/PROTOCOL index 37f289a..8c5937b 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -154,7 +154,6 @@ PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR at the end: early_requests (bool) - ### v15, implemented by >= 0.9.15 PA_COMMAND_CREATE_PLAYBACK_STREAM @@ -163,4 +162,9 @@ PA_COMMAND_CREATE_PLAYBACK_STREAM PA_COMMAND_CREATE_PLAYBACK_STREAM, PA_COMMAND_CREATE_RECORD_STREAM: - bool dont_inhibit_auto_suspend ate the end + bool dont_inhibit_auto_suspend at the end + +PA_COMMAND_GET_MODULE_INFO_LIST + + remove bool auto_unload + add proplist at the end diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c index bdc50e2..e7fa6d7 100644 --- a/src/pulse/introspect.c +++ b/src/pulse/introspect.c @@ -480,13 +480,16 @@ static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, while (!pa_tagstruct_eof(t)) { pa_module_info i; pa_bool_t auto_unload = FALSE; + memset(&i, 0, sizeof(i)); + i.proplist = pa_proplist_new(); if (pa_tagstruct_getu32(t, &i.index) < 0 || pa_tagstruct_gets(t, &i.name) < 0 || pa_tagstruct_gets(t, &i.argument) < 0 || pa_tagstruct_getu32(t, &i.n_used) < 0 || - pa_tagstruct_get_boolean(t, &auto_unload) < 0) { + (o->context->version < 15 && pa_tagstruct_get_boolean(t, &auto_unload) < 0) || + (o->context->version >= 15 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) { pa_context_fail(o->context, PA_ERR_PROTOCOL); goto finish; } @@ -497,6 +500,8 @@ static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, pa_module_info_cb_t cb = (pa_module_info_cb_t) o->callback; cb(o->context, &i, 0, o->userdata); } + + pa_proplist_free(i.proplist); } } diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index ae9bd5b..428826e 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -333,6 +333,7 @@ typedef struct pa_module_info { /** \cond fulldocs */ int auto_unload; /**< \deprecated Non-zero if this is an autoloaded module */ /** \endcond */ + pa_proplist *proplist; /**< Property list \since 0.9.15 */ } pa_module_info; /** Callback prototype for pa_context_get_module_info() and firends*/ diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h index 8f44df2..529871f 100644 --- a/src/pulse/proplist.h +++ b/src/pulse/proplist.h @@ -128,6 +128,10 @@ PA_C_DECL_BEGIN #define PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE "device.buffering.fragment_size" #define PA_PROP_DEVICE_PROFILE_NAME "device.profile.name" #define PA_PROP_DEVICE_PROFILE_DESCRIPTION "device.profile.description" +#define PA_PROP_MODULE_AUTHOR "module.author" +#define PA_PROP_MODULE_DESCRIPTION "module.description" +#define PA_PROP_MODULE_USAGE "module.usage" +#define PA_PROP_MODULE_VERSION "module.version" /** A property list object. Basically a dictionary with UTF-8 strings * as keys and arbitrary data as values. \since 0.9.11 */ diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 8f5d9bd..f810579 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -51,6 +51,7 @@ #include #include #include +#include #include "cli-command.h" diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c index 5c3d3af..cbd36e2 100644 --- a/src/pulsecore/cli-text.c +++ b/src/pulsecore/cli-text.c @@ -54,6 +54,8 @@ char *pa_module_list_to_string(pa_core *c) { pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules)); for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) { + char *t; + pa_strbuf_printf(s, " index: %u\n" "\tname: <%s>\n" "\targument: <%s>\n" @@ -64,6 +66,10 @@ char *pa_module_list_to_string(pa_core *c) { pa_strempty(m->argument), pa_module_get_n_used(m), pa_yes_no(m->load_once)); + + t = pa_proplist_to_string_sep(m->proplist, "\n\t\t"); + pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t); + pa_xfree(t); } return pa_strbuf_tostring_free(s); diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index 0a8c8f5..d470bb0 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -33,12 +33,14 @@ #include #include +#include #include #include #include #include #include +#include #include "module.h" @@ -50,6 +52,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { pa_module *m = NULL; pa_bool_t (*load_once)(void); + pa_modinfo *mi; pa_assert(c); pa_assert(name); @@ -61,6 +64,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { m->name = pa_xstrdup(name); m->argument = pa_xstrdup(argument); m->load_once = FALSE; + m->proplist = pa_proplist_new(); if (!(m->dl = lt_dlopenext(name))) { pa_log("Failed to open module \"%s\": %s", name, lt_dlerror()); @@ -111,11 +115,28 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_NEW, m->index); + if ((mi = pa_modinfo_get_by_handle(m->dl, name))) { + + if (mi->author && !pa_proplist_contains(m->proplist, PA_PROP_MODULE_AUTHOR)) + pa_proplist_sets(m->proplist, PA_PROP_MODULE_AUTHOR, mi->author); + + if (mi->description && !pa_proplist_contains(m->proplist, PA_PROP_MODULE_DESCRIPTION)) + pa_proplist_sets(m->proplist, PA_PROP_MODULE_DESCRIPTION, mi->description); + + if (mi->version && !pa_proplist_contains(m->proplist, PA_PROP_MODULE_VERSION)) + pa_proplist_sets(m->proplist, PA_PROP_MODULE_VERSION, mi->version); + + pa_modinfo_free(mi); + } + return m; fail: if (m) { + if (m->proplist) + pa_proplist_free(m->proplist); + pa_xfree(m->argument); pa_xfree(m->name); @@ -137,6 +158,9 @@ static void pa_module_free(pa_module *m) { if (m->done) m->done(m); + if (m->proplist) + pa_proplist_free(m->proplist); + lt_dlclose(m->dl); pa_log_info("Unloaded \"%s\" (index: #%u).", m->name, m->index); diff --git a/src/pulsecore/module.h b/src/pulsecore/module.h index 5c49bd2..6ab43dc 100644 --- a/src/pulsecore/module.h +++ b/src/pulsecore/module.h @@ -27,8 +27,9 @@ typedef struct pa_module pa_module; +#include + #include -#include struct pa_module { pa_core *core; @@ -45,6 +46,8 @@ struct pa_module { pa_bool_t load_once:1; pa_bool_t unload_requested:1; + + pa_proplist *proplist; }; pa_module* pa_module_load(pa_core *c, const char *name, const char*argument); diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 5412267..eb55505 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -2728,10 +2728,9 @@ static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_c if (c->version >= 13) pa_tagstruct_put_proplist(t, client->proplist); - } -static void module_fill_tagstruct(pa_tagstruct *t, pa_module *module) { +static void module_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_module *module) { pa_assert(t); pa_assert(module); @@ -2739,7 +2738,12 @@ static void module_fill_tagstruct(pa_tagstruct *t, pa_module *module) { pa_tagstruct_puts(t, module->name); pa_tagstruct_puts(t, module->argument); pa_tagstruct_putu32(t, (uint32_t) pa_module_get_n_used(module)); - pa_tagstruct_put_boolean(t, FALSE); /* autoload is obsolete */ + + if (c->version < 15) + pa_tagstruct_put_boolean(t, FALSE); /* autoload is obsolete */ + + if (c->version >= 15) + pa_tagstruct_put_proplist(t, module->proplist); } static void sink_input_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sink_input *s) { @@ -2891,7 +2895,7 @@ static void command_get_info(pa_pdispatch *pd, uint32_t command, uint32_t tag, p else if (client) client_fill_tagstruct(c, reply, client); else if (module) - module_fill_tagstruct(reply, module); + module_fill_tagstruct(c, reply, module); else if (si) sink_input_fill_tagstruct(c, reply, si); else if (so) @@ -2946,7 +2950,7 @@ static void command_get_info_list(pa_pdispatch *pd, uint32_t command, uint32_t t else if (command == PA_COMMAND_GET_CLIENT_INFO_LIST) client_fill_tagstruct(c, reply, p); else if (command == PA_COMMAND_GET_MODULE_INFO_LIST) - module_fill_tagstruct(reply, p); + module_fill_tagstruct(c, reply, p); else if (command == PA_COMMAND_GET_SINK_INPUT_INFO_LIST) sink_input_fill_tagstruct(c, reply, p); else if (command == PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST) -- 2.7.4