]> code.delx.au - pulseaudio/commitdiff
* drop redundant pa_core argument from module initialization functions
authorLennart Poettering <lennart@poettering.net>
Fri, 10 Aug 2007 14:28:39 +0000 (14:28 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Aug 2007 14:28:39 +0000 (14:28 +0000)
* make pa__done() implementations optional
* a couple of modernizations
* wrap lt_dlsym() at a single place
* allow passing of an "api" argument to the HAL module, to choose whether OSS devices or ALSA devices should be picked up
* optimize fd closing a little on linux in the forked gconf helper
* save a little memory in the xsmp module

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1615 fefdeb5f-60dc-0310-8127-8f9354f1896f

33 files changed:
src/Makefile.am
src/modules/gconf/module-gconf.c
src/modules/module-alsa-sink.c
src/modules/module-alsa-source.c
src/modules/module-cli.c
src/modules/module-defs.h.m4
src/modules/module-detect.c
src/modules/module-esound-compat-spawnfd.c
src/modules/module-esound-compat-spawnpid.c
src/modules/module-hal-detect.c
src/modules/module-lirc.c
src/modules/module-match.c
src/modules/module-mmkbd-evdev.c
src/modules/module-native-protocol-fd.c
src/modules/module-null-sink.c
src/modules/module-oss.c
src/modules/module-pipe-sink.c
src/modules/module-pipe-source.c
src/modules/module-protocol-stub.c
src/modules/module-rescue-streams.c
src/modules/module-sine.c
src/modules/module-suspend-on-idle.c
src/modules/module-volume-restore.c
src/modules/module-x11-bell.c
src/modules/module-x11-publish.c
src/modules/module-x11-xsmp.c
src/modules/module-zeroconf-publish.c
src/pulsecore/ltdl-helper.c [new file with mode: 0644]
src/pulsecore/ltdl-helper.h [new file with mode: 0644]
src/pulsecore/modinfo.c
src/pulsecore/modinfo.h
src/pulsecore/module.c
src/pulsecore/module.h

index 5edd200fd16e53bb006f714754542ddaec01e64b..8273d336babb4ecaf4ff54c456d75a83f1d32c03 100644 (file)
@@ -624,6 +624,7 @@ libpulsecore_la_SOURCES += \
                pulsecore/memchunk.c pulsecore/memchunk.h \
                pulsecore/modargs.c pulsecore/modargs.h \
                pulsecore/modinfo.c pulsecore/modinfo.h \
+               pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \
                pulsecore/module.c pulsecore/module.h \
                pulsecore/namereg.c pulsecore/namereg.h \
                pulsecore/pid.c pulsecore/pid.h \
@@ -1038,9 +1039,7 @@ EXTRA_DIST += $(SYMDEF_FILES)
 BUILT_SOURCES += $(SYMDEF_FILES)
 
 $(SYMDEF_FILES): modules/module-defs.h.m4
-       -mkdir modules
-       -mkdir modules/gconf
-       -mkdir modules/rtp
+       $(mkdir_p) modules modules/gconf modules/rtp
        $(M4) -Dfname="$@" $< > $@
 
 # Simple protocol
index cbe17d200d58d815dc785231a2378d9a6d38717d..7e932c11494d2c826fae0e5fbe632c7e04a8062a 100644 (file)
@@ -25,7 +25,6 @@
 #include <config.h>
 #endif
 
-#include <assert.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -34,6 +33,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <fcntl.h>
+#include <dirent.h>
 
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
@@ -95,7 +95,7 @@ struct userdata {
 
 static int fill_buf(struct userdata *u) {
     ssize_t r;
-    assert(u);
+    pa_assert(u);
 
     if (u->buf_fill >= BUF_MAX) {
         pa_log("read buffer overflow");
@@ -111,21 +111,21 @@ static int fill_buf(struct userdata *u) {
 
 static int read_byte(struct userdata *u) {
     int ret;
-    assert(u);
+    pa_assert(u);
 
     if (u->buf_fill < 1)
         if (fill_buf(u) < 0)
             return -1;
 
     ret = u->buf[0];
-    assert(u->buf_fill > 0);
+    pa_assert(u->buf_fill > 0);
     u->buf_fill--;
     memmove(u->buf, u->buf+1, u->buf_fill);
     return ret;
 }
 
 static char *read_string(struct userdata *u) {
-    assert(u);
+    pa_assert(u);
 
     for (;;) {
         char *e;
@@ -143,9 +143,9 @@ static char *read_string(struct userdata *u) {
 }
 
 static void unload_one_module(struct userdata *u, struct module_info*m, unsigned i) {
-    assert(u);
-    assert(m);
-    assert(i < m->n_items);
+    pa_assert(u);
+    pa_assert(m);
+    pa_assert(i < m->n_items);
 
     if (m->items[i].index == PA_INVALID_INDEX)
         return;
@@ -161,8 +161,8 @@ static void unload_one_module(struct userdata *u, struct module_info*m, unsigned
 static void unload_all_modules(struct userdata *u, struct module_info*m) {
     unsigned i;
 
-    assert(u);
-    assert(m);
+    pa_assert(u);
+    pa_assert(m);
 
     for (i = 0; i < m->n_items; i++)
         unload_one_module(u, m, i);
@@ -180,10 +180,10 @@ static void load_module(
 
     pa_module *mod;
 
-    assert(u);
-    assert(m);
-    assert(name);
-    assert(args);
+    pa_assert(u);
+    pa_assert(m);
+    pa_assert(name);
+    pa_assert(args);
 
     if (!is_new) {
         if (m->items[i].index != PA_INVALID_INDEX &&
@@ -212,8 +212,8 @@ static void module_info_free(void *p, void *userdata) {
     struct module_info *m = p;
     struct userdata *u = userdata;
 
-    assert(m);
-    assert(u);
+    pa_assert(m);
+    pa_assert(u);
 
     unload_all_modules(u, m);
     pa_xfree(m->name);
@@ -356,8 +356,10 @@ static int start_client(const char *n, pid_t *pid) {
 
         return pipe_fds[0];
     } else {
+#ifdef __linux__
+        DIR* d;
+#endif
         int max_fd, i;
-
         /* child */
 
         close(pipe_fds[0]);
@@ -372,19 +374,46 @@ static int start_client(const char *n, pid_t *pid) {
         close(2);
         open("/dev/null", O_WRONLY);
 
-        max_fd = 1024;
+#ifdef __linux__
+
+        if ((d = opendir("/proc/self/fd/"))) {
+
+            struct dirent *de;
+
+            while ((de = readdir(d))) {
+                char *e;
+                int fd;
+                
+                errno = 0;
+                fd = strtol(de->d_name, &e, 10);
+                pa_assert(errno == 0 && *e == 0);
 
+                if (fd >= 3)
+                    close(fd);
+            }
+            
+            closedir(d);
+        } else {
+            
+#endif
+        
+            max_fd = 1024;
+            
 #ifdef HAVE_SYS_RESOURCE_H
-        {
-            struct rlimit r;
-            if (getrlimit(RLIMIT_NOFILE, &r) == 0)
-                max_fd = r.rlim_max;
+            {
+                struct rlimit r;
+                if (getrlimit(RLIMIT_NOFILE, &r) == 0)
+                    max_fd = r.rlim_max;
+            }
+#endif
+            
+            for (i = 3; i < max_fd; i++)
+                close(i);
+#
+#ifdef __linux__
         }
 #endif
 
-        for (i = 3; i < max_fd; i++)
-            close(i);
-
 #ifdef PR_SET_PDEATHSIG
         /* On Linux we can use PR_SET_PDEATHSIG to have the helper
         process killed when the daemon dies abnormally. On non-Linux
@@ -413,12 +442,12 @@ fail:
     return -1;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     struct userdata *u;
     int r;
 
     u = pa_xnew(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
     u->module_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
@@ -431,8 +460,8 @@ int pa__init(pa_core *c, pa_module*m) {
     if ((u->fd = start_client(PA_GCONF_HELPER, &u->pid)) < 0)
         goto fail;
 
-    u->io_event = c->mainloop->io_new(
-            c->mainloop,
+    u->io_event = m->core->mainloop->io_new(
+            m->core->mainloop,
             u->fd,
             PA_IO_EVENT_INPUT,
             io_event_cb,
@@ -449,21 +478,20 @@ int pa__init(pa_core *c, pa_module*m) {
     return 0;
 
 fail:
-    pa__done(c, m);
+    pa__done(m);
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
 
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     if (!(u = m->userdata))
         return;
 
     if (u->io_event)
-        c->mainloop->io_free(u->io_event);
+        m->core->mainloop->io_free(u->io_event);
 
     if (u->fd >= 0)
         close(u->fd);
index 1a69954cf956ad954b94b269eb1ac0a358fa95cd..387e70c42474b5aa27936767352a3395cff05ed0 100644 (file)
@@ -704,7 +704,7 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     
     pa_modargs *ma = NULL;
     int ret = -1;
@@ -723,7 +723,6 @@ int pa__init(pa_core *c, pa_module*m) {
     int namereg_fail;
     int use_mmap = 1, b;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -731,7 +730,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    ss = c->default_sample_spec;
+    ss = m->core->default_sample_spec;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log("Failed to parse sample specification and channel map");
         goto fail;
@@ -756,7 +755,7 @@ int pa__init(pa_core *c, pa_module*m) {
     }
         
     u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
     u->use_mmap = use_mmap;
@@ -824,7 +823,7 @@ int pa__init(pa_core *c, pa_module*m) {
         namereg_fail = 0;
     }
 
-    u->sink = pa_sink_new(c, __FILE__, name, namereg_fail, &ss, &map);
+    u->sink = pa_sink_new(m->core, __FILE__, name, namereg_fail, &ss, &map);
     pa_xfree(name_buf);
     
     if (!u->sink) {
@@ -881,7 +880,7 @@ int pa__init(pa_core *c, pa_module*m) {
 
         u->mixer_fdl = pa_alsa_fdlist_new();
 
-        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, c->mainloop) < 0) {
+        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, m->core->mainloop) < 0) {
             pa_log("failed to initialise file descriptor monitoring");
             goto fail;
         }
@@ -917,15 +916,14 @@ finish:
 fail:
 
     if (u)
-        pa__done(c, m);
+        pa__done(m);
 
     goto finish;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index 553d028395e3912d98b29c0ab69e7f17b56e3d0d..7ed430e356f363143fcbc93d350ece01ed109746 100644 (file)
@@ -679,7 +679,7 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     
     pa_modargs *ma = NULL;
     int ret = -1;
@@ -698,7 +698,6 @@ int pa__init(pa_core *c, pa_module*m) {
     int namereg_fail;
     int use_mmap = 1, b;
 
-    pa_assert(c);
     pa_assert(m);
     
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -706,7 +705,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    ss = c->default_sample_spec;
+    ss = m->core->default_sample_spec;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
         pa_log("Failed to parse sample specification");
         goto fail;
@@ -732,7 +731,7 @@ int pa__init(pa_core *c, pa_module*m) {
     }
     
     u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
     u->use_mmap = use_mmap;
@@ -796,7 +795,7 @@ int pa__init(pa_core *c, pa_module*m) {
         namereg_fail = 0;
     }
 
-    u->source = pa_source_new(c, __FILE__, name, namereg_fail, &ss, &map);
+    u->source = pa_source_new(m->core, __FILE__, name, namereg_fail, &ss, &map);
     pa_xfree(name_buf);
     
     if (!u->source) {
@@ -849,7 +848,7 @@ int pa__init(pa_core *c, pa_module*m) {
 
         u->mixer_fdl = pa_alsa_fdlist_new();
         
-        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, c->mainloop) < 0) {
+        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, m->core->mainloop) < 0) {
             pa_log("failed to initialise file descriptor monitoring");
             goto fail;
         }
@@ -886,15 +885,14 @@ finish:
 fail:
 
     if (u)
-        pa__done(c, m);
+        pa__done(m);
 
     goto finish;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index 19ac0c26cf86379f06ae0d30923c8078be19ab2e..fd180bc79af20d81de9cde52d7a55f3eea993cbb 100644 (file)
@@ -66,15 +66,14 @@ static void eof_and_exit_cb(pa_cli*c, void *userdata) {
     m->core->mainloop->quit(m->core->mainloop, 0);
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_iochannel *io;
     pa_modargs *ma;
     int exit_on_eof = 0;
 
-    assert(c);
     assert(m);
 
-    if (c->running_as_daemon) {
+    if (m->core->running_as_daemon) {
         pa_log_info("Running as daemon, refusing to load this module.");
         return 0;
     }
@@ -94,12 +93,10 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
-    assert(io);
+    io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO);
     pa_iochannel_set_noclose(io, 1);
 
-    m->userdata = pa_cli_new(c, io, m);
-    assert(m->userdata);
+    m->userdata = pa_cli_new(m->core, io, m);
 
     pa_cli_set_eof_callback(m->userdata, exit_on_eof ? eof_and_exit_cb : eof_and_unload_cb, m);
 
@@ -115,11 +112,10 @@ fail:
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
-    assert(c);
+void pa__done(pa_module*m) {
     assert(m);
 
-    if (c->running_as_daemon == 0) {
+    if (m->core->running_as_daemon == 0) {
         pa_cli_free(m->userdata);
         pa_stdio_release();
     }
index c961412d8b956992299f49f2663540123853b833..5bff748e3abe2d13e4853dbc74c9890b54fd68f1 100644 (file)
@@ -18,8 +18,8 @@ gen_symbol(pa__get_description)
 gen_symbol(pa__get_usage)
 gen_symbol(pa__get_version)
 
-int pa__init(struct pa_core *c, struct pa_module*m);
-void pa__done(struct pa_core *c, struct pa_module*m);
+int pa__init(pa_module*m);
+void pa__done(pa_module*m);
 
 const char* pa__get_author(void);
 const char* pa__get_description(void);
index 190cda9dc6f35ac9fe24b4cc6fdcfb58d2d5288e..858147e317e470bb411f481c93e94bee5da6428d 100644 (file)
@@ -52,6 +52,11 @@ PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers
 PA_MODULE_VERSION(PACKAGE_VERSION)
 PA_MODULE_USAGE("just-one=<boolean>")
 
+static const char* const valid_modargs[] = {
+    "just-one",
+    NULL
+};
+
 #ifdef HAVE_ALSA
 
 static int detect_alsa(pa_core *c, int just_one) {
@@ -215,17 +220,11 @@ static int detect_waveout(pa_core *c, int just_one) {
 }
 #endif
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     int just_one = 0, n = 0;
     pa_modargs *ma;
 
-    static const char* const valid_modargs[] = {
-        "just-one",
-        NULL
-    };
-
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("Failed to parse module arguments");
@@ -238,16 +237,16 @@ int pa__init(pa_core *c, pa_module*m) {
     }
 
 #if HAVE_ALSA
-    if ((n = detect_alsa(c, just_one)) <= 0)
+    if ((n = detect_alsa(m->core, just_one)) <= 0)
 #endif
 #if HAVE_OSS
-    if ((n = detect_oss(c, just_one)) <= 0)
+    if ((n = detect_oss(m->core, just_one)) <= 0)
 #endif
 #if HAVE_SOLARIS
-    if ((n = detect_solaris(c, just_one)) <= 0)
+    if ((n = detect_solaris(m->core, just_one)) <= 0)
 #endif
 #if OS_IS_WIN32
-    if ((n = detect_waveout(c, just_one)) <= 0)
+    if ((n = detect_waveout(m->core, just_one)) <= 0)
 #endif
     {
         pa_log_warn("failed to detect any sound hardware.");
@@ -269,9 +268,3 @@ fail:
 
     return -1;
 }
-
-
-void pa__done(PA_GCC_UNUSED pa_core *c, PA_GCC_UNUSED pa_module*m) {
-    /* NOP */
-}
-
index 1aecade506248324b3f3e6abe5ec382501970d4b..890ebb164e8c40bc0a90b944bff9729f9c794c31 100644 (file)
@@ -26,7 +26,6 @@
 #endif
 
 #include <unistd.h>
-#include <assert.h>
 #include <string.h>
 #include <errno.h>
 
@@ -48,21 +47,23 @@ static const char* const valid_modargs[] = {
     NULL,
 };
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     int ret = -1, fd = -1;
     char x = 1;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs)) ||
         pa_modargs_get_value_s32(ma, "fd", &fd) < 0 ||
         fd < 0) {
+        
         pa_log("Failed to parse module arguments");
         goto finish;
     }
 
     if (pa_loop_write(fd, &x, sizeof(x), NULL) != sizeof(x))
-        pa_log("WARNING: write(%u, 1, 1) failed: %s", fd, pa_cstrerror(errno));
+        pa_log_warn("WARNING: write(%u, 1, 1) failed: %s", fd, pa_cstrerror(errno));
 
     close(fd);
 
@@ -76,9 +77,3 @@ finish:
 
     return ret;
 }
-
-void pa__done(pa_core *c, pa_module*m) {
-    assert(c && m);
-}
-
-
index a9fd166d4b74c81cbab08e8e3ede67fe4e79b37d..1cc86d20a3e52e471c6d7daf57e201e109ff8049 100644 (file)
@@ -25,7 +25,6 @@
 #endif
 
 #include <unistd.h>
-#include <assert.h>
 #include <string.h>
 #include <errno.h>
 #include <signal.h>
@@ -48,11 +47,12 @@ static const char* const valid_modargs[] = {
     NULL,
 };
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     int ret = -1;
     uint32_t pid = 0;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs)) ||
         pa_modargs_get_value_u32(ma, "pid", &pid) < 0 ||
@@ -62,7 +62,7 @@ int pa__init(pa_core *c, pa_module*m) {
     }
 
     if (kill(pid, SIGUSR1) < 0)
-        pa_log("WARNING: kill(%u) failed: %s", pid, pa_cstrerror(errno));
+        pa_log_warn("WARNING: kill(%u) failed: %s", pid, pa_cstrerror(errno));
 
     pa_module_unload_request(m);
 
@@ -74,9 +74,3 @@ finish:
 
     return ret;
 }
-
-void pa__done(pa_core *c, pa_module*m) {
-    assert(c && m);
-}
-
-
index d73ca0ce10119be87f31c5eafa1b7a67b5af3803..672bdc06426c86f984746315e69c27da1411e613 100644 (file)
@@ -46,6 +46,7 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/namereg.h>
 #include <pulsecore/core-scache.h>
+#include <pulsecore/modargs.h>
 
 #include <hal/libhal.h>
 
 PA_MODULE_AUTHOR("Shahms King")
 PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers")
 PA_MODULE_VERSION(PACKAGE_VERSION)
+#if defined(HAVE_ALSA) && defined(HAVE_OSS)
+PA_MODULE_USAGE("api=<alsa or oss>")
+#elif defined(HAVE_ALSA)
+PA_MODULE_USAGE("api=<alsa>")
+#elif defined(HAVE_OSS)
+PA_MODULE_USAGE("api=<oss>")
+#endif
 
 struct device {
     uint32_t index;
@@ -78,6 +86,11 @@ struct timerdata {
 #define CAPABILITY_ALSA "alsa"
 #define CAPABILITY_OSS "oss"
 
+static const char* const valid_modargs[] = {
+    "api",
+    NULL
+};
+
 static void hal_device_free(struct device* d) {
     pa_assert(d);
     
@@ -663,37 +676,65 @@ fail:
     return NULL;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     DBusError error;
     pa_dbus_connection *conn;
     struct userdata *u = NULL;
     LibHalContext *hal_context = NULL;
     int n = 0;
+    pa_modargs *ma;
+    const char *api;
     
-    pa_assert(c);
     pa_assert(m);
 
     dbus_error_init(&error);
-    
-    if (!(conn = pa_dbus_bus_get(c, DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set(&error)) {
+
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log("Failed to parse module arguments");
+        goto fail;
+    }
+
+    if ((api = pa_modargs_get_value(ma, "api", NULL))) {
+        int good = 0;
+
+#ifdef HAVE_ALSA
+        if (strcmp(api, CAPABILITY_ALSA) == 0) {
+            good = 1;
+            api = CAPABILITY_ALSA;
+        } 
+#endif
+#ifdef HAVE_OSS
+        if (strcmp(api, CAPABILITY_OSS) == 0) {
+            good = 1;
+            api = CAPABILITY_OSS;
+        }
+#endif
+        
+        if (!good) {
+            pa_log_error("Invalid API specification.");
+            goto fail;
+        }
+    }
+        
+    if (!(conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set(&error)) {
         if (conn)
             pa_dbus_connection_unref(conn);
         pa_log_error("Unable to contact DBUS system bus: %s: %s", error.name, error.message);
         goto fail;
     }
 
-    if (!(hal_context = hal_context_new(c, pa_dbus_connection_get(conn)))) {
+    if (!(hal_context = hal_context_new(m->core, pa_dbus_connection_get(conn)))) {
         /* pa_hal_context_new() logs appropriate errors */
         pa_dbus_connection_unref(conn);
         goto fail;
     }
 
     u = pa_xnew(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->context = hal_context;
     u->connection = conn;
     u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    u->capability = NULL;
+    u->capability = api;
     m->userdata = u;
 
 #ifdef HAVE_ALSA
@@ -736,19 +777,24 @@ int pa__init(pa_core *c, pa_module*m) {
     
     pa_log_info("Loaded %i modules.", n);
 
+    pa_modargs_free(ma);
+    
     return 0;
 
 fail:
+    if (ma)
+        pa_modargs_free(ma);
+    
     dbus_error_free(&error);
-    pa__done(c, m);
+    pa__done(m);
+
     return -1;
 }
 
 
-void pa__done(PA_GCC_UNUSED pa_core *c, pa_module *m) {
+void pa__done(pa_module *m) {
     struct userdata *u;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index 452fa1f3c810f5ab1512373cfa1ad118ab4b8236..6f4e98dce4a851b8003d7d6a2d4fdb8d6ab3f1fa 100644 (file)
@@ -68,11 +68,12 @@ static int lirc_in_use = 0;
 static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) {
     struct userdata *u = userdata;
     char *name = NULL, *code = NULL;
-    assert(io);
-    assert(u);
+
+    pa_assert(io);
+    pa_assert(u);
 
     if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) {
-        pa_log("lost connection to LIRC daemon.");
+        pa_log("Lost connection to LIRC daemon.");
         goto fail;
     }
 
@@ -86,7 +87,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
 
         c = pa_xstrdup(code);
         c[strcspn(c, "\n\r")] = 0;
-        pa_log_debug("raw IR code '%s'", c);
+        pa_log_debug("Raw IR code '%s'", c);
         pa_xfree(c);
 
         while (lirc_code2char(u->config, code, &name) == 0 && name) {
@@ -99,7 +100,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
                 MUTE_TOGGLE
             } volchange = INVALID;
 
-            pa_log_info("translated IR code '%s'", name);
+            pa_log_info("Translated IR code '%s'", name);
 
             if (strcasecmp(name, "volume-up") == 0)
                 volchange = UP;
@@ -113,12 +114,12 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
                 volchange = RESET;
 
             if (volchange == INVALID)
-                pa_log_warn("recieved unknown IR code '%s'", name);
+                pa_log_warn("Recieved unknown IR code '%s'", name);
             else {
                 pa_sink *s;
 
                 if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK, 1)))
-                    pa_log("failed to get sink '%s'", u->sink_name);
+                    pa_log("Failed to get sink '%s'", u->sink_name);
                 else {
                     int i;
                     pa_cvolume cv = *pa_sink_get_volume(s);
@@ -179,13 +180,14 @@ fail:
 
     pa_module_unload_request(u->module);
 
-    free(code);
+    pa_xfree(code);
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (lirc_in_use) {
         pa_log("module-lirc may no be loaded twice.");
@@ -197,7 +199,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    m->userdata = u = pa_xmalloc(sizeof(struct userdata));
+    m->userdata = u = pa_xnew(struct userdata, 1);
     u->module = m;
     u->io = NULL;
     u->config = NULL;
@@ -215,7 +217,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    u->io = c->mainloop->io_new(c->mainloop, u->lirc_fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);
+    u->io = m->core->mainloop->io_new(m->core->mainloop, u->lirc_fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);
 
     lirc_in_use = 1;
 
@@ -228,14 +230,13 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     if (!(u = m->userdata))
         return;
index 0b051facbf7ef121414b9ad8e13d0d97004b2871..373ed487cf36a36488deb7e337ac25033b4e9f57 100644 (file)
@@ -26,7 +26,6 @@
 #endif
 
 #include <unistd.h>
-#include <assert.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -80,6 +79,8 @@ static int load_rules(struct userdata *u, const char *filename) {
     struct rule *end = NULL;
     char *fn = NULL;
 
+    pa_assert(u);
+
     f = filename ?
         fopen(fn = pa_xstrdup(filename), "r") :
         pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn, "r");
@@ -132,7 +133,7 @@ static int load_rules(struct userdata *u, const char *filename) {
             goto finish;
         }
 
-        rule = pa_xmalloc(sizeof(struct rule));
+        rule = pa_xnew(struct rule, 1);
         rule->regex = regex;
         rule->volume = volume;
         rule->next = NULL;
@@ -164,7 +165,9 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
     struct userdata *u =  userdata;
     pa_sink_input *si;
     struct rule *r;
-    assert(c && u);
+    
+    pa_assert(c);
+    pa_assert(u);
 
     if (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW))
         return;
@@ -185,17 +188,18 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
     }
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("Failed to parse module arguments");
         goto fail;
     }
 
-    u = pa_xmalloc(sizeof(struct userdata));
+    u = pa_xnew(struct userdata, 1);
     u->rules = NULL;
     u->subscription = NULL;
     m->userdata = u;
@@ -203,23 +207,24 @@ int pa__init(pa_core *c, pa_module*m) {
     if (load_rules(u, pa_modargs_get_value(ma, "table", NULL)) < 0)
         goto fail;
 
-    u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);
+    u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);
 
     pa_modargs_free(ma);
     return 0;
 
 fail:
-    pa__done(c, m);
+    pa__done(m);
 
     if (ma)
         pa_modargs_free(ma);
     return  -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata* u;
     struct rule *r, *n;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (!(u = m->userdata))
         return;
index 919b399d76b9c2d4254eea5faf9e9804d6b783b7..03394c0a25f362b047bd980ead5dc85b6629779c 100644 (file)
@@ -26,7 +26,6 @@
 #endif
 
 #include <stdio.h>
-#include <assert.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -80,11 +79,12 @@ struct userdata {
 
 static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) {
     struct userdata *u = userdata;
-    assert(io);
-    assert(u);
+    
+    pa_assert(io);
+    pa_assert(u);
 
     if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) {
-        pa_log("lost connection to evdev device.");
+        pa_log("Lost connection to evdev device.");
         goto fail;
     }
 
@@ -92,14 +92,14 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
         struct input_event ev;
 
         if (pa_loop_read(u->fd, &ev, sizeof(ev), &u->fd_type) <= 0) {
-            pa_log("failed to read from event device: %s", pa_cstrerror(errno));
+            pa_log("Failed to read from event device: %s", pa_cstrerror(errno));
             goto fail;
         }
 
         if (ev.type == EV_KEY && (ev.value == 1 || ev.value == 2)) {
             enum { INVALID, UP, DOWN, MUTE_TOGGLE } volchange = INVALID;
 
-            pa_log_debug("key code=%u, value=%u", ev.code, ev.value);
+            pa_log_debug("Key code=%u, value=%u", ev.code, ev.value);
 
             switch (ev.code) {
                 case KEY_VOLUMEDOWN:  volchange = DOWN; break;
@@ -111,7 +111,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
                 pa_sink *s;
 
                 if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK, 1)))
-                    pa_log("failed to get sink '%s'", u->sink_name);
+                    pa_log("Failed to get sink '%s'", u->sink_name);
                 else {
                     int i;
                     pa_cvolume cv = *pa_sink_get_volume(s);
@@ -165,21 +165,23 @@ fail:
 
 #define test_bit(bit, array) (array[bit/8] & (1<<(bit%8)))
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
+    
     pa_modargs *ma = NULL;
     struct userdata *u;
     int version;
     struct _input_id input_id;
     char name[256];
     uint8_t evtype_bitmask[EV_MAX/8 + 1];
-    assert(c && m);
+
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("Failed to parse module arguments");
         goto fail;
     }
 
-    m->userdata = u = pa_xmalloc(sizeof(struct userdata));
+    m->userdata = u = pa_xnew(struct userdata,1);
     u->module = m;
     u->io = NULL;
     u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
@@ -221,11 +223,11 @@ int pa__init(pa_core *c, pa_module*m) {
     }
 
     if (!test_bit(EV_KEY, evtype_bitmask)) {
-        pa_log("device has no keys.");
+        pa_log("Device has no keys.");
         goto fail;
     }
 
-    u->io = c->mainloop->io_new(c->mainloop, u->fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);
+    u->io = m->core->mainloop->io_new(m->core->mainloop, u->fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);
 
     pa_modargs_free(ma);
 
@@ -236,14 +238,14 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
-    assert(c);
-    assert(m);
+
+    pa_assert(m);
 
     if (!(u = m->userdata))
         return;
index 3c1c2bca4877d6b89a36b1d8eabf028db1b62ccc..b0a9ebb0bcd90851d205a75a29c4c90b76e281af 100644 (file)
 #endif
 
 #include <stdio.h>
-#include <assert.h>
 #include <unistd.h>
 
 #include <pulsecore/module.h>
+#include <pulsecore/macro.h>
 #include <pulsecore/iochannel.h>
 #include <pulsecore/modargs.h>
 #include <pulsecore/protocol-native.h>
@@ -48,25 +48,26 @@ static const char* const valid_modargs[] = {
     NULL,
 };
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_iochannel *io;
     pa_modargs *ma;
     int fd, r = -1;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
-        pa_log("failed to parse module arguments.");
+        pa_log("Failed to parse module arguments.");
         goto finish;
     }
 
     if (pa_modargs_get_value_s32(ma, "fd", &fd) < 0) {
-        pa_log("invalid file descriptor.");
+        pa_log("Invalid file descriptor.");
         goto finish;
     }
 
-    io = pa_iochannel_new(c->mainloop, fd, fd);
+    io = pa_iochannel_new(m->core->mainloop, fd, fd);
 
-    if (!(m->userdata = pa_protocol_native_new_iochannel(c, io, m, ma))) {
+    if (!(m->userdata = pa_protocol_native_new_iochannel(m->core, io, m, ma))) {
         pa_iochannel_free(io);
         goto finish;
     }
@@ -80,8 +81,8 @@ finish:
     return r;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
-    assert(c && m);
+void pa__done(pa_module*m) {
+    pa_assert(m);
 
     pa_protocol_native_free(m->userdata);
 }
index f0e3a061398bee2a280dccbbd2432399b612baeb..2ede01a42ae1869c8e43f17f1d0631b6cc6de90a 100644 (file)
@@ -198,13 +198,12 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     struct userdata *u = NULL;
     pa_sample_spec ss;
     pa_channel_map map;
     pa_modargs *ma = NULL;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -212,20 +211,20 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    ss = c->default_sample_spec;
+    ss = m->core->default_sample_spec;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("Invalid sample format specification or channel map");
         goto fail;
     }
 
     u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
 
     pa_assert_se(u->asyncmsgq = pa_asyncmsgq_new(0));
     
-    if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
+    if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
         pa_log("Failed to create sink.");
         goto fail;
     }
@@ -254,15 +253,14 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
 
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index a43bdb3cdc293f5b0ea5699a0c524b557e85e522..d93d8c79e27cbb866fa2ef1756b933809ebac2d2 100644 (file)
@@ -1059,7 +1059,7 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     
     struct audio_buf_info info;
     struct userdata *u = NULL;
@@ -1075,7 +1075,6 @@ int pa__init(pa_core *c, pa_module*m) {
     const char *name;
     int namereg_fail;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -1095,7 +1094,7 @@ int pa__init(pa_core *c, pa_module*m) {
 
     mode = (playback && record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0));
 
-    ss = c->default_sample_spec;
+    ss = m->core->default_sample_spec;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_OSS) < 0) {
         pa_log("Failed to parse sample specification or channel map");
         goto fail;
@@ -1150,7 +1149,7 @@ int pa__init(pa_core *c, pa_module*m) {
     pa_assert(frag_size > 0);
 
     u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
     u->fd = fd;
@@ -1206,7 +1205,7 @@ int pa__init(pa_core *c, pa_module*m) {
             namereg_fail = 0;
         }
 
-        u->source = pa_source_new(c, __FILE__, name, namereg_fail, &ss, &map);
+        u->source = pa_source_new(m->core, __FILE__, name, namereg_fail, &ss, &map);
         pa_xfree(name_buf);
         if (!u->source) {
             pa_log("Failed to create source object");
@@ -1260,7 +1259,7 @@ try_write:
             namereg_fail = 0;
         }
 
-        u->sink = pa_sink_new(c, __FILE__, name, namereg_fail, &ss, &map);
+        u->sink = pa_sink_new(m->core, __FILE__, name, namereg_fail, &ss, &map);
         pa_xfree(name_buf);
         if (!u->sink) {
             pa_log("Failed to create sink object");
@@ -1310,7 +1309,7 @@ go_on:
 fail:
 
     if (u)
-        pa__done(c, m);
+        pa__done(m);
     else if (fd >= 0)
         close(fd);
 
@@ -1320,10 +1319,9 @@ fail:
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index 83ee06b7108f8f6faf92d623703574ce17be87de..1b6d081375c854ebebeadf3707f4ad5723285b51 100644 (file)
@@ -232,7 +232,7 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     struct userdata *u;
     struct stat st;
     pa_sample_spec ss;
@@ -240,7 +240,6 @@ int pa__init(pa_core *c, pa_module*m) {
     pa_modargs *ma;
     char *t;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -248,14 +247,14 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    ss = c->default_sample_spec;
+    ss = m->core->default_sample_spec;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("Invalid sample format specification or channel map");
         goto fail;
     }
 
     u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
     pa_memchunk_reset(&u->memchunk);
@@ -283,7 +282,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
+    if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
         pa_log("Failed to create sink.");
         goto fail;
     }
@@ -309,15 +308,14 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
 
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index a5f95f9a3604c76d8fa0545bba3c5fdd6f0f3ab2..a8fbcf3d0c9fd144a0e5b1bcb54a8ffc55ea8c0e 100644 (file)
@@ -210,7 +210,7 @@ finish:
     pa_log_debug("Thread shutting down");
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     struct userdata *u;
     struct stat st;
     pa_sample_spec ss;
@@ -218,7 +218,6 @@ int pa__init(pa_core *c, pa_module*m) {
     pa_modargs *ma;
     char *t;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -226,14 +225,14 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    ss = c->default_sample_spec;
+    ss = m->core->default_sample_spec;
     if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {
         pa_log("invalid sample format specification or channel map");
         goto fail;
     }
 
     u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     m->userdata = u;
     pa_memchunk_reset(&u->memchunk);
@@ -261,7 +260,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) {
+    if (!(u->source = pa_source_new(m->core, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) {
         pa_log("Failed to create source.");
         goto fail;
     }
@@ -286,15 +285,14 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
 
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index 3edb59e51425aaddfc2323e50b0bee7529acffb0..fb7cf22d969204b6b29d8e872759b6ef1bd9a1cf 100644 (file)
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <errno.h>
 #include <stdio.h>
-#include <assert.h>
 #include <unistd.h>
 #include <limits.h>
 
 #include <netinet/in.h>
 #endif
 
-#include "../pulsecore/winsock.h"
-
 #include <pulse/xmalloc.h>
 
+#include <pulsecore/winsock.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/module.h>
 #include <pulsecore/socket-server.h>
@@ -204,10 +202,9 @@ struct userdata {
 #endif
 };
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     int ret = -1;
-
     struct userdata *u = NULL;
 
 #if defined(USE_TCP_SOCKETS)
@@ -224,7 +221,7 @@ int pa__init(pa_core *c, pa_module*m) {
 #endif
 #endif
 
-    assert(c && m);
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("Failed to parse module arguments");
@@ -242,22 +239,22 @@ int pa__init(pa_core *c, pa_module*m) {
     listen_on = pa_modargs_get_value(ma, "listen", NULL);
 
     if (listen_on) {
-        s_ipv6 = pa_socket_server_new_ipv6_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
-        s_ipv4 = pa_socket_server_new_ipv4_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
+        s_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);
+        s_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);
     } else {
-        s_ipv6 = pa_socket_server_new_ipv6_any(c->mainloop, port, TCPWRAP_SERVICE);
-        s_ipv4 = pa_socket_server_new_ipv4_any(c->mainloop, port, TCPWRAP_SERVICE);
+        s_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, port, TCPWRAP_SERVICE);
+        s_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, port, TCPWRAP_SERVICE);
     }
 
     if (!s_ipv4 && !s_ipv6)
         goto fail;
 
     if (s_ipv4)
-        if (!(u->protocol_ipv4 = protocol_new(c, s_ipv4, m, ma)))
+        if (!(u->protocol_ipv4 = protocol_new(m->core, s_ipv4, m, ma)))
             pa_socket_server_unref(s_ipv4);
 
     if (s_ipv6)
-        if (!(u->protocol_ipv6 = protocol_new(c, s_ipv6, m, ma)))
+        if (!(u->protocol_ipv6 = protocol_new(m->core, s_ipv6, m, ma)))
             pa_socket_server_unref(s_ipv6);
 
     if (!u->protocol_ipv4 && !u->protocol_ipv6)
@@ -274,7 +271,7 @@ int pa__init(pa_core *c, pa_module*m) {
     /* This socket doesn't reside in our own runtime dir but in
      * /tmp/.esd/, hence we have to create the dir first */
 
-    if (pa_make_secure_parent_dir(u->socket_path, c->is_system_instance ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) {
+    if (pa_make_secure_parent_dir(u->socket_path, m->core->is_system_instance ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) {
         pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno));
         goto fail;
     }
@@ -292,10 +289,10 @@ int pa__init(pa_core *c, pa_module*m) {
     if (r)
         pa_log("Removed stale UNIX socket '%s'.", tmp);
 
-    if (!(s = pa_socket_server_new_unix(c->mainloop, tmp)))
+    if (!(s = pa_socket_server_new_unix(m->core->mainloop, tmp)))
         goto fail;
 
-    if (!(u->protocol_unix = protocol_new(c, s, m, ma)))
+    if (!(u->protocol_unix = protocol_new(m->core, s, m, ma)))
         goto fail;
 
 #endif
@@ -341,11 +338,10 @@ fail:
     goto finish;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
 
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     u = m->userdata;
 
@@ -366,7 +362,6 @@ void pa__done(pa_core *c, pa_module*m) {
     }
 #endif
 
-
     pa_xfree(u->socket_path);
 #endif
 
index 034660e43650789a7d76ea03d87b3f8c3c42b14e..fa22d60a6f84000fa928cfe9b83ed6f54e055f42 100644 (file)
@@ -126,11 +126,10 @@ static pa_hook_result_t source_hook_callback(pa_core *c, pa_source *source, void
     return PA_HOOK_OK;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -139,17 +138,16 @@ int pa__init(pa_core *c, pa_module*m) {
     }
 
     m->userdata = u = pa_xnew(struct userdata, 1);
-    u->sink_slot = pa_hook_connect(&c->hook_sink_disconnect, (pa_hook_cb_t) sink_hook_callback, NULL);
-    u->source_slot = pa_hook_connect(&c->hook_source_disconnect, (pa_hook_cb_t) source_hook_callback, NULL);
+    u->sink_slot = pa_hook_connect(&m->core->hook_sink_disconnect, (pa_hook_cb_t) sink_hook_callback, NULL);
+    u->source_slot = pa_hook_connect(&m->core->hook_source_disconnect, (pa_hook_cb_t) source_hook_callback, NULL);
 
     pa_modargs_free(ma);
     return 0;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
 
-    pa_assert(c);
     pa_assert(m);
 
     if (!m->userdata)
index 797ba44052303893e969fad75f983b3a05bf40ce..f2830ff0ab1a9417c3c89a44171dc186bcc4b9b6 100644 (file)
@@ -114,7 +114,7 @@ static void calc_sine(float *f, size_t l, float freq) {
         f[i] = (float) sin((double) i/l*M_PI*2*freq)/2;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
     pa_sink *sink;
@@ -130,13 +130,13 @@ int pa__init(pa_core *c, pa_module*m) {
     }
 
     m->userdata = u = pa_xnew0(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->module = m;
     u->sink_input = NULL;
     u->memblock = NULL;
     u->peek_index = 0;
 
-    if (!(sink = pa_namereg_get(c, pa_modargs_get_value(ma, "sink", NULL), PA_NAMEREG_SINK, 1))) {
+    if (!(sink = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink", NULL), PA_NAMEREG_SINK, 1))) {
         pa_log("No such sink.");
         goto fail;
     }
@@ -151,7 +151,7 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    u->memblock = pa_memblock_new(c->mempool, pa_bytes_per_second(&ss));
+    u->memblock = pa_memblock_new(m->core->mempool, pa_bytes_per_second(&ss));
     p = pa_memblock_acquire(u->memblock);
     calc_sine(p, pa_memblock_get_length(u->memblock), frequency);
     pa_memblock_release(u->memblock);
@@ -165,7 +165,7 @@ int pa__init(pa_core *c, pa_module*m) {
     pa_sink_input_new_data_set_sample_spec(&data, &ss);
     data.module = m;
 
-    if (!(u->sink_input = pa_sink_input_new(c, &data, 0)))
+    if (!(u->sink_input = pa_sink_input_new(m->core, &data, 0)))
         goto fail;
 
     u->sink_input->peek = sink_input_peek_cb;
@@ -182,14 +182,13 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(u = m->userdata))
index d2c51a10f6fb3af6155d1256fc5056c62f7961cb..ad148644d194878360f63d88621c692e673a5fc6 100644 (file)
@@ -209,7 +209,7 @@ static pa_hook_result_t device_disconnect_hook_cb(pa_core *c, pa_object *o, stru
     return PA_HOOK_OK;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
     uint32_t timeout = 5;
@@ -217,8 +217,7 @@ int pa__init(pa_core *c, pa_module*m) {
     pa_sink *sink;
     pa_source *source;
 
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("Failed to parse module arguments.");
@@ -231,25 +230,25 @@ int pa__init(pa_core *c, pa_module*m) {
     }
     
     m->userdata = u = pa_xnew(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->timeout = timeout;
     u->device_infos = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
 
-    for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx))
-        device_new_hook_cb(c, PA_OBJECT(sink), u);
+    for (sink = pa_idxset_first(m->core->sinks, &idx); sink; sink = pa_idxset_next(m->core->sinks, &idx))
+        device_new_hook_cb(m->core, PA_OBJECT(sink), u);
 
-    for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx))
-        device_new_hook_cb(c, PA_OBJECT(source), u);
+    for (source = pa_idxset_first(m->core->sources, &idx); source; source = pa_idxset_next(m->core->sources, &idx))
+        device_new_hook_cb(m->core, PA_OBJECT(source), u);
 
-    u->sink_new_slot = pa_hook_connect(&c->hook_sink_new_post, (pa_hook_cb_t) device_new_hook_cb, u);
-    u->source_new_slot = pa_hook_connect(&c->hook_source_new_post, (pa_hook_cb_t) device_new_hook_cb, u);
-    u->sink_disconnect_slot = pa_hook_connect(&c->hook_sink_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u);
-    u->source_disconnect_slot = pa_hook_connect(&c->hook_source_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u);
+    u->sink_new_slot = pa_hook_connect(&m->core->hook_sink_new_post, (pa_hook_cb_t) device_new_hook_cb, u);
+    u->source_new_slot = pa_hook_connect(&m->core->hook_source_new_post, (pa_hook_cb_t) device_new_hook_cb, u);
+    u->sink_disconnect_slot = pa_hook_connect(&m->core->hook_sink_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u);
+    u->source_disconnect_slot = pa_hook_connect(&m->core->hook_source_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u);
 
-    u->sink_input_new_slot = pa_hook_connect(&c->hook_sink_input_new_post, (pa_hook_cb_t) sink_input_new_hook_cb, u);
-    u->source_output_new_slot = pa_hook_connect(&c->hook_source_output_new_post, (pa_hook_cb_t) source_output_new_hook_cb, u);
-    u->sink_input_disconnect_slot = pa_hook_connect(&c->hook_sink_input_disconnect_post, (pa_hook_cb_t) sink_input_disconnect_hook_cb, u);
-    u->source_output_disconnect_slot = pa_hook_connect(&c->hook_source_output_disconnect_post, (pa_hook_cb_t) source_output_disconnect_hook_cb, u);
+    u->sink_input_new_slot = pa_hook_connect(&m->core->hook_sink_input_new_post, (pa_hook_cb_t) sink_input_new_hook_cb, u);
+    u->source_output_new_slot = pa_hook_connect(&m->core->hook_source_output_new_post, (pa_hook_cb_t) source_output_new_hook_cb, u);
+    u->sink_input_disconnect_slot = pa_hook_connect(&m->core->hook_sink_input_disconnect_post, (pa_hook_cb_t) sink_input_disconnect_hook_cb, u);
+    u->source_output_disconnect_slot = pa_hook_connect(&m->core->hook_source_output_disconnect_post, (pa_hook_cb_t) source_output_disconnect_hook_cb, u);
     
     pa_modargs_free(ma);
     return 0;
@@ -262,12 +261,11 @@ fail:
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     struct device_info *d;
     
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     if (!m->userdata)
         return;
index 0f0d998ba52cd7d8705544225c707a4d5d30423f..addd937b56c60806a43eed3766381437e879cf89 100644 (file)
@@ -420,11 +420,10 @@ static pa_hook_result_t source_output_hook_callback(pa_core *c, pa_source_output
     return PA_HOOK_OK;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
 
-    assert(c);
     assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -444,16 +443,15 @@ int pa__init(pa_core *c, pa_module*m) {
     if (load_rules(u) < 0)
         goto fail;
 
-    u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u);
-    u->sink_input_hook_slot = pa_hook_connect(&c->hook_sink_input_new, (pa_hook_cb_t) sink_input_hook_callback, u);
-    u->source_output_hook_slot = pa_hook_connect(&c->hook_source_output_new, (pa_hook_cb_t) source_output_hook_callback, u);
+    u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u);
+    u->sink_input_hook_slot = pa_hook_connect(&m->core->hook_sink_input_new, (pa_hook_cb_t) sink_input_hook_callback, u);
+    u->source_output_hook_slot = pa_hook_connect(&m->core->hook_source_output_new, (pa_hook_cb_t) source_output_hook_callback, u);
 
     pa_modargs_free(ma);
     return 0;
 
 fail:
-    pa__done(c, m);
-
+    pa__done(m);
     if (ma)
         pa_modargs_free(ma);
 
@@ -470,10 +468,9 @@ static void free_func(void *p, void *userdata) {
     pa_xfree(r);
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata* u;
 
-    assert(c);
     assert(m);
 
     if (!(u = m->userdata))
index 0c3c63f3be0e12a9160807d464c63ea902c637f9..e59db83cbcb3e4a978415b7cfbf3c254d18cf489 100644 (file)
@@ -88,14 +88,13 @@ static int x11_event_callback(pa_x11_wrapper *w, XEvent *e, void *userdata) {
     return 1;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
 
     struct userdata *u = NULL;
     pa_modargs *ma = NULL;
     int major, minor;
     unsigned int auto_ctrls, auto_values;
     
-    pa_assert(c);
     pa_assert(m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -104,12 +103,12 @@ int pa__init(pa_core *c, pa_module*m) {
     }
 
     m->userdata = u = pa_xnew(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->scache_item = pa_xstrdup(pa_modargs_get_value(ma, "sample", "x11-bell"));
     u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
     u->x11_client = NULL;
 
-    if (!(u->x11_wrapper = pa_x11_wrapper_get(c, pa_modargs_get_value(ma, "display", NULL))))
+    if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
         goto fail;
 
     major = XkbMajorVersion;
@@ -143,16 +142,15 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
     
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata *u;
     
-    assert(c);
-    assert(m);
+    pa_assert(m);
 
     if (!m->userdata)
         return;
index fd1d532f53369b89fd8075fc2195525d8659af01..7da9cc2d3464443f484126e22cd8a097eac5864a 100644 (file)
@@ -26,7 +26,6 @@
 #endif
 
 #include <stdio.h>
-#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -76,7 +75,7 @@ struct userdata {
 };
 
 static int load_key(struct userdata *u, const char*fn) {
-    assert(u);
+    pa_assert(u);
 
     u->auth_cookie_in_property = 0;
 
@@ -93,7 +92,7 @@ static int load_key(struct userdata *u, const char*fn) {
     if (pa_authkey_load_auto(fn, u->auth_cookie, sizeof(u->auth_cookie)) < 0)
         return -1;
 
-    pa_log_debug("loading cookie from disk.");
+    pa_log_debug("Loading cookie from disk.");
 
     if (pa_authkey_prop_put(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0)
         u->auth_cookie_in_property = 1;
@@ -101,7 +100,7 @@ static int load_key(struct userdata *u, const char*fn) {
     return 0;
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
     struct userdata *u;
     pa_modargs *ma = NULL;
     char hn[256], un[128];
@@ -110,23 +109,25 @@ int pa__init(pa_core *c, pa_module*m) {
     char *s;
     pa_strlist *l;
 
+    pa_assert(m);
+    
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("failed to parse module arguments");
         goto fail;
     }
 
     m->userdata = u = pa_xmalloc(sizeof(struct userdata));
-    u->core = c;
+    u->core = m->core;
     u->id = NULL;
     u->auth_cookie_in_property = 0;
 
     if (load_key(u, pa_modargs_get_value(ma, "cookie", NULL)) < 0)
         goto fail;
 
-    if (!(u->x11_wrapper = pa_x11_wrapper_get(c, pa_modargs_get_value(ma, "display", NULL))))
+    if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
         goto fail;
 
-    if (!(l = pa_property_get(c, PA_NATIVE_SERVER_PROPERTY_NAME)))
+    if (!(l = pa_property_get(m->core, PA_NATIVE_SERVER_PROPERTY_NAME)))
         goto fail;
 
     s = pa_strlist_tostring(l);
@@ -154,13 +155,14 @@ fail:
     if (ma)
         pa_modargs_free(ma);
 
-    pa__done(c, m);
+    pa__done(m);
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata*u;
-    assert(c && m);
+    
+    pa_assert(m);
 
     if (!(u = m->userdata))
         return;
@@ -185,7 +187,7 @@ void pa__done(pa_core *c, pa_module*m) {
         pa_x11_wrapper_unref(u->x11_wrapper);
 
     if (u->auth_cookie_in_property)
-        pa_authkey_prop_unref(c, PA_NATIVE_COOKIE_PROPERTY_NAME);
+        pa_authkey_prop_unref(m->core, PA_NATIVE_COOKIE_PROPERTY_NAME);
 
     pa_xfree(u->id);
     pa_xfree(u);
index dc23ebe3d53c4576d78c8dd5d701f747525aa211..4ef437a1d3cc70f7defccb8d64603842345a974e 100644 (file)
@@ -49,17 +49,14 @@ PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("X11 session management")
 PA_MODULE_VERSION(PACKAGE_VERSION)
 
-struct userdata {
-    pa_core *core;
-    SmcConn sm_conn;
-};
+static int ice_in_use = 0;
 
 static const char* const valid_modargs[] = {
     NULL
 };
 
 static void die_cb(SmcConn connection, SmPointer client_data){
-    pa_core *c = client_data;
+    pa_core *c = PA_CORE(client_data);
 
     pa_log_debug("Got die message from XSM. Exiting...");
     
@@ -98,18 +95,26 @@ static void new_ice_connection(IceConn connection, IcePointer client_data, Bool
         c->mainloop->io_free(*watch_data);
 }
 
-int pa__init(pa_core *c, pa_module*m) {
-    struct userdata *u = NULL;
+int pa__init(pa_module*m) {
+
     pa_modargs *ma = NULL;
     char t[256], *vendor, *client_id;
     SmcCallbacks callbacks;
     SmProp prop_program, prop_user;
     SmProp *prop_list[2];
     SmPropValue val_program, val_user;
+    SmcConn connection;
     
-    pa_assert(c);
     pa_assert(m);
 
+    if (ice_in_use) {
+        pa_log("module-x11-xsmp may no be loaded twice.");
+        return -1;
+    }
+    
+    IceAddConnectionWatch(new_ice_connection, m->core);
+    ice_in_use = 1;
+
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log("Failed to parse module arguments");
         goto fail;
@@ -119,23 +124,19 @@ int pa__init(pa_core *c, pa_module*m) {
         pa_log("X11 session manager not running.");
         goto fail;
     }
-
-    m->userdata = u = pa_xnew(struct userdata, 1);
-    u->core = c;
-    u->sm_conn = NULL;
-
-    IceAddConnectionWatch(new_ice_connection, c);
     
     memset(&callbacks, 0, sizeof(callbacks));
     callbacks.die.callback = die_cb;
-    callbacks.die.client_data = c;
-
+    callbacks.die.client_data = m->core;
     callbacks.save_yourself.callback = save_yourself_cb;
+    callbacks.save_yourself.client_data = m->core;
     callbacks.save_complete.callback = save_complete_cb;
+    callbacks.save_complete.client_data = m->core;
     callbacks.shutdown_cancelled.callback = shutdown_cancelled_cb;
+    callbacks.shutdown_cancelled.client_data = m->core;
     
-    if (!(u->sm_conn = SmcOpenConnection(
-                  NULL, u,
+    if (!(m->userdata = connection = SmcOpenConnection(
+                  NULL, m->core,
                   SmProtoMajor, SmProtoMinor,
                   SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask,
                   &callbacks, NULL, &client_id,
@@ -162,9 +163,9 @@ int pa__init(pa_core *c, pa_module*m) {
     prop_user.vals = &val_user;
     prop_list[1] = &prop_user;
 
-    SmcSetProperties(u->sm_conn, PA_ELEMENTSOF(prop_list), prop_list);
+    SmcSetProperties(connection, PA_ELEMENTSOF(prop_list), prop_list);
 
-    pa_log_info("Connected to session manager '%s' as '%s'.", vendor = SmcVendor(u->sm_conn), client_id);
+    pa_log_info("Connected to session manager '%s' as '%s'.", vendor = SmcVendor(connection), client_id);
     free(vendor);
     free(client_id);
     
@@ -176,26 +177,19 @@ fail:
     if (ma)
         pa_modargs_free(ma);
     
-    pa__done(c, m);
+    pa__done(m);
     
     return -1;
 }
 
-void pa__done(pa_core *c, pa_module*m) {
-    struct userdata *u;
-    
-    assert(c);
-    assert(m);
-
-    if (!m->userdata)
-        return;
-
-    u = m->userdata;
+void pa__done(pa_module*m) {
+    pa_assert(m);
 
-    if (u->sm_conn)
-        SmcCloseConnection(u->sm_conn, 0, NULL);
+    if (m->userdata)
+        SmcCloseConnection(m->userdata, 0, NULL);
 
-    IceRemoveConnectionWatch(new_ice_connection, c);
-    
-    pa_xfree(u);
+    if (ice_in_use) {
+        IceRemoveConnectionWatch(new_ice_connection, m->core);
+        ice_in_use = 0;
+    }
 }
index 69508ad0367298cb122c1487b8fec4a9a23e28dc..34565395fb080948b39322d294a6a9995dba9d41 100644 (file)
@@ -102,25 +102,25 @@ struct userdata {
 };
 
 static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description) {
-    assert(u && s && s->loaded.valid && ret_ss && ret_description);
+    pa_assert(u && s && s->loaded.valid && ret_ss && ret_description);
 
     if (s->loaded.type == PA_NAMEREG_SINK) {
         pa_sink *sink = pa_idxset_get_by_index(u->core->sinks, s->loaded.index);
-        assert(sink);
+        pa_assert(sink);
         *ret_ss = sink->sample_spec;
         *ret_description = sink->description;
     } else if (s->loaded.type == PA_NAMEREG_SOURCE) {
         pa_source *source = pa_idxset_get_by_index(u->core->sources, s->loaded.index);
-        assert(source);
+        pa_assert(source);
         *ret_ss = source->sample_spec;
         *ret_description = source->description;
     } else
-        assert(0);
+        pa_assert(0);
 }
 
 static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList *l) {
     char s[128];
-    assert(c);
+    pa_assert(c);
 
     l = avahi_string_list_add_pair(l, "server-version", PACKAGE_NAME" "PACKAGE_VERSION);
     l = avahi_string_list_add_pair(l, "user-name", pa_get_user_name(s, sizeof(s)));
@@ -150,8 +150,8 @@ static int publish_service(struct userdata *u, struct service *s) {
     int r = -1;
     AvahiStringList *txt = NULL;
 
-    assert(u);
-    assert(s);
+    pa_assert(u);
+    pa_assert(s);
 
     if (!u->client || avahi_client_get_state(u->client) != AVAHI_CLIENT_S_RUNNING)
         return 0;
@@ -265,7 +265,7 @@ static struct service *get_service(struct userdata *u, const char *name, const c
 static int publish_sink(struct userdata *u, pa_sink *s) {
     struct service *svc;
     int ret;
-    assert(u && s);
+    pa_assert(u && s);
 
     svc = get_service(u, s->name, s->description);
     if (svc->loaded.valid)
@@ -286,7 +286,7 @@ static int publish_source(struct userdata *u, pa_source *s) {
     struct service *svc;
     int ret;
 
-    assert(u && s);
+    pa_assert(u && s);
 
     svc = get_service(u, s->name, s->description);
     if (svc->loaded.valid)
@@ -309,7 +309,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) {
     struct service *svc;
     int ret;
 
-    assert(u && s);
+    pa_assert(u && s);
 
     svc = get_service(u, s->name, NULL);
     if (svc->autoload.valid)
@@ -328,7 +328,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) {
 
 static int remove_sink(struct userdata *u, uint32_t idx) {
     struct service *svc;
-    assert(u && idx != PA_INVALID_INDEX);
+    pa_assert(u && idx != PA_INVALID_INDEX);
 
     if (!(svc = pa_dynarray_get(u->sink_dynarray, idx)))
         return 0;
@@ -344,7 +344,7 @@ static int remove_sink(struct userdata *u, uint32_t idx) {
 
 static int remove_source(struct userdata *u, uint32_t idx) {
     struct service *svc;
-    assert(u && idx != PA_INVALID_INDEX);
+    pa_assert(u && idx != PA_INVALID_INDEX);
 
     if (!(svc = pa_dynarray_get(u->source_dynarray, idx)))
         return 0;
@@ -360,7 +360,7 @@ static int remove_source(struct userdata *u, uint32_t idx) {
 
 static int remove_autoload(struct userdata *u, uint32_t idx) {
     struct service *svc;
-    assert(u && idx != PA_INVALID_INDEX);
+    pa_assert(u && idx != PA_INVALID_INDEX);
 
     if (!(svc = pa_dynarray_get(u->autoload_dynarray, idx)))
         return 0;
@@ -376,7 +376,7 @@ static int remove_autoload(struct userdata *u, uint32_t idx) {
 
 static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
     struct userdata *u = userdata;
-    assert(u && c);
+    pa_assert(u && c);
 
     switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK)
         case PA_SUBSCRIPTION_EVENT_SINK: {
@@ -439,7 +439,7 @@ static int publish_main_service(struct userdata *u);
 
 static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
     struct userdata *u = userdata;
-    assert(u);
+    pa_assert(u);
 
     if (state == AVAHI_ENTRY_GROUP_COLLISION) {
         char *t;
@@ -501,7 +501,7 @@ static int publish_all_services(struct userdata *u) {
     int r = -1;
     uint32_t idx;
 
-    assert(u);
+    pa_assert(u);
 
     pa_log_debug("Publishing services in Zeroconf");
 
@@ -531,7 +531,7 @@ static void unpublish_all_services(struct userdata *u, int rem) {
     void *state = NULL;
     struct service *s;
 
-    assert(u);
+    pa_assert(u);
 
     pa_log_debug("Unpublishing services in Zeroconf");
 
@@ -558,7 +558,7 @@ static void unpublish_all_services(struct userdata *u, int rem) {
 
 static void client_callback(AvahiClient *c, AvahiClientState state, void *userdata) {
     struct userdata *u = userdata;
-    assert(c);
+    pa_assert(c);
 
     u->client = c;
 
@@ -587,7 +587,8 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda
     }
 }
 
-int pa__init(pa_core *c, pa_module*m) {
+int pa__init(pa_module*m) {
+    
     struct userdata *u;
     uint32_t port = PA_NATIVE_DEFAULT_PORT;
     pa_modargs *ma = NULL;
@@ -599,23 +600,23 @@ int pa__init(pa_core *c, pa_module*m) {
         goto fail;
     }
 
-    if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port == 0 || port >= 0xFFFF) {
+    if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port <= 0 || port > 0xFFFF) {
         pa_log("invalid port specified.");
         goto fail;
     }
 
     m->userdata = u = pa_xnew(struct userdata, 1);
-    u->core = c;
+    u->core = m->core;
     u->port = (uint16_t) port;
 
-    u->avahi_poll = pa_avahi_poll_new(c->mainloop);
+    u->avahi_poll = pa_avahi_poll_new(m->core->mainloop);
 
     u->services = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
     u->sink_dynarray = pa_dynarray_new();
     u->source_dynarray = pa_dynarray_new();
     u->autoload_dynarray = pa_dynarray_new();
 
-    u->subscription = pa_subscription_new(c,
+    u->subscription = pa_subscription_new(m->core,
                                           PA_SUBSCRIPTION_MASK_SINK|
                                           PA_SUBSCRIPTION_MASK_SOURCE|
                                           PA_SUBSCRIPTION_MASK_AUTOLOAD, subscribe_callback, u);
@@ -634,7 +635,7 @@ int pa__init(pa_core *c, pa_module*m) {
     return 0;
 
 fail:
-    pa__done(c, m);
+    pa__done(m);
 
     if (ma)
         pa_modargs_free(ma);
@@ -646,8 +647,8 @@ static void service_free(void *p, void *userdata) {
     struct service *s = p;
     struct userdata *u = userdata;
 
-    assert(s);
-    assert(u);
+    pa_assert(s);
+    pa_assert(u);
 
     if (s->entry_group)
         avahi_entry_group_free(s->entry_group);
@@ -657,9 +658,9 @@ static void service_free(void *p, void *userdata) {
     pa_xfree(s);
 }
 
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module*m) {
     struct userdata*u;
-    assert(c && m);
+    pa_assert(m);
 
     if (!(u = m->userdata))
         return;
diff --git a/src/pulsecore/ltdl-helper.c b/src/pulsecore/ltdl-helper.c
new file mode 100644 (file)
index 0000000..bdce18e
--- /dev/null
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+/***
+  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
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <pulse/xmalloc.h>
+#include <pulse/util.h>
+
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+#include "ltdl-helper.h"
+
+pa_void_func_t pa_load_sym(lt_dlhandle handle, const char *module, const char *symbol) {
+    char *sn, *c;
+    pa_void_func_t f;
+
+    pa_assert(handle);
+    pa_assert(module);
+    pa_assert(symbol);
+    
+    if ((f = ((pa_void_func_t) (long) lt_dlsym(handle, symbol))))
+        return f;
+
+    /* As the .la files might have been cleansed from the system, we should
+     * try with the ltdl prefix as well. */
+
+    sn = pa_sprintf_malloc("%s_LTX_%s", module, symbol);
+
+    for (c = sn; *c; c++)
+        if (!isalnum(*c))
+            *c = '_';
+
+    f = (pa_void_func_t) (long) lt_dlsym(handle, sn);
+    pa_xfree(sn);
+
+    return f;
+}
diff --git a/src/pulsecore/ltdl-helper.h b/src/pulsecore/ltdl-helper.h
new file mode 100644 (file)
index 0000000..5c7388a
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef foopulsecoreltdlhelperhfoo
+#define foopulsecoreltdlhelperhfoo
+
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-2006 Lennart Poettering
+
+  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.
+***/
+
+#include <ltdl.h>
+
+typedef void (*pa_void_func_t)(void);
+
+pa_void_func_t pa_load_sym(lt_dlhandle handle, const char*module, const char *symbol);
+
+#endif
+
index 58394e594d6e42d8daf11a64f33a65693643c75a..79baef842a3a039ca8995167c4d4457c2ed203b5 100644 (file)
 #endif
 
 #include <ltdl.h>
-#include <assert.h>
 
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/core-util.h>
 #include <pulsecore/log.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/ltdl-helper.h>
 
 #include "modinfo.h"
 
 #define PA_SYMBOL_USAGE "pa__get_usage"
 #define PA_SYMBOL_VERSION "pa__get_version"
 
-/* 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);
-}
-
-pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {
+pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name) {
     pa_modinfo *i;
     const char* (*func)(void);
-    assert(dl);
+
+    pa_assert(dl);
 
     i = pa_xnew0(pa_modinfo, 1);
 
-    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_AUTHOR)))
+    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_AUTHOR)))
         i->author = pa_xstrdup(func());
 
-    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_DESCRIPTION)))
+    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DESCRIPTION)))
         i->description = pa_xstrdup(func());
 
-    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_USAGE)))
+    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_USAGE)))
         i->usage = pa_xstrdup(func());
 
-    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_VERSION)))
+    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_VERSION)))
         i->version = pa_xstrdup(func());
 
     return i;
@@ -72,14 +67,15 @@ pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {
 pa_modinfo *pa_modinfo_get_by_name(const char *name) {
     lt_dlhandle dl;
     pa_modinfo *i;
-    assert(name);
+    
+    pa_assert(name);
 
     if (!(dl = lt_dlopenext(name))) {
         pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());
         return NULL;
     }
 
-    i = pa_modinfo_get_by_handle(dl);
+    i = pa_modinfo_get_by_handle(dl, name);
     lt_dlclose(dl);
 
     return i;
@@ -87,6 +83,7 @@ pa_modinfo *pa_modinfo_get_by_name(const char *name) {
 
 void pa_modinfo_free(pa_modinfo *i) {
     assert(i);
+    
     pa_xfree(i->author);
     pa_xfree(i->description);
     pa_xfree(i->usage);
index 3ee33ede4cda3c2609a4e2cb9995d560789e6f31..02e536c66d6d7d92bb463fab5d0027befcdbcf6a 100644 (file)
@@ -34,7 +34,7 @@ typedef struct pa_modinfo {
 } pa_modinfo;
 
 /* Read meta data from an libtool handle */
-pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl);
+pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name);
 
 /* Read meta data from a module file */
 pa_modinfo *pa_modinfo_get_by_name(const char *name);
index 09b15b8b01f917f45fc301d63b6cf3d9f858300d..bd5655469d6a62d2e12e6d56852e6906d82c0e15 100644 (file)
@@ -29,7 +29,6 @@
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
@@ -40,6 +39,8 @@
 #include <pulsecore/core-subscribe.h>
 #include <pulsecore/log.h>
 #include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/ltdl-helper.h>
 
 #include "module.h"
 
 
 #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,9 @@ static void pa_module_free(pa_module *m) {
 }
 
 void pa_module_unload(pa_core *c, pa_module *m) {
-    assert(c && m);
+    pa_assert(c && m);
 
-    assert(c->modules);
+    pa_assert(c->modules);
     if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL)))
         return;
 
@@ -210,9 +168,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 +179,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 +211,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 +226,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 +237,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 +248,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 +271,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);
 }
index 750dfaa8dd1f133c09ec96c5b4b7194c4d232111..7a93a071aac7191f72beabadcccd15007d09a0f9 100644 (file)
@@ -39,8 +39,8 @@ struct pa_module {
 
     lt_dlhandle dl;
 
-    int (*init)(pa_core *c, pa_module*m);
-    void (*done)(pa_core *c, pa_module*m);
+    int (*init)(pa_module*m);
+    void (*done)(pa_module*m);
 
     void *userdata;
 
@@ -62,9 +62,9 @@ void pa_module_unload_request(pa_module *m);
 
 void pa_module_set_used(pa_module*m, int used);
 
-#define PA_MODULE_AUTHOR(s) const char * pa__get_author(void) { return s; }
-#define PA_MODULE_DESCRIPTION(s) const char * pa__get_description(void) { return s; }
-#define PA_MODULE_USAGE(s) const char * pa__get_usage(void) { return s; }
+#define PA_MODULE_AUTHOR(s) const char *pa__get_author(void) { return s; }
+#define PA_MODULE_DESCRIPTION(s) const char *pa__get_description(void) { return s; }
+#define PA_MODULE_USAGE(s) const char *pa__get_usage(void) { return s; }
 #define PA_MODULE_VERSION(s) const char * pa__get_version(void) { return s; }
 
 pa_modinfo *pa_module_get_info(pa_module *m);