From b43a45d1847f2eff096cc69f70efedd2b94c3aaa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jan 2009 22:02:28 +0100 Subject: allow setting properties for modules, too --- 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 +++++++++----- 5 files changed, 44 insertions(+), 6 deletions(-) (limited to 'src/pulsecore') diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 8f5d9bdd..f810579e 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 5c3d3af6..cbd36e2a 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 0a8c8f57..d470bb0b 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 5c49bd2d..6ab43dcf 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 54122679..eb555050 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) -- cgit