From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 319 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 319 insertions(+) create mode 100644 src/pulsecore/module.c (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c new file mode 100644 index 00000000..e7dca78d --- /dev/null +++ b/src/pulsecore/module.c @@ -0,0 +1,319 @@ +/* $Id$ */ + +/*** + This file is part of PulseAudio. + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "module.h" + +#define PA_SYMBOL_INIT "pa__init" +#define PA_SYMBOL_DONE "pa__done" + +#define UNLOAD_POLL_TIME 2 + +/* lt_dlsym() violates ISO C, so confide the breakage into this function to + * avoid warnings. */ +typedef void (*fnptr)(void); +static inline fnptr lt_dlsym_fn(lt_dlhandle handle, const char *symbol) { + return (fnptr) (long) lt_dlsym(handle, symbol); +} + +static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { + pa_core *c = userdata; + struct timeval ntv; + assert(c && c->mainloop == m && c->module_auto_unload_event == e); + + pa_module_unload_unused(c); + + pa_gettimeofday(&ntv); + ntv.tv_sec += UNLOAD_POLL_TIME; + m->time_restart(e, &ntv); +} + +static inline fnptr load_sym(lt_dlhandle handle, const char *module, const char *symbol) { + char *buffer, *ch; + size_t buflen; + fnptr res; + + res = lt_dlsym_fn(handle, symbol); + if (res) + return res; + + /* As the .la files might have been cleansed from the system, we should + * try with the ltdl prefix as well. */ + + buflen = strlen(symbol) + strlen(module) + strlen("_LTX_") + 1; + buffer = pa_xmalloc(buflen); + assert(buffer); + + strcpy(buffer, module); + + for (ch = buffer;*ch != '\0';ch++) { + if (!isalnum(*ch)) + *ch = '_'; + } + + strcat(buffer, "_LTX_"); + strcat(buffer, symbol); + + res = lt_dlsym_fn(handle, buffer); + + pa_xfree(buffer); + + return res; +} + +pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { + pa_module *m = NULL; + int r; + + assert(c && name); + + if (c->disallow_module_loading) + goto fail; + + m = pa_xmalloc(sizeof(pa_module)); + + m->name = pa_xstrdup(name); + m->argument = pa_xstrdup(argument); + + if (!(m->dl = lt_dlopenext(name))) { + pa_log(__FILE__": Failed to open module \"%s\": %s", name, lt_dlerror()); + goto fail; + } + + if (!(m->init = (int (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_INIT))) { + pa_log(__FILE__": Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name); + goto fail; + } + + if (!(m->done = (void (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_DONE))) { + pa_log(__FILE__": Failed to load module \"%s\": symbol \""PA_SYMBOL_DONE"\" not found.", name); + goto fail; + } + + m->userdata = NULL; + m->core = c; + m->n_used = -1; + m->auto_unload = 0; + m->unload_requested = 0; + + assert(m->init); + if (m->init(c, m) < 0) { + pa_log_error(__FILE__": Failed to load module \"%s\" (argument: \"%s\"): initialization failed.", name, argument ? argument : ""); + goto fail; + } + + if (!c->modules) + c->modules = pa_idxset_new(NULL, NULL); + + if (!c->module_auto_unload_event) { + struct timeval ntv; + pa_gettimeofday(&ntv); + ntv.tv_sec += UNLOAD_POLL_TIME; + c->module_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c); + } + assert(c->module_auto_unload_event); + + assert(c->modules); + r = pa_idxset_put(c->modules, m, &m->index); + assert(r >= 0 && m->index != PA_IDXSET_INVALID); + + pa_log_info(__FILE__": Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); + + pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_NEW, m->index); + + return m; + +fail: + + if (m) { + pa_xfree(m->argument); + pa_xfree(m->name); + + if (m->dl) + lt_dlclose(m->dl); + + pa_xfree(m); + } + + return NULL; +} + +static void pa_module_free(pa_module *m) { + assert(m && m->done && m->core); + + if (m->core->disallow_module_loading) + return; + + pa_log_info(__FILE__": Unloading \"%s\" (index: #%u).", m->name, m->index); + + m->done(m->core, m); + + lt_dlclose(m->dl); + + pa_log_info(__FILE__": Unloaded \"%s\" (index: #%u).", m->name, m->index); + + pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_REMOVE, m->index); + + pa_xfree(m->name); + pa_xfree(m->argument); + pa_xfree(m); +} + +void pa_module_unload(pa_core *c, pa_module *m) { + assert(c && m); + + assert(c->modules); + if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL))) + return; + + pa_module_free(m); +} + +void pa_module_unload_by_index(pa_core *c, uint32_t idx) { + pa_module *m; + assert(c && idx != PA_IDXSET_INVALID); + + assert(c->modules); + if (!(m = pa_idxset_remove_by_index(c->modules, idx))) + return; + + pa_module_free(m); +} + +static void free_callback(void *p, PA_GCC_UNUSED void *userdata) { + pa_module *m = p; + assert(m); + pa_module_free(m); +} + +void pa_module_unload_all(pa_core *c) { + assert(c); + + if (!c->modules) + return; + + pa_idxset_free(c->modules, free_callback, NULL); + c->modules = NULL; + + if (c->module_auto_unload_event) { + c->mainloop->time_free(c->module_auto_unload_event); + c->module_auto_unload_event = NULL; + } + + if (c->module_defer_unload_event) { + c->mainloop->defer_free(c->module_defer_unload_event); + c->module_defer_unload_event = NULL; + } +} + +static int unused_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void *userdata) { + pa_module *m = p; + time_t *now = userdata; + assert(p && del && now); + + if (m->n_used == 0 && m->auto_unload && m->last_used_time+m->core->module_idle_time <= *now) { + pa_module_free(m); + *del = 1; + } + + return 0; +} + +void pa_module_unload_unused(pa_core *c) { + time_t now; + assert(c); + + if (!c->modules) + return; + + time(&now); + pa_idxset_foreach(c->modules, unused_callback, &now); +} + +static int unload_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, PA_GCC_UNUSED void *userdata) { + pa_module *m = p; + assert(m); + + if (m->unload_requested) { + pa_module_free(m); + *del = 1; + } + + return 0; +} + +static void defer_cb(pa_mainloop_api*api, pa_defer_event *e, void *userdata) { + pa_core *core = userdata; + api->defer_enable(e, 0); + + if (!core->modules) + return; + + pa_idxset_foreach(core->modules, unload_callback, NULL); + +} + +void pa_module_unload_request(pa_module *m) { + assert(m); + + m->unload_requested = 1; + + if (!m->core->module_defer_unload_event) + m->core->module_defer_unload_event = m->core->mainloop->defer_new(m->core->mainloop, defer_cb, m->core); + + m->core->mainloop->defer_enable(m->core->module_defer_unload_event, 1); +} + +void pa_module_set_used(pa_module*m, int used) { + assert(m); + + if (m->n_used != used) + pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_CHANGE, m->index); + + if (m->n_used != used && used == 0) + time(&m->last_used_time); + + m->n_used = used; +} + +pa_modinfo *pa_module_get_info(pa_module *m) { + assert(m); + + return pa_modinfo_get_by_handle(m->dl); +} -- cgit From ccf67d2988521a8caf14ef1d650dcab4764462e4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 31 Jul 2006 21:53:48 +0000 Subject: deal properly with recursive module unloading git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1174 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index e7dca78d..3568059e 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -224,10 +224,14 @@ static void free_callback(void *p, PA_GCC_UNUSED void *userdata) { void pa_module_unload_all(pa_core *c) { assert(c); + pa_module *m; if (!c->modules) return; + while ((m = pa_idxset_first(c->modules, NULL))) + pa_module_unload(c, m); + pa_idxset_free(c->modules, free_callback, NULL); c->modules = NULL; -- cgit From f8e5f47e233fc401eec5e2c7fdeab46c7314a6b2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 02:16:47 +0000 Subject: fix a compiler warning git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1210 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index 3568059e..cdf95ada 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -223,8 +223,8 @@ static void free_callback(void *p, PA_GCC_UNUSED void *userdata) { } void pa_module_unload_all(pa_core *c) { - assert(c); pa_module *m; + assert(c); if (!c->modules) return; -- cgit From e385d93e5aad6a6fce754c00c804ff1d6a6746d4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 21:38:40 +0000 Subject: remove all occurences of pa_logXXX(__FILE__": and replace them by pa_logXXX(" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1272 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index cdf95ada..ea3d726e 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -112,17 +112,17 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { m->argument = pa_xstrdup(argument); if (!(m->dl = lt_dlopenext(name))) { - pa_log(__FILE__": Failed to open module \"%s\": %s", name, lt_dlerror()); + pa_log("Failed to open module \"%s\": %s", name, lt_dlerror()); goto fail; } if (!(m->init = (int (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_INIT))) { - pa_log(__FILE__": Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name); + pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name); goto fail; } if (!(m->done = (void (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_DONE))) { - pa_log(__FILE__": Failed to load module \"%s\": symbol \""PA_SYMBOL_DONE"\" not found.", name); + pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_DONE"\" not found.", name); goto fail; } @@ -134,7 +134,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { assert(m->init); if (m->init(c, m) < 0) { - pa_log_error(__FILE__": Failed to load module \"%s\" (argument: \"%s\"): initialization failed.", name, argument ? argument : ""); + pa_log_error("Failed to load module \"%s\" (argument: \"%s\"): initialization failed.", name, argument ? argument : ""); goto fail; } @@ -153,7 +153,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { r = pa_idxset_put(c->modules, m, &m->index); assert(r >= 0 && m->index != PA_IDXSET_INVALID); - pa_log_info(__FILE__": Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); + pa_log_info("Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_NEW, m->index); @@ -180,13 +180,13 @@ static void pa_module_free(pa_module *m) { if (m->core->disallow_module_loading) return; - pa_log_info(__FILE__": Unloading \"%s\" (index: #%u).", m->name, m->index); + pa_log_info("Unloading \"%s\" (index: #%u).", m->name, m->index); m->done(m->core, m); lt_dlclose(m->dl); - pa_log_info(__FILE__": Unloaded \"%s\" (index: #%u).", m->name, m->index); + pa_log_info("Unloaded \"%s\" (index: #%u).", m->name, m->index); pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_REMOVE, m->index); -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index ea3d726e..94410b39 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -2,17 +2,17 @@ /*** This file is part of PulseAudio. - + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -100,17 +100,17 @@ static inline fnptr load_sym(lt_dlhandle handle, const char *module, const char pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { pa_module *m = NULL; int r; - + assert(c && name); if (c->disallow_module_loading) goto fail; - + m = pa_xmalloc(sizeof(pa_module)); m->name = pa_xstrdup(name); m->argument = pa_xstrdup(argument); - + if (!(m->dl = lt_dlopenext(name))) { pa_log("Failed to open module \"%s\": %s", name, lt_dlerror()); goto fail; @@ -125,7 +125,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_DONE"\" not found.", name); goto fail; } - + m->userdata = NULL; m->core = c; m->n_used = -1; @@ -148,23 +148,23 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { c->module_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c); } assert(c->module_auto_unload_event); - + assert(c->modules); r = pa_idxset_put(c->modules, m, &m->index); assert(r >= 0 && m->index != PA_IDXSET_INVALID); - pa_log_info("Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); + pa_log_info("Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_NEW, m->index); - + return m; - + fail: if (m) { pa_xfree(m->argument); pa_xfree(m->name); - + if (m->dl) lt_dlclose(m->dl); @@ -180,16 +180,16 @@ static void pa_module_free(pa_module *m) { if (m->core->disallow_module_loading) return; - pa_log_info("Unloading \"%s\" (index: #%u).", m->name, m->index); + pa_log_info("Unloading \"%s\" (index: #%u).", m->name, m->index); m->done(m->core, m); lt_dlclose(m->dl); - - pa_log_info("Unloaded \"%s\" (index: #%u).", m->name, m->index); + + pa_log_info("Unloaded \"%s\" (index: #%u).", m->name, m->index); pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_REMOVE, m->index); - + pa_xfree(m->name); pa_xfree(m->argument); pa_xfree(m); @@ -250,7 +250,7 @@ static int unused_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void * pa_module *m = p; time_t *now = userdata; assert(p && del && now); - + if (m->n_used == 0 && m->auto_unload && m->last_used_time+m->core->module_idle_time <= *now) { pa_module_free(m); *del = 1; @@ -265,7 +265,7 @@ void pa_module_unload_unused(pa_core *c) { if (!c->modules) return; - + time(&now); pa_idxset_foreach(c->modules, unused_callback, &now); } @@ -309,7 +309,7 @@ void pa_module_set_used(pa_module*m, int used) { if (m->n_used != used) pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_CHANGE, m->index); - + if (m->n_used != used && used == 0) time(&m->last_used_time); -- cgit From 06211b7c8fd329137ae9003818543912a87d9898 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 13 Feb 2007 15:35:19 +0000 Subject: Add copyright notices to all relevant files. (based on svn log) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1426 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index 94410b39..09b15b8b 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -3,6 +3,9 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + Copyright 2006 Pierre Ossman for Cendio AB + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 122 +++++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 79 deletions(-) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index 09b15b8b..dce91a71 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -40,6 +39,8 @@ #include #include #include +#include +#include #include "module.h" @@ -48,69 +49,31 @@ #define UNLOAD_POLL_TIME 2 -/* lt_dlsym() violates ISO C, so confide the breakage into this function to - * avoid warnings. */ -typedef void (*fnptr)(void); -static inline fnptr lt_dlsym_fn(lt_dlhandle handle, const char *symbol) { - return (fnptr) (long) lt_dlsym(handle, symbol); -} - static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { - pa_core *c = userdata; + pa_core *c = PA_CORE(userdata); struct timeval ntv; - assert(c && c->mainloop == m && c->module_auto_unload_event == e); + + pa_core_assert_ref(c); + pa_assert(c->mainloop == m); + pa_assert(c->module_auto_unload_event == e); pa_module_unload_unused(c); pa_gettimeofday(&ntv); - ntv.tv_sec += UNLOAD_POLL_TIME; + pa_timeval_add(&ntv, UNLOAD_POLL_TIME*1000000); m->time_restart(e, &ntv); } -static inline fnptr load_sym(lt_dlhandle handle, const char *module, const char *symbol) { - char *buffer, *ch; - size_t buflen; - fnptr res; - - res = lt_dlsym_fn(handle, symbol); - if (res) - return res; - - /* As the .la files might have been cleansed from the system, we should - * try with the ltdl prefix as well. */ - - buflen = strlen(symbol) + strlen(module) + strlen("_LTX_") + 1; - buffer = pa_xmalloc(buflen); - assert(buffer); - - strcpy(buffer, module); - - for (ch = buffer;*ch != '\0';ch++) { - if (!isalnum(*ch)) - *ch = '_'; - } - - strcat(buffer, "_LTX_"); - strcat(buffer, symbol); - - res = lt_dlsym_fn(handle, buffer); - - pa_xfree(buffer); - - return res; -} - pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { pa_module *m = NULL; - int r; - assert(c && name); + pa_assert(c); + pa_assert(name); if (c->disallow_module_loading) goto fail; - m = pa_xmalloc(sizeof(pa_module)); - + m = pa_xnew(pa_module, 1); m->name = pa_xstrdup(name); m->argument = pa_xstrdup(argument); @@ -119,24 +82,19 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { goto fail; } - if (!(m->init = (int (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_INIT))) { + if (!(m->init = (int (*)(pa_module*_m)) pa_load_sym(m->dl, name, PA_SYMBOL_INIT))) { pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name); goto fail; } - if (!(m->done = (void (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_DONE))) { - pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_DONE"\" not found.", name); - goto fail; - } - + m->done = (void (*)(pa_module*_m)) pa_load_sym(m->dl, name, PA_SYMBOL_DONE); m->userdata = NULL; m->core = c; m->n_used = -1; m->auto_unload = 0; m->unload_requested = 0; - assert(m->init); - if (m->init(c, m) < 0) { + if (m->init(m) < 0) { pa_log_error("Failed to load module \"%s\" (argument: \"%s\"): initialization failed.", name, argument ? argument : ""); goto fail; } @@ -147,14 +105,12 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { if (!c->module_auto_unload_event) { struct timeval ntv; pa_gettimeofday(&ntv); - ntv.tv_sec += UNLOAD_POLL_TIME; + pa_timeval_add(&ntv, UNLOAD_POLL_TIME*1000000); c->module_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c); } - assert(c->module_auto_unload_event); - assert(c->modules); - r = pa_idxset_put(c->modules, m, &m->index); - assert(r >= 0 && m->index != PA_IDXSET_INVALID); + pa_assert_se(pa_idxset_put(c->modules, m, &m->index) >= 0); + pa_assert(m->index != PA_IDXSET_INVALID); pa_log_info("Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); @@ -178,14 +134,16 @@ fail: } static void pa_module_free(pa_module *m) { - assert(m && m->done && m->core); + pa_assert(m); + pa_assert(m->core); if (m->core->disallow_module_loading) return; pa_log_info("Unloading \"%s\" (index: #%u).", m->name, m->index); - m->done(m->core, m); + if (m->done) + m->done(m); lt_dlclose(m->dl); @@ -199,9 +157,10 @@ static void pa_module_free(pa_module *m) { } void pa_module_unload(pa_core *c, pa_module *m) { - assert(c && m); + pa_assert(c); + pa_assert(m); - assert(c->modules); + pa_assert(c->modules); if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL))) return; @@ -210,9 +169,9 @@ void pa_module_unload(pa_core *c, pa_module *m) { void pa_module_unload_by_index(pa_core *c, uint32_t idx) { pa_module *m; - assert(c && idx != PA_IDXSET_INVALID); + pa_assert(c); + pa_assert(idx != PA_IDXSET_INVALID); - assert(c->modules); if (!(m = pa_idxset_remove_by_index(c->modules, idx))) return; @@ -221,13 +180,14 @@ void pa_module_unload_by_index(pa_core *c, uint32_t idx) { static void free_callback(void *p, PA_GCC_UNUSED void *userdata) { pa_module *m = p; - assert(m); + pa_assert(m); pa_module_free(m); } void pa_module_unload_all(pa_core *c) { pa_module *m; - assert(c); + + pa_assert(c); if (!c->modules) return; @@ -252,7 +212,10 @@ void pa_module_unload_all(pa_core *c) { static int unused_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void *userdata) { pa_module *m = p; time_t *now = userdata; - assert(p && del && now); + + pa_assert(m); + pa_assert(del); + pa_assert(now); if (m->n_used == 0 && m->auto_unload && m->last_used_time+m->core->module_idle_time <= *now) { pa_module_free(m); @@ -264,7 +227,7 @@ static int unused_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void * void pa_module_unload_unused(pa_core *c) { time_t now; - assert(c); + pa_assert(c); if (!c->modules) return; @@ -275,7 +238,7 @@ void pa_module_unload_unused(pa_core *c) { static int unload_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, PA_GCC_UNUSED void *userdata) { pa_module *m = p; - assert(m); + pa_assert(m); if (m->unload_requested) { pa_module_free(m); @@ -286,18 +249,19 @@ static int unload_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, PA_GCC } static void defer_cb(pa_mainloop_api*api, pa_defer_event *e, void *userdata) { - pa_core *core = userdata; + pa_core *core = PA_CORE(userdata); + + pa_core_assert_ref(core); api->defer_enable(e, 0); if (!core->modules) return; pa_idxset_foreach(core->modules, unload_callback, NULL); - } void pa_module_unload_request(pa_module *m) { - assert(m); + pa_assert(m); m->unload_requested = 1; @@ -308,19 +272,19 @@ void pa_module_unload_request(pa_module *m) { } void pa_module_set_used(pa_module*m, int used) { - assert(m); + pa_assert(m); if (m->n_used != used) pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_CHANGE, m->index); - if (m->n_used != used && used == 0) + if (used == 0 && m->n_used > 0) time(&m->last_used_time); m->n_used = used; } pa_modinfo *pa_module_get_info(pa_module *m) { - assert(m); + pa_assert(m); - return pa_modinfo_get_by_handle(m->dl); + return pa_modinfo_get_by_handle(m->dl, m->name); } -- cgit From e313fe1b3d0d9f9945c41c151d72edbe9cf1ec54 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 18:25:40 +0000 Subject: tag modules that may only be loaded once at most especially, and enforce that in the module loader git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index dce91a71..e1680de5 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -46,6 +46,7 @@ #define PA_SYMBOL_INIT "pa__init" #define PA_SYMBOL_DONE "pa__done" +#define PA_SYMBOL_LOAD_ONCE "pa__load_once" #define UNLOAD_POLL_TIME 2 @@ -66,6 +67,7 @@ static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED 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_assert(c); pa_assert(name); @@ -82,6 +84,22 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { goto fail; } + if ((load_once = (pa_bool_t (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) { + + if (load_once()) { + pa_module *i; + uint32_t idx; + /* OK, the module only wants to be loaded once, let's make sure it is */ + + for (i = pa_idxset_first(c->modules, &idx); i; i = pa_idxset_next(c->modules, &idx)) { + if (strcmp(name, i->name) == 0) { + pa_log("Module \"%s\" should be loaded once at most. Refusing to load.", name); + goto fail; + } + } + } + } + if (!(m->init = (int (*)(pa_module*_m)) pa_load_sym(m->dl, name, PA_SYMBOL_INIT))) { pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name); goto fail; -- cgit From f7528825257d5d4b056268da3c82181f520a8ff6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 13 Nov 2007 17:35:48 +0000 Subject: fix loading of load-once modules if no other modules was loaded before git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2049 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/module.c') diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index e1680de5..ae140ff4 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -86,7 +86,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) { if ((load_once = (pa_bool_t (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) { - if (load_once()) { + if (load_once() && c->modules) { pa_module *i; uint32_t idx; /* OK, the module only wants to be loaded once, let's make sure it is */ -- cgit