/***
This file is part of PulseAudio.
-
+
+ Copyright 2004-2006 Lennart Poettering
+ Copyright 2006 Pierre Ossman <ossman@cendio.se> 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,
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
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());
+ 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;
}
-
+
m->userdata = NULL;
m->core = c;
m->n_used = -1;
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;
}
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_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);
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);
-
+
pa_xfree(m->name);
pa_xfree(m->argument);
pa_xfree(m);
}
void pa_module_unload_all(pa_core *c) {
+ pa_module *m;
assert(c);
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;
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;
if (!c->modules)
return;
-
+
time(&now);
pa_idxset_foreach(c->modules, unused_callback, &now);
}
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);