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

Lennart Poettering gitmailer-noreply at 0pointer.de
Tue Jan 27 19:24:18 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  a5401a50a67ebf1d86e979ee5556961b24a25400 (commit)

- Log -----------------------------------------------------------------
b56e038... Merge commit '12db687acf3befe485bfff3700111999c95247fa'
12db687... bluetooth: cold hsp/a2dp device detection
a6a1b42... bluetooth: hsp volume control
-----------------------------------------------------------------------

Summary of changes:
 src/modules/bluetooth/module-bluetooth-device.c   |  224 ++++++++++++++++-
 src/modules/bluetooth/module-bluetooth-discover.c |  291 ++++++++++++++++++++-
 2 files changed, 510 insertions(+), 5 deletions(-)

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

commit a6a1b42c871710f8a492f32adc72272cef9d019c
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Mon Jan 19 14:53:35 2009 +0200

    bluetooth: hsp volume control

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 804be35..e2f6d01 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -65,7 +65,10 @@ PA_MODULE_LOAD_ONCE(FALSE);
 PA_MODULE_USAGE(
         "sink_name=<name of the device> "
         "address=<address of the device> "
-        "profile=<a2dp|hsp>");
+        "profile=<a2dp|hsp> "
+        "rate=<sample rate> "
+        "channels=<number of channels> "
+        "path=<device object path>");
 
 struct bt_a2dp {
     sbc_capabilities_t sbc_capabilities;
@@ -85,6 +88,7 @@ struct userdata {
     pa_core *core;
     pa_module *module;
     pa_sink *sink;
+    pa_source *source;
 
     pa_thread_mq thread_mq;
     pa_rtpoll *rtpoll;
@@ -109,6 +113,8 @@ struct userdata {
     pa_usec_t latency;
 
     struct bt_a2dp a2dp;
+    char *path;
+    pa_dbus_connection *conn;
 };
 
 static const char* const valid_modargs[] = {
@@ -117,6 +123,7 @@ static const char* const valid_modargs[] = {
     "profile",
     "rate",
     "channels",
+    "path",
     NULL
 };
 
@@ -228,9 +235,9 @@ static int bt_getcaps(struct userdata *u) {
     msg.getcaps_req.h.length = sizeof(msg.getcaps_req);
 
     strncpy(msg.getcaps_req.device, u->addr, 18);
-    if (strcasecmp(u->profile, "a2dp") == 0)
+    if (pa_streq(u->profile, "a2dp"))
         msg.getcaps_req.transport = BT_CAPABILITIES_TRANSPORT_A2DP;
-    else if (strcasecmp(u->profile, "hsp") == 0)
+    else if (pa_streq(u->profile, "hsp"))
         msg.getcaps_req.transport = BT_CAPABILITIES_TRANSPORT_SCO;
     else {
         pa_log_error("Invalid profile argument: %s", u->profile);
@@ -789,6 +796,144 @@ finish:
     pa_log_debug("IO thread shutting down");
 }
 
+static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *userdata) {
+    DBusMessageIter arg_i;
+    DBusError err;
+    const char *value;
+    struct userdata *u;
+
+    pa_assert(bus);
+    pa_assert(msg);
+    pa_assert(userdata);
+    u = userdata;
+
+    pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
+                 dbus_message_get_interface(msg),
+                 dbus_message_get_path(msg),
+                 dbus_message_get_member(msg));
+
+    dbus_error_init(&err);
+
+    if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged") ||
+        dbus_message_is_signal(msg, "org.bluez.AudioSink", "PropertyChanged")) {
+
+        struct device *d;
+        const char *profile;
+        DBusMessageIter variant_i;
+        dbus_uint16_t gain;
+
+        if (!dbus_message_iter_init(msg, &arg_i)) {
+            pa_log("dbus: message has no parameters");
+            goto done;
+        }
+
+        if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_STRING) {
+            pa_log("Property name not a string.");
+            goto done;
+        }
+
+        dbus_message_iter_get_basic(&arg_i, &value);
+
+        if (!dbus_message_iter_next(&arg_i)) {
+            pa_log("Property value missing");
+            goto done;
+        }
+
+        if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_VARIANT) {
+            pa_log("Property value not a variant.");
+            goto done;
+        }
+
+        dbus_message_iter_recurse(&arg_i, &variant_i);
+
+        if (dbus_message_iter_get_arg_type(&variant_i) != DBUS_TYPE_UINT16) {
+            dbus_message_iter_get_basic(&variant_i, &gain);
+
+            if (pa_streq(value, "SpeakerGain")) {
+                pa_log("spk gain: %d", gain);
+                pa_cvolume_set(&u->sink->volume, 1, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
+                u->sink->virtual_volume = u->sink->volume;
+                pa_subscription_post(u->sink->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, u->sink->index);
+            } else {
+                pa_log("mic gain: %d", gain);
+                if (!u->source)
+                    goto done;
+
+                pa_cvolume_set(&u->source->volume, 1, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
+                pa_subscription_post(u->source->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, u->source->index);
+            }
+        }
+    }
+
+done:
+    dbus_error_free(&err);
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static int sink_get_volume_cb(pa_sink *s) {
+    struct userdata *u = s->userdata;
+    pa_assert(u);
+
+    /* refresh? */
+
+    return 0;
+}
+
+static int source_get_volume_cb(pa_source *s) {
+    struct userdata *u = s->userdata;
+    pa_assert(u);
+
+    /* refresh? */
+
+    return 0;
+}
+
+static int sink_set_volume_cb(pa_sink *s) {
+    DBusError e;
+    DBusMessage *m, *r;
+    DBusMessageIter it, itvar;
+    dbus_uint16_t vol;
+    const char *spkgain = "SpeakerGain";
+    struct userdata *u = s->userdata;
+    pa_assert(u);
+
+    dbus_error_init(&e);
+
+    vol = ((float)pa_cvolume_max(&s->volume) / PA_VOLUME_NORM) * 15;
+    pa_log_debug("set headset volume: %d", vol);
+
+    pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetProperty"));
+    dbus_message_iter_init_append(m, &it);
+    dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &spkgain);
+    dbus_message_iter_open_container(&it, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &itvar);
+    dbus_message_iter_append_basic(&itvar, DBUS_TYPE_UINT16, &vol);
+    dbus_message_iter_close_container(&it, &itvar);
+
+    r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(u->conn), m, -1, &e);
+
+finish:
+    if (m)
+        dbus_message_unref(m);
+    if (r)
+        dbus_message_unref(r);
+
+    dbus_error_free(&e);
+
+    return 0;
+}
+
+static int source_set_volume_cb(pa_source *s) {
+    dbus_uint16_t vol;
+    struct userdata *u = s->userdata;
+    pa_assert(u);
+
+    vol = ((float)pa_cvolume_max(&s->volume) / PA_VOLUME_NORM) * 15;
+
+    pa_log_debug("set headset mic volume: %d (not implemented yet)", vol);
+
+    return 0;
+}
+
 int pa__init(pa_module* m) {
     int e;
     pa_modargs *ma;
@@ -796,8 +941,12 @@ int pa__init(pa_module* m) {
     pa_sink_new_data data;
     struct pollfd *pollfd;
     struct userdata *u;
+    DBusError err;
+    char *tmp;
 
     pa_assert(m);
+    dbus_error_init(&err);
+
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->module = m;
     u->core = m->core;
@@ -833,6 +982,7 @@ int pa__init(pa_module* m) {
         pa_log_error("Failed to get rate from module arguments");
         goto fail;
     }
+    u->path = pa_xstrdup(pa_modargs_get_value(ma, "path", NULL));
 
     channels = u->ss.channels;
     if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0) {
@@ -910,7 +1060,50 @@ int pa__init(pa_module* m) {
         goto fail;
     }
     pa_sink_put(u->sink);
+    if (!u->path)
+        goto end;
+
+    /* connect to the bus */
+    u->conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &err);
+    if (dbus_error_is_set(&err) || (u->conn == NULL) ) {
+        pa_log("Failed to get D-Bus connection: %s", err.message);
+        goto fail;
+    }
 
+    /* monitor property changes */
+    if (!dbus_connection_add_filter(pa_dbus_connection_get(u->conn), filter_cb, u, NULL)) {
+        pa_log_error("Failed to add filter function");
+        goto fail;
+    }
+
+    if (pa_streq(u->profile, "hsp")) {
+
+        tmp = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged',path='%s'", u->path);
+        dbus_bus_add_match(pa_dbus_connection_get(u->conn), tmp, &err);
+        pa_xfree(tmp);
+        if (dbus_error_is_set(&err)) {
+            pa_log_error("Unable to subscribe to org.bluez.Headset signals: %s: %s", err.name, err.message);
+            goto fail;
+        }
+    } else {
+
+        tmp = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged',path='%s'", u->path);
+        dbus_bus_add_match(pa_dbus_connection_get(u->conn), tmp, &err);
+        pa_xfree(tmp);
+        if (dbus_error_is_set(&err)) {
+            pa_log_error("Unable to subscribe to org.bluez.AudioSink signals: %s: %s", err.name, err.message);
+            goto fail;
+        }
+    }
+
+    u->sink->get_volume = sink_get_volume_cb;
+    u->sink->set_volume = sink_set_volume_cb;
+    if (u->source) {
+        u->source->get_volume = source_get_volume_cb;
+        u->source->set_volume = source_set_volume_cb;
+    }
+
+end:
     pa_modargs_free(ma);
     return 0;
 
@@ -929,6 +1122,31 @@ void pa__done(pa_module *m) {
     if (!(u = m->userdata))
         return;
 
+    if (u->conn) {
+        DBusError error;
+        char *tmp;
+        dbus_error_init(&error);
+
+        if (pa_streq(u->profile, "hsp")) {
+            tmp = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged',path='%s'", u->path);
+            dbus_bus_remove_match(pa_dbus_connection_get(u->conn), tmp, &error);
+            pa_xfree(tmp);
+            dbus_error_free(&error);
+        } else {
+            tmp = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged',path='%s'", u->path);
+            dbus_bus_remove_match(pa_dbus_connection_get(u->conn), tmp, &error);
+            pa_xfree(tmp);
+            dbus_error_free(&error);
+        }
+
+        dbus_connection_remove_filter(pa_dbus_connection_get(u->conn), filter_cb, u);
+
+        pa_dbus_connection_unref(u->conn);
+    }
+
+    if (u->path)
+        pa_xfree(u->path);
+
     if (u->sink)
         pa_sink_unlink(u->sink);
 
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 2fe0937..4f83def 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -342,7 +342,7 @@ static void load_module_for_device(struct userdata *u, struct device *d, const c
     pa_assert(d);
 
     get_device_properties(u, d);
-    args = pa_sprintf_malloc("sink_name=\"%s\" address=\"%s\" profile=\"%s\"", d->name, d->address, profile);
+    args = pa_sprintf_malloc("sink_name=\"%s\" address=\"%s\" profile=\"%s\" path=\"%s\"", d->name, d->address, profile, d->object_path);
     pa_m = pa_module_load(u->module->core, "module-bluetooth-device", args);
     pa_xfree(args);
 
@@ -468,7 +468,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
 
 done:
     dbus_error_free(&err);
-    return DBUS_HANDLER_RESULT_HANDLED;
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
 void pa__done(pa_module* m) {

commit 12db687acf3befe485bfff3700111999c95247fa
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Mon Jan 19 19:58:41 2009 +0200

    bluetooth: cold hsp/a2dp device detection

diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 4f83def..1bc05c0 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -53,6 +53,13 @@ struct uuid {
     PA_LLIST_FIELDS(struct uuid);
 };
 
+struct dbus_pending {
+    char *path;
+    char *profile;
+    DBusPendingCall *pending;
+    PA_LLIST_FIELDS(struct dbus_pending);
+};
+
 struct device {
     char *name;
     char *object_path;
@@ -70,7 +77,9 @@ struct device {
 struct userdata {
     pa_module *module;
     pa_dbus_connection *conn;
+    dbus_int32_t dbus_data_slot;
     PA_LLIST_HEAD(struct device, device_list);
+    PA_LLIST_HEAD(struct dbus_pending, dbus_pending_list);
 };
 
 static struct module *module_new(const char *profile, pa_module *pa_m) {
@@ -118,6 +127,31 @@ static void uuid_free(struct uuid *uuid) {
     pa_xfree(uuid);
 }
 
+static struct dbus_pending *dbus_pending_new(struct userdata *u, DBusPendingCall *pending, const char *path, const char *profile) {
+    struct dbus_pending *node;
+
+    pa_assert(pending);
+
+    node = pa_xnew(struct dbus_pending, 1);
+    node->pending = pending;
+    node->path = pa_xstrdup(path);
+    node->profile = pa_xstrdup(profile);
+    PA_LLIST_INIT(struct dbus_pending, node);
+    dbus_pending_call_set_data(pending, u->dbus_data_slot, node, NULL);
+
+    return node;
+}
+
+static void dbus_pending_free(struct dbus_pending *pending) {
+    pa_assert(pending);
+
+    pa_xfree(pending->path);
+    pa_xfree(pending->profile);
+    dbus_pending_call_cancel(pending->pending);
+    dbus_pending_call_unref(pending->pending);
+    pa_xfree(pending);
+}
+
 static struct device *device_new(const char *object_path) {
     struct device *node;
 
@@ -471,20 +505,266 @@ done:
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
+
+
+static void get_properties_reply(DBusPendingCall *pending, void *user_data) {
+    struct userdata *u;
+    DBusMessage *r;
+    dbus_bool_t connected;
+    DBusMessageIter arg_i, element_i;
+    DBusMessageIter variant_i;
+    struct device *d;
+    struct dbus_pending *p;
+
+    pa_assert(u = user_data);
+
+    r = dbus_pending_call_steal_reply(pending);
+    if (!r)
+        goto end;
+
+    if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
+        pa_log("Error from GetProperties reply: %s", dbus_message_get_error_name(r));
+        goto end;
+    }
+
+    if (!dbus_message_iter_init(r, &arg_i)) {
+        pa_log("%s GetProperties reply has no arguments", p->profile);
+        goto end;
+    }
+
+    if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_ARRAY) {
+        pa_log("%s GetProperties argument is not an array", p->profile);
+        goto end;
+    }
+
+    connected = FALSE;
+    dbus_message_iter_recurse(&arg_i, &element_i);
+    while (dbus_message_iter_get_arg_type(&element_i) != DBUS_TYPE_INVALID) {
+
+        if (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
+            DBusMessageIter dict_i;
+            const char *key;
+
+            dbus_message_iter_recurse(&element_i, &dict_i);
+
+            if (dbus_message_iter_get_arg_type(&dict_i) != DBUS_TYPE_STRING) {
+                pa_log("Property name not a string.");
+                goto end;
+            }
+
+            dbus_message_iter_get_basic(&dict_i, &key);
+
+            if (!dbus_message_iter_next(&dict_i))  {
+                pa_log("Property value missing");
+                goto end;
+            }
+
+            if (dbus_message_iter_get_arg_type(&dict_i) != DBUS_TYPE_VARIANT) {
+                pa_log("Property value not a variant.");
+                goto end;
+            }
+
+            dbus_message_iter_recurse(&dict_i, &variant_i);
+
+            switch (dbus_message_iter_get_arg_type(&variant_i)) {
+
+                case DBUS_TYPE_BOOLEAN: {
+
+                    dbus_bool_t value;
+                    dbus_message_iter_get_basic(&variant_i, &value);
+
+                    if (pa_streq(key, "Connected")) {
+                        connected = value;
+                        goto endloop;
+                    }
+
+                    break;
+                }
+            }
+        }
+
+        if (!dbus_message_iter_next(&element_i))
+            break;
+    }
+
+endloop:
+    if (connected) {
+        p = dbus_pending_call_get_data(pending, u->dbus_data_slot);
+        pa_log_debug("%s: %s connected", p->path, p->profile);
+        d = device_find(u, p->path);
+
+        if (!d) {
+            d = device_new(p->path);
+            PA_LLIST_PREPEND(struct device, u->device_list, d);
+        }
+
+        load_module_for_device(u, d, p->profile);
+    }
+
+    dbus_message_unref(r);
+
+end:
+    p = dbus_pending_call_get_data(pending, u->dbus_data_slot);
+    PA_LLIST_REMOVE(struct dbus_pending, u->dbus_pending_list, p);
+    dbus_pending_free(p);
+}
+
+static void list_devices_reply(DBusPendingCall *pending, void *user_data) {
+    DBusMessage *r, *m;
+    DBusPendingCall *call;
+    DBusError e;
+    char **paths = NULL;
+    int i, num = -1;
+    struct dbus_pending *p;
+    struct userdata *u;
+
+    pa_assert(u = user_data);
+    dbus_error_init(&e);
+
+    r = dbus_pending_call_steal_reply(pending);
+    if (!r) {
+        pa_log("Failed to get ListDevices reply");
+        goto end;
+    }
+
+    if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
+        pa_log("Error from ListDevices reply: %s", dbus_message_get_error_name(r));
+        goto end;
+    }
+
+    if (!dbus_message_get_args(r, &e, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID)) {
+        pa_log("org.bluez.Adapter.ListDevices returned an error: '%s'\n", e.message);
+        dbus_error_free(&e);
+    } else {
+        for (i = 0; i < num; ++i) {
+            pa_assert_se(m = dbus_message_new_method_call("org.bluez", paths[i], "org.bluez.Headset", "GetProperties"));
+            if (dbus_connection_send_with_reply(pa_dbus_connection_get(u->conn), m, &call, -1)) {
+                p = dbus_pending_new(u, call, paths[i], "hsp");
+                PA_LLIST_PREPEND(struct dbus_pending, u->dbus_pending_list, p);
+                dbus_pending_call_set_notify(call, get_properties_reply, u, NULL);
+            } else {
+                pa_log("Failed to send GetProperties");
+            }
+
+            dbus_message_unref(m);
+
+            pa_assert_se(m = dbus_message_new_method_call("org.bluez", paths[i], "org.bluez.AudioSink", "GetProperties"));
+            if (dbus_connection_send_with_reply(pa_dbus_connection_get(u->conn), m, &call, -1)) {
+                p = dbus_pending_new(u, call, paths[i], "a2dp");
+                PA_LLIST_PREPEND(struct dbus_pending, u->dbus_pending_list, p);
+                dbus_pending_call_set_notify(call, get_properties_reply, u, NULL);
+            } else {
+                pa_log("Failed to send GetProperties");
+            }
+
+            dbus_message_unref(m);
+        }
+    }
+
+    if (paths)
+        dbus_free_string_array (paths);
+    dbus_message_unref(r);
+
+end:
+    p = dbus_pending_call_get_data(pending, u->dbus_data_slot);
+    PA_LLIST_REMOVE(struct dbus_pending, u->dbus_pending_list, p);
+    dbus_pending_free(p);
+}
+
+static void list_adapters_reply(DBusPendingCall *pending, void *user_data) {
+    DBusMessage *r, *m;
+    DBusPendingCall *call;
+    DBusError e;
+    char **paths = NULL;
+    int i, num = -1;
+    struct dbus_pending *p;
+    struct userdata *u;
+
+    pa_assert(u = user_data);
+    dbus_error_init(&e);
+
+    r = dbus_pending_call_steal_reply(pending);
+    if (!r) {
+        pa_log("Failed to get ListAdapters reply");
+        goto end;
+    }
+
+    if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
+        pa_log("Error from ListAdapters reply: %s", dbus_message_get_error_name(r));
+        goto end;
+    }
+
+    if (!dbus_message_get_args(r, &e, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID)) {
+        pa_log("org.bluez.Manager.ListAdapters returned an error: '%s'\n", e.message);
+        dbus_error_free(&e);
+    } else {
+        for (i = 0; i < num; ++i) {
+            pa_assert_se(m = dbus_message_new_method_call("org.bluez", paths[i], "org.bluez.Adapter", "ListDevices"));
+            if (dbus_connection_send_with_reply(pa_dbus_connection_get(u->conn), m, &call, -1)) {
+                p = dbus_pending_new(u, call, NULL, NULL);
+                PA_LLIST_PREPEND(struct dbus_pending, u->dbus_pending_list, p);
+                dbus_pending_call_set_notify(call, list_devices_reply, u, NULL);
+            } else {
+                pa_log("Failed to send ListDevices");
+            }
+
+            dbus_message_unref(m);
+        }
+    }
+
+    if (paths)
+        dbus_free_string_array (paths);
+    dbus_message_unref(r);
+
+end:
+    p = dbus_pending_call_get_data(pending, u->dbus_data_slot);
+    PA_LLIST_REMOVE(struct dbus_pending, u->dbus_pending_list, p);
+    dbus_pending_free(p);
+}
+
+static void lookup_devices(struct userdata *u) {
+    DBusMessage *m;
+    DBusPendingCall *call;
+    struct dbus_pending *p;
+
+    pa_assert(u);
+
+    pa_assert_se(m = dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "ListAdapters"));
+    if (dbus_connection_send_with_reply(pa_dbus_connection_get(u->conn), m, &call, -1)) {
+        p = dbus_pending_new(u, call, NULL, NULL);
+        PA_LLIST_PREPEND(struct dbus_pending, u->dbus_pending_list, p);
+        dbus_pending_call_set_notify(call, list_adapters_reply, u, NULL);
+    } else {
+        pa_log("Failed to send ListAdapters");
+    }
+
+    dbus_message_unref(m);
+}
+
 void pa__done(pa_module* m) {
     struct userdata *u;
     struct device *i;
+    struct dbus_pending *p;
 
     pa_assert(m);
 
     if (!(u = m->userdata))
         return;
 
+    while ((p = u->dbus_pending_list)) {
+        PA_LLIST_REMOVE(struct dbus_pending, u->dbus_pending_list, p);
+        dbus_pending_free(p);
+    }
+
     while ((i = u->device_list)) {
         PA_LLIST_REMOVE(struct device, u->device_list, i);
         device_free(i);
     }
 
+    if (u->dbus_data_slot != -1) {
+        dbus_pending_call_free_data_slot(&u->dbus_data_slot);
+    }
+
     if (u->conn) {
         DBusError error;
         dbus_error_init(&error);
@@ -514,8 +794,10 @@ int pa__init(pa_module* m) {
     dbus_error_init(&err);
 
     m->userdata = u = pa_xnew(struct userdata, 1);
+    u->dbus_data_slot = -1;
     u->module = m;
     PA_LLIST_HEAD_INIT(struct device, u->device_list);
+    PA_LLIST_HEAD_INIT(DBusPendingCall, u->dbus_pending_list);
 
     /* connect to the bus */
     u->conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &err);
@@ -524,6 +806,9 @@ int pa__init(pa_module* m) {
         goto fail;
     }
 
+    if (!dbus_pending_call_allocate_data_slot(&u->dbus_data_slot))
+        goto fail;
+
     /* dynamic detection of bluetooth audio devices */
     if (!dbus_connection_add_filter(pa_dbus_connection_get(u->conn), filter_cb, u, NULL)) {
         pa_log_error("Failed to add filter function");
@@ -548,6 +833,8 @@ int pa__init(pa_module* m) {
         goto fail;
     }
 
+    lookup_devices(u);
+
     return 0;
 
 fail:

commit b56e0389d1ddf5dea496bf7c0536e1ce1e49b49e
Merge: a5401a5... 12db687...
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 28 04:22:51 2009 +0100

    Merge commit '12db687acf3befe485bfff3700111999c95247fa'


-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list