]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/module.c
Remove unnecessary #includes
[pulseaudio] / src / pulsecore / module.c
index c4dcb4789617d5ab85f575f829e6cf246eb5b32f..8b3ff8f54a021ed59b8a05410c91e4959533cf77 100644 (file)
@@ -6,7 +6,7 @@
 
   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,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #include <config.h>
 #endif
 
-#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <ctype.h>
 
-#include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
+#include <pulse/proplist.h>
 
 #include <pulsecore/core-subscribe.h>
 #include <pulsecore/log.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/ltdl-helper.h>
+#include <pulsecore/modinfo.h>
 
 #include "module.h"
 
 #define PA_SYMBOL_DONE "pa__done"
 #define PA_SYMBOL_LOAD_ONCE "pa__load_once"
 #define PA_SYMBOL_GET_N_USED "pa__get_n_used"
+#define PA_SYMBOL_GET_DEPRECATE "pa__get_deprecated"
 
 pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
     pa_module *m = NULL;
     pa_bool_t (*load_once)(void);
+    const char* (*get_deprecated)(void);
+    pa_modinfo *mi;
 
     pa_assert(c);
     pa_assert(name);
@@ -61,6 +63,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());
@@ -71,7 +74,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
 
         m->load_once = load_once();
 
-        if (m->load_once && c->modules) {
+        if (m->load_once) {
             pa_module *i;
             uint32_t idx;
             /* OK, the module only wants to be loaded once, let's make sure it is */
@@ -85,6 +88,13 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
         }
     }
 
+    if ((get_deprecated = (const char* (*) (void)) pa_load_sym(m->dl, name, PA_SYMBOL_GET_DEPRECATE))) {
+        const char *t;
+
+        if ((t = get_deprecated()))
+            pa_log_warn("%s is deprecated: %s", name, t);
+    }
+
     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;
@@ -97,13 +107,10 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
     m->unload_requested = FALSE;
 
     if (m->init(m) < 0) {
-        pa_log_error("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;
     }
 
-    if (!c->modules)
-        c->modules = pa_idxset_new(NULL, NULL);
-
     pa_assert_se(pa_idxset_put(c->modules, m, &m->index) >= 0);
     pa_assert(m->index != PA_IDXSET_INVALID);
 
@@ -111,11 +118,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 +161,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);
@@ -176,17 +203,11 @@ void pa_module_unload_by_index(pa_core *c, uint32_t idx, pa_bool_t force) {
 }
 
 void pa_module_unload_all(pa_core *c) {
+    pa_module *m;
     pa_assert(c);
 
-    if (c->modules) {
-        pa_module *m;
-
-        while ((m = pa_idxset_steal_first(c->modules, NULL)))
-            pa_module_free(m);
-
-        pa_idxset_free(c->modules, NULL, NULL);
-        c->modules = NULL;
-    }
+    while ((m = pa_idxset_steal_first(c->modules, NULL)))
+        pa_module_free(m);
 
     if (c->module_defer_unload_event) {
         c->mainloop->defer_free(c->module_defer_unload_event);
@@ -202,9 +223,6 @@ static void defer_cb(pa_mainloop_api*api, pa_defer_event *e, void *userdata) {
     pa_core_assert_ref(c);
     api->defer_enable(e, 0);
 
-    if (!c->modules)
-        return;
-
     while ((m = pa_idxset_iterate(c->modules, &state, NULL)))
         if (m->unload_requested)
             pa_module_unload(c, m, TRUE);
@@ -234,12 +252,6 @@ void pa_module_unload_request_by_index(pa_core *c, uint32_t idx, pa_bool_t force
     pa_module_unload_request(m, force);
 }
 
-pa_modinfo *pa_module_get_info(pa_module *m) {
-    pa_assert(m);
-
-    return pa_modinfo_get_by_handle(m->dl, m->name);
-}
-
 int pa_module_get_n_used(pa_module*m) {
     pa_assert(m);
 
@@ -248,3 +260,12 @@ int pa_module_get_n_used(pa_module*m) {
 
     return m->get_n_used(m);
 }
+
+void pa_module_update_proplist(pa_module *m, pa_update_mode_t mode, pa_proplist *p) {
+    pa_assert(m);
+
+    if (p)
+        pa_proplist_update(m->proplist, mode, p);
+
+    pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_CHANGE, m->index);
+}