[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.13-427-g47a9b96

Lennart Poettering gitmailer-noreply at 0pointer.de
Thu Jan 29 07:27:43 PST 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  daf0612e372f66d70bc40655e637c00675e1b4c1 (commit)

- Log -----------------------------------------------------------------
47a9b96... add some helpers for dealing with DBusPendingCall based on Mrc-Andre's work in module-bluetooth-discover
746dc2a... get rid of nonsensical late initialization of namereg/scache and things
4a06af6... make use of new functions pa_dbus_add_matches/pa_dbus_remove_matches
509535d... add new functions pa_dbus_add_matches()/pa_dbus_remove_matches()
-----------------------------------------------------------------------

Summary of changes:
 src/modules/dbus-util.c          |  105 ++++++++++++++++++++++++++++++++++++++
 src/modules/dbus-util.h          |   27 ++++++++++
 src/modules/module-console-kit.c |   16 +++---
 src/modules/module-hal-detect.c  |   27 ++++------
 src/pulsecore/core-scache.c      |   22 +++-----
 src/pulsecore/core-scache.h      |    2 +-
 src/pulsecore/core.c             |   41 +++++++++------
 src/pulsecore/core.h             |    9 ++--
 src/pulsecore/module.c           |   20 ++------
 src/pulsecore/namereg.c          |   15 +-----
 src/pulsecore/namereg.h          |    2 -
 src/pulsecore/shared.c           |   26 ---------
 src/pulsecore/shared.h           |    6 --
 13 files changed, 191 insertions(+), 127 deletions(-)

-----------------------------------------------------------------------

commit 509535d240506bc35881fe8d254f0bce28aed4c8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 29 03:30:50 2009 +0100

    add new functions pa_dbus_add_matches()/pa_dbus_remove_matches()

diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c
index d2abf08..1fc1e86 100644
--- a/src/modules/dbus-util.c
+++ b/src/modules/dbus-util.c
@@ -24,6 +24,8 @@
 #include <config.h>
 #endif
 
+#include <stdarg.h>
+
 #include <pulse/xmalloc.h>
 #include <pulse/timeval.h>
 #include <pulsecore/log.h>
@@ -325,3 +327,58 @@ pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *err
 
     return pconn;
 }
+
+int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) {
+    const char *t;
+    va_list ap;
+    unsigned k = 0;
+
+    pa_assert(c);
+    pa_assert(error);
+
+    va_start(ap, error);
+    while ((t = va_arg(ap, const char*))) {
+        dbus_bus_add_match(c, t, error);
+
+        if (dbus_error_is_set(error))
+            goto fail;
+
+        k++;
+    }
+    va_end(ap);
+    return 0;
+
+fail:
+
+    va_end(ap);
+    va_start(ap, error);
+    for (; k > 0; k--) {
+        DBusError e;
+
+        pa_assert_se(t = va_arg(ap, const char*));
+
+        dbus_error_init(&e);
+        dbus_bus_remove_match(c, t, &e);
+        dbus_error_free(&e);
+    }
+    va_end(ap);
+
+    return -1;
+}
+
+void pa_dbus_remove_matches(DBusConnection *c, ...) {
+    const char *t;
+    va_list ap;
+    DBusError error;
+
+    pa_assert(c);
+
+    dbus_error_init(&error);
+
+    va_start(ap, c);
+    while ((t = va_arg(ap, const char*))) {
+        dbus_bus_remove_match(c, t, &error);
+        dbus_error_free(&error);
+    }
+    va_end(ap);
+}
diff --git a/src/modules/dbus-util.h b/src/modules/dbus-util.h
index c4794da..0ab8780 100644
--- a/src/modules/dbus-util.h
+++ b/src/modules/dbus-util.h
@@ -37,4 +37,7 @@ DBusConnection* pa_dbus_connection_get(pa_dbus_connection *conn);
 pa_dbus_connection* pa_dbus_connection_ref(pa_dbus_connection *conn);
 void pa_dbus_connection_unref(pa_dbus_connection *conn);
 
+int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) PA_GCC_SENTINEL;
+void pa_dbus_remove_matches(DBusConnection *c,  ...) PA_GCC_SENTINEL;
+
 #endif

commit 4a06af6081c0fc081ad6ca136880a61ebe1c4e01
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 29 03:31:42 2009 +0100

    make use of new functions pa_dbus_add_matches/pa_dbus_remove_matches

diff --git a/src/modules/module-console-kit.c b/src/modules/module-console-kit.c
index 4f3ed8d..805f5ee 100644
--- a/src/modules/module-console-kit.c
+++ b/src/modules/module-console-kit.c
@@ -313,8 +313,10 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    dbus_bus_add_match(pa_dbus_connection_get(connection), "type='signal',sender='org.freedesktop.ConsoleKit', interface='org.freedesktop.ConsoleKit.Seat'", &error);
-    if (dbus_error_is_set(&error)) {
+    if (pa_dbus_add_matches(
+                pa_dbus_connection_get(connection), &error,
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionAdded'",
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionRemoved'", NULL) < 0) {
         pa_log_error("Unable to subscribe to ConsoleKit signals: %s: %s", error.name, error.message);
         goto fail;
     }
@@ -354,14 +356,12 @@ void pa__done(pa_module *m) {
     }
 
     if (u->connection) {
-        DBusError error;
-        dbus_error_init(&error);
-
-        dbus_bus_remove_match(pa_dbus_connection_get(u->connection), "type='signal',sender='org.freedesktop.ConsoleKit', interface='org.freedesktop.ConsoleKit.Seat'", &error);
-        dbus_error_free(&error);
+        pa_dbus_remove_matches(
+                pa_dbus_connection_get(u->connection),
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionAdded'",
+                "type='signal',sender='org.freedesktop.ConsoleKit',interface='org.freedesktop.ConsoleKit.Seat',member='SessionRemoved'", NULL);
 
         dbus_connection_remove_filter(pa_dbus_connection_get(u->connection), filter_cb, u);
-
         pa_dbus_connection_unref(u->connection);
     }
 
diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c
index d3b351a..8b1f0b2 100644
--- a/src/modules/module-hal-detect.c
+++ b/src/modules/module-hal-detect.c
@@ -773,18 +773,15 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    dbus_bus_add_match(pa_dbus_connection_get(u->connection), "type='signal',sender='org.freedesktop.Hal', interface='org.freedesktop.Hal.Device.AccessControl'", &error);
-    if (dbus_error_is_set(&error)) {
+    if (pa_dbus_add_matches(
+                pa_dbus_connection_get(u->connection), &error,
+                "type='signal',sender='org.freedesktop.Hal',interface='org.freedesktop.Hal.Device.AccessControl',member='ACLAdded'",
+                "type='signal',sender='org.freedesktop.Hal',interface='org.freedesktop.Hal.Device.AccessControl',member='ACLRemoved'",
+                "type='signal',interface='org.pulseaudio.Server',member='DirtyGiveUpMessage'", NULL) < 0) {
         pa_log_error("Unable to subscribe to HAL ACL signals: %s: %s", error.name, error.message);
         goto fail;
     }
 
-    dbus_bus_add_match(pa_dbus_connection_get(u->connection), "type='signal',interface='org.pulseaudio.Server'", &error);
-    if (dbus_error_is_set(&error)) {
-        pa_log_error("Unable to subscribe to PulseAudio signals: %s: %s", error.name, error.message);
-        goto fail;
-    }
-
     pa_log_info("Loaded %i modules.", n);
 
     pa_modargs_free(ma);
@@ -825,17 +822,13 @@ void pa__done(pa_module *m) {
     }
 
     if (u->connection) {
-        DBusError error;
-        dbus_error_init(&error);
-
-        dbus_bus_remove_match(pa_dbus_connection_get(u->connection), "type='signal',sender='org.freedesktop.Hal', interface='org.freedesktop.Hal.Device.AccessControl'", &error);
-        dbus_error_free(&error);
-
-        dbus_bus_remove_match(pa_dbus_connection_get(u->connection), "type='signal',interface='org.pulseaudio.Server'", &error);
-        dbus_error_free(&error);
+        pa_dbus_remove_matches(
+                pa_dbus_connection_get(u->connection),
+                "type='signal',sender='org.freedesktop.Hal',interface='org.freedesktop.Hal.Device.AccessControl',member='ACLAdded'",
+                "type='signal',sender='org.freedesktop.Hal',interface='org.freedesktop.Hal.Device.AccessControl',member='ACLRemoved'",
+                "type='signal',interface='org.pulseaudio.Server',member='DirtyGiveUpMessage'", NULL);
 
         dbus_connection_remove_filter(pa_dbus_connection_get(u->connection), filter_cb, u);
-
         pa_dbus_connection_unref(u->connection);
     }
 

commit 746dc2ac19950d4eecc083929d6ed86443e3a112
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 29 16:25:29 2009 +0100

    get rid of nonsensical late initialization of namereg/scache and things

diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c
index 6d2ae93..e548941 100644
--- a/src/pulsecore/core-scache.c
+++ b/src/pulsecore/core-scache.c
@@ -120,9 +120,6 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
         e->core = c;
         e->proplist = pa_proplist_new();
 
-        if (!c->scache)
-            c->scache = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-
         pa_idxset_put(c->scache, e, &e->index);
 
         pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_NEW, e->index);
@@ -287,23 +284,18 @@ int pa_scache_remove_item(pa_core *c, const char *name) {
     return 0;
 }
 
-static void free_cb(void *p, void *userdata) {
-    pa_scache_entry *e = p;
-    pa_assert(e);
-
-    free_entry(e);
-}
+void pa_scache_free_all(pa_core *c) {
+    pa_scache_entry *e;
 
-void pa_scache_free(pa_core *c) {
     pa_assert(c);
 
-    if (c->scache) {
-        pa_idxset_free(c->scache, free_cb, NULL);
-        c->scache = NULL;
-    }
+    while ((e = pa_idxset_steal_first(c->scache, NULL)))
+        free_entry(e);
 
-    if (c->scache_auto_unload_event)
+    if (c->scache_auto_unload_event) {
         c->mainloop->time_free(c->scache_auto_unload_event);
+        c->scache_auto_unload_event = NULL;
+    }
 }
 
 int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx) {
diff --git a/src/pulsecore/core-scache.h b/src/pulsecore/core-scache.h
index a75f8ac..1fe3c30 100644
--- a/src/pulsecore/core-scache.h
+++ b/src/pulsecore/core-scache.h
@@ -58,7 +58,7 @@ int pa_scache_add_directory_lazy(pa_core *c, const char *pathname);
 int pa_scache_remove_item(pa_core *c, const char *name);
 int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx);
 int pa_scache_play_item_by_name(pa_core *c, const char *name, const char*sink_name, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx);
-void pa_scache_free(pa_core *c);
+void pa_scache_free_all(pa_core *c);
 
 const char *pa_scache_get_name_by_id(pa_core *c, uint32_t id);
 uint32_t pa_scache_get_id_by_name(pa_core *c, const char *name);
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 689fc8f..5fd2bdf 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -92,21 +92,22 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) {
 
     c->state = PA_CORE_STARTUP;
     c->mainloop = m;
+
     c->clients = pa_idxset_new(NULL, NULL);
+    c->cards = pa_idxset_new(NULL, NULL);
     c->sinks = pa_idxset_new(NULL, NULL);
     c->sources = pa_idxset_new(NULL, NULL);
-    c->source_outputs = pa_idxset_new(NULL, NULL);
     c->sink_inputs = pa_idxset_new(NULL, NULL);
-    c->cards = pa_idxset_new(NULL, NULL);
+    c->source_outputs = pa_idxset_new(NULL, NULL);
+    c->modules = pa_idxset_new(NULL, NULL);
+    c->scache = pa_idxset_new(NULL, NULL);
+
+    c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 
     c->default_source = NULL;
     c->default_sink = NULL;
 
-    c->modules = NULL;
-    c->namereg = NULL;
-    c->scache = NULL;
-    c->running_as_daemon = FALSE;
-
     c->default_sample_spec.format = PA_SAMPLE_S16NE;
     c->default_sample_spec.rate = 44100;
     c->default_sample_spec.channels = 2;
@@ -128,22 +129,20 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) {
 
     c->exit_idle_time = -1;
     c->scache_idle_time = 20;
-    c->flat_volumes = TRUE;
-
-    c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 3;
 
+    c->flat_volumes = TRUE;
     c->disallow_module_loading = FALSE;
     c->disallow_exit = FALSE;
+    c->running_as_daemon = FALSE;
     c->realtime_scheduling = FALSE;
     c->realtime_priority = 5;
     c->disable_remixing = FALSE;
     c->disable_lfe_remixing = FALSE;
+    c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 3;
 
     for (j = 0; j < PA_CORE_HOOK_MAX; j++)
         pa_hook_init(&c->hooks[j], c);
 
-    pa_shared_init(c);
-
     pa_random(&c->cookie, sizeof(c->cookie));
 
 #ifdef SIGPIPE
@@ -165,7 +164,13 @@ static void core_free(pa_object *o) {
     c->state = PA_CORE_SHUTDOWN;
 
     pa_module_unload_all(c);
-    pa_assert(!c->modules);
+    pa_scache_free_all(c);
+
+    pa_assert(pa_idxset_isempty(c->scache));
+    pa_idxset_free(c->scache, NULL, NULL);
+
+    pa_assert(pa_idxset_isempty(c->modules));
+    pa_idxset_free(c->modules, NULL, NULL);
 
     pa_assert(pa_idxset_isempty(c->clients));
     pa_idxset_free(c->clients, NULL, NULL);
@@ -185,8 +190,12 @@ static void core_free(pa_object *o) {
     pa_assert(pa_idxset_isempty(c->sink_inputs));
     pa_idxset_free(c->sink_inputs, NULL, NULL);
 
-    pa_scache_free(c);
-    pa_namereg_free(c);
+    pa_assert(pa_hashmap_isempty(c->namereg));
+    pa_hashmap_free(c->namereg, NULL, NULL);
+
+    pa_assert(pa_hashmap_isempty(c->shared));
+    pa_hashmap_free(c->shared, NULL, NULL);
+
     pa_subscription_free_all(c);
 
     if (c->exit_event)
@@ -198,8 +207,6 @@ static void core_free(pa_object *o) {
     pa_silence_cache_done(&c->silence_cache);
     pa_mempool_free(c->mempool);
 
-    pa_shared_cleanup(c);
-
     for (j = 0; j < PA_CORE_HOOK_MAX; j++)
         pa_hook_done(&c->hooks[j]);
 
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index b349c6f..2b8f819 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -112,7 +112,7 @@ struct pa_core {
     /* Some hashmaps for all sorts of entities */
     pa_hashmap *namereg, *shared;
 
-    /* The name of the default sink/source */
+    /* The default sink/source */
     pa_source *default_source;
     pa_sink *default_sink;
 
@@ -129,13 +129,12 @@ struct pa_core {
     pa_mempool *mempool;
     pa_silence_cache silence_cache;
 
-    int exit_idle_time, scache_idle_time;
-    pa_bool_t flat_volumes;
-
     pa_time_event *exit_event;
-
     pa_time_event *scache_auto_unload_event;
 
+    int exit_idle_time, scache_idle_time;
+
+    pa_bool_t flat_volumes:1;
     pa_bool_t disallow_module_loading:1;
     pa_bool_t disallow_exit:1;
     pa_bool_t running_as_daemon:1;
diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c
index d470bb0..1eb70c8 100644
--- a/src/pulsecore/module.c
+++ b/src/pulsecore/module.c
@@ -75,7 +75,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 */
@@ -105,9 +105,6 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *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);
 
@@ -200,17 +197,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);
@@ -226,9 +217,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);
diff --git a/src/pulsecore/namereg.c b/src/pulsecore/namereg.c
index f3d5a8f..ac456ac 100644
--- a/src/pulsecore/namereg.c
+++ b/src/pulsecore/namereg.c
@@ -87,16 +87,6 @@ char* pa_namereg_make_valid_name(const char *name) {
     return n;
 }
 
-void pa_namereg_free(pa_core *c) {
-    pa_assert(c);
-
-    if (!c->namereg)
-        return;
-
-    pa_assert(pa_hashmap_size(c->namereg) == 0);
-    pa_hashmap_free(c->namereg, NULL, NULL);
-}
-
 const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, pa_bool_t fail) {
     struct namereg_entry *e;
     char *n = NULL;
@@ -118,9 +108,6 @@ const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t
             return NULL;
     }
 
-    if (!c->namereg)
-        c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-
     if ((e = pa_hashmap_get(c->namereg, name)) && fail) {
         pa_xfree(n);
         return NULL;
@@ -210,7 +197,7 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
     if (*name == '@' || !name || !pa_namereg_is_valid_name(name))
         return NULL;
 
-    if (c->namereg && (e = pa_hashmap_get(c->namereg, name)))
+    if ((e = pa_hashmap_get(c->namereg, name)))
         if (e->type == type)
             return e->data;
 
diff --git a/src/pulsecore/namereg.h b/src/pulsecore/namereg.h
index b91dd52..ff99525 100644
--- a/src/pulsecore/namereg.h
+++ b/src/pulsecore/namereg.h
@@ -34,8 +34,6 @@ typedef enum pa_namereg_type {
     PA_NAMEREG_CARD
 } pa_namereg_type_t;
 
-void pa_namereg_free(pa_core *c);
-
 const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, pa_bool_t fail);
 void pa_namereg_unregister(pa_core *c, const char *name);
 void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type);
diff --git a/src/pulsecore/shared.c b/src/pulsecore/shared.c
index d6e42dd..9485dc3 100644
--- a/src/pulsecore/shared.c
+++ b/src/pulsecore/shared.c
@@ -99,32 +99,6 @@ int pa_shared_remove(pa_core *c, const char *name) {
     return 0;
 }
 
-void pa_shared_init(pa_core *c) {
-    pa_assert(c);
-
-    c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-}
-
-void pa_shared_cleanup(pa_core *c) {
-    pa_assert(c);
-
-    if (!c->shared)
-        return;
-
-    if (!pa_hashmap_isempty(c->shared)) {
-        pa_strbuf *s = pa_strbuf_new();
-
-        pa_shared_dump(c, s);
-        pa_log_debug("%s", pa_strbuf_tostring(s));
-        pa_strbuf_free(s);
-        pa_assert(pa_hashmap_isempty(c->shared));
-    }
-
-    pa_hashmap_free(c->shared, NULL, NULL);
-    c->shared = NULL;
-
-}
-
 void pa_shared_dump(pa_core *c, pa_strbuf *s) {
     void *state = NULL;
     pa_shared *p;
diff --git a/src/pulsecore/shared.h b/src/pulsecore/shared.h
index dd3f94e..f6f8d3c 100644
--- a/src/pulsecore/shared.h
+++ b/src/pulsecore/shared.h
@@ -49,12 +49,6 @@ int pa_shared_remove(pa_core *c, const char *name);
 /* A combination of pa_shared_remove() and pa_shared_set() */
 int pa_shared_replace(pa_core *c, const char *name, void *data);
 
-/* Free all memory used by the shared property system */
-void pa_shared_cleanup(pa_core *c);
-
-/* Initialize the shared property system */
-void pa_shared_init(pa_core *c);
-
 /* Dump the current set of shared properties */
 void pa_shared_dump(pa_core *c, pa_strbuf *s);
 

commit 47a9b96b64e9fd949adf4dd1fbd26c5d75a5df30
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 29 16:26:34 2009 +0100

    add some helpers for dealing with DBusPendingCall based on Mrc-Andre's work in module-bluetooth-discover

diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c
index 1fc1e86..f6a986a 100644
--- a/src/modules/dbus-util.c
+++ b/src/modules/dbus-util.c
@@ -382,3 +382,51 @@ void pa_dbus_remove_matches(DBusConnection *c, ...) {
     }
     va_end(ap);
 }
+
+pa_dbus_pending *pa_dbus_pending_new(DBusMessage *m, DBusPendingCall *pending, void *context_data, void *call_data) {
+    pa_dbus_pending *p;
+
+    pa_assert(pending);
+
+    p = pa_xnew(pa_dbus_pending, 1);
+    p->message = m;
+    p->pending = pending;
+    p->context_data = context_data;
+    p->call_data = call_data;
+
+    PA_LLIST_INIT(pa_dbus_pending, p);
+
+    return p;
+}
+
+void pa_dbus_pending_free(pa_dbus_pending *p) {
+    pa_assert(p);
+
+    if (p->pending) {
+        dbus_pending_call_cancel(p->pending);
+        dbus_pending_call_unref(p->pending);
+    }
+
+    if (p->message)
+        dbus_message_unref(p->message);
+
+    pa_xfree(p);
+}
+
+void pa_dbus_sync_pending_list(pa_dbus_pending **p) {
+    pa_assert(p);
+
+    while (*p)
+        dbus_pending_call_block((*p)->pending);
+}
+
+void pa_dbus_free_pending_list(pa_dbus_pending **p) {
+    pa_dbus_pending *i;
+
+    pa_assert(p);
+
+    while ((i = *p)) {
+        PA_LLIST_REMOVE(pa_dbus_pending, *p, i);
+        pa_dbus_pending_free(i);
+    }
+}
diff --git a/src/modules/dbus-util.h b/src/modules/dbus-util.h
index 0ab8780..fd97467 100644
--- a/src/modules/dbus-util.h
+++ b/src/modules/dbus-util.h
@@ -25,6 +25,7 @@
 #include <dbus/dbus.h>
 
 #include <pulsecore/core.h>
+#include <pulsecore/llist.h>
 
 typedef struct pa_dbus_connection pa_dbus_connection;
 
@@ -40,4 +41,27 @@ void pa_dbus_connection_unref(pa_dbus_connection *conn);
 int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) PA_GCC_SENTINEL;
 void pa_dbus_remove_matches(DBusConnection *c,  ...) PA_GCC_SENTINEL;
 
+typedef struct pa_dbus_pending pa_dbus_pending;
+
+struct userdata; /* We leave the actual definition to the caller */
+
+struct pa_dbus_pending {
+    DBusMessage *message;
+    DBusPendingCall *pending;
+
+    void *context_data;
+    void *call_data;
+
+    PA_LLIST_FIELDS(pa_dbus_pending);
+};
+
+pa_dbus_pending *pa_dbus_pending_new(DBusMessage *m, DBusPendingCall *pending, void *context_data, void *call_data);
+void pa_dbus_pending_free(pa_dbus_pending *p);
+
+/* Sync up a list of pa_dbus_pending_call objects */
+void pa_dbus_sync_pending_list(pa_dbus_pending **p);
+
+/* Free up a list of pa_dbus_pending_call objects */
+void pa_dbus_free_pending_list(pa_dbus_pending **p);
+
 #endif

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list