2008-07-17 16:29:49 -03:00
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2008 Joao Paulo Rechi Vita
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
***/
|
|
|
|
|
|
2008-07-31 16:17:03 -03:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2008-07-17 16:29:49 -03:00
|
|
|
#include <config.h>
|
2008-07-31 16:17:03 -03:00
|
|
|
#endif
|
2008-07-17 16:29:49 -03:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <pulse/xmalloc.h>
|
|
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
2008-07-22 10:37:34 -03:00
|
|
|
#include <pulsecore/macro.h>
|
2008-07-23 11:12:57 -03:00
|
|
|
#include <pulsecore/llist.h>
|
2008-09-29 21:45:00 +02:00
|
|
|
#include <pulsecore/core-util.h>
|
2008-07-17 16:29:49 -03:00
|
|
|
|
2008-10-06 03:35:46 +02:00
|
|
|
#include "../dbus-util.h"
|
2008-08-29 20:22:14 -03:00
|
|
|
#include "module-bluetooth-discover-symdef.h"
|
2008-07-17 16:29:49 -03:00
|
|
|
|
|
|
|
|
PA_MODULE_AUTHOR("Joao Paulo Rechi Vita");
|
|
|
|
|
PA_MODULE_DESCRIPTION("Detect available bluetooth audio devices and load bluetooth audio drivers");
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
|
|
|
|
PA_MODULE_USAGE("");
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
struct module {
|
|
|
|
|
char *profile;
|
2008-12-17 21:19:53 +01:00
|
|
|
uint32_t index;
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_FIELDS(struct module);
|
|
|
|
|
};
|
2008-07-17 16:29:49 -03:00
|
|
|
|
|
|
|
|
struct uuid {
|
|
|
|
|
char *uuid;
|
2008-07-23 11:12:57 -03:00
|
|
|
PA_LLIST_FIELDS(struct uuid);
|
2008-07-17 16:29:49 -03:00
|
|
|
};
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
struct dbus_pending {
|
|
|
|
|
char *path;
|
|
|
|
|
char *profile;
|
|
|
|
|
DBusPendingCall *pending;
|
|
|
|
|
PA_LLIST_FIELDS(struct dbus_pending);
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
struct device {
|
|
|
|
|
char *name;
|
|
|
|
|
char *object_path;
|
|
|
|
|
int paired;
|
|
|
|
|
char *alias;
|
|
|
|
|
int connected;
|
2008-07-23 11:12:57 -03:00
|
|
|
PA_LLIST_HEAD(struct uuid, uuid_list);
|
2008-07-17 16:29:49 -03:00
|
|
|
char *address;
|
|
|
|
|
int class;
|
|
|
|
|
int trusted;
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_HEAD(struct module, module_list);
|
2008-07-23 11:12:57 -03:00
|
|
|
PA_LLIST_FIELDS(struct device);
|
2008-07-17 16:29:49 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct userdata {
|
|
|
|
|
pa_module *module;
|
|
|
|
|
pa_dbus_connection *conn;
|
2009-01-19 19:58:41 +02:00
|
|
|
dbus_int32_t dbus_data_slot;
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_HEAD(struct device, device_list);
|
2009-01-19 19:58:41 +02:00
|
|
|
PA_LLIST_HEAD(struct dbus_pending, dbus_pending_list);
|
2008-07-17 16:29:49 -03:00
|
|
|
};
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
static struct module *module_new(const char *profile, pa_module *pa_m) {
|
|
|
|
|
struct module *m;
|
|
|
|
|
|
|
|
|
|
m = pa_xnew(struct module, 1);
|
|
|
|
|
m->profile = pa_xstrdup(profile);
|
2008-12-17 21:19:53 +01:00
|
|
|
m->index = pa_m->index;
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_INIT(struct module, m);
|
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void module_free(struct module *m) {
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
pa_xfree(m->profile);
|
|
|
|
|
pa_xfree(m);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-06 14:59:15 -03:00
|
|
|
static struct module* module_find(struct device *d, const char *profile) {
|
|
|
|
|
struct module *m;
|
|
|
|
|
|
2008-12-05 15:47:37 -03:00
|
|
|
for (m = d->module_list; m; m = m->next)
|
2008-10-06 14:59:15 -03:00
|
|
|
if (pa_streq(m->profile, profile))
|
|
|
|
|
return m;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 11:12:57 -03:00
|
|
|
static struct uuid *uuid_new(const char *uuid) {
|
2008-09-29 21:45:00 +02:00
|
|
|
struct uuid *node;
|
|
|
|
|
|
|
|
|
|
node = pa_xnew(struct uuid, 1);
|
2008-07-17 16:29:49 -03:00
|
|
|
node->uuid = pa_xstrdup(uuid);
|
2008-07-23 11:12:57 -03:00
|
|
|
PA_LLIST_INIT(struct uuid, node);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 11:12:57 -03:00
|
|
|
static void uuid_free(struct uuid *uuid) {
|
2008-09-29 21:45:00 +02:00
|
|
|
pa_assert(uuid);
|
|
|
|
|
|
|
|
|
|
pa_xfree(uuid->uuid);
|
2008-07-23 11:12:57 -03:00
|
|
|
pa_xfree(uuid);
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
static struct device *device_new(const char *object_path) {
|
2008-09-29 21:45:00 +02:00
|
|
|
struct device *node;
|
|
|
|
|
|
|
|
|
|
node = pa_xnew(struct device, 1);
|
2008-07-17 16:29:49 -03:00
|
|
|
node->name = NULL;
|
2008-09-29 21:45:00 +02:00
|
|
|
node->object_path = pa_xstrdup(object_path);
|
2008-07-17 16:29:49 -03:00
|
|
|
node->paired = -1;
|
|
|
|
|
node->alias = NULL;
|
|
|
|
|
node->connected = -1;
|
2008-07-23 11:12:57 -03:00
|
|
|
PA_LLIST_HEAD_INIT(struct uuid, node->uuid_list);
|
2008-07-17 16:29:49 -03:00
|
|
|
node->address = NULL;
|
|
|
|
|
node->class = -1;
|
|
|
|
|
node->trusted = -1;
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_HEAD_INIT(struct module, node->module_list);
|
2008-07-23 11:12:57 -03:00
|
|
|
PA_LLIST_INIT(struct device, node);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 11:12:57 -03:00
|
|
|
static void device_free(struct device *device) {
|
2008-10-01 20:15:09 -03:00
|
|
|
struct module *m;
|
2008-09-29 21:45:00 +02:00
|
|
|
struct uuid *i;
|
|
|
|
|
|
|
|
|
|
pa_assert(device);
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
while ((m = device->module_list)) {
|
|
|
|
|
PA_LLIST_REMOVE(struct module, device->module_list, m);
|
|
|
|
|
module_free(m);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-29 21:45:00 +02:00
|
|
|
while ((i = device->uuid_list)) {
|
|
|
|
|
PA_LLIST_REMOVE(struct uuid, device->uuid_list, i);
|
|
|
|
|
uuid_free(i);
|
2008-07-23 11:12:57 -03:00
|
|
|
}
|
2008-09-29 21:45:00 +02:00
|
|
|
|
|
|
|
|
pa_xfree(device->name);
|
|
|
|
|
pa_xfree(device->object_path);
|
|
|
|
|
pa_xfree(device->alias);
|
|
|
|
|
pa_xfree(device->address);
|
2008-07-23 11:12:57 -03:00
|
|
|
pa_xfree(device);
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
static struct device* device_find(struct userdata *u, const char *path) {
|
2008-09-29 21:45:00 +02:00
|
|
|
struct device *i;
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
for (i = u->device_list; i; i = i->next)
|
2008-09-29 21:45:00 +02:00
|
|
|
if (pa_streq(i->object_path, path))
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 01:16:43 +02:00
|
|
|
static int parse_device_property(struct userdata *u, struct device *d, DBusMessageIter *i) {
|
|
|
|
|
const char *key;
|
|
|
|
|
DBusMessageIter variant_i;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(d);
|
|
|
|
|
pa_assert(i);
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING) {
|
|
|
|
|
pa_log("Property name not a string.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(i, &key);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_next(i)) {
|
|
|
|
|
pa_log("Property value missing");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_VARIANT) {
|
|
|
|
|
pa_log("Property value not a variant.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(i, &variant_i);
|
|
|
|
|
|
|
|
|
|
pa_log_debug("Parsing device property %s", key);
|
|
|
|
|
|
|
|
|
|
switch (dbus_message_iter_get_arg_type(&variant_i)) {
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_STRING: {
|
|
|
|
|
|
|
|
|
|
const char *value;
|
|
|
|
|
dbus_message_iter_get_basic(&variant_i, &value);
|
|
|
|
|
|
|
|
|
|
if (pa_streq(key, "Name")) {
|
|
|
|
|
pa_xfree(d->name);
|
|
|
|
|
d->name = pa_xstrdup(value);
|
|
|
|
|
} else if (pa_streq(key, "Alias")) {
|
|
|
|
|
pa_xfree(d->alias);
|
|
|
|
|
d->alias = pa_xstrdup(value);
|
|
|
|
|
} else if (pa_streq(key, "Address")) {
|
|
|
|
|
pa_xfree(d->address);
|
|
|
|
|
d->address = pa_xstrdup(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_BOOLEAN: {
|
|
|
|
|
|
|
|
|
|
dbus_bool_t value;
|
|
|
|
|
dbus_message_iter_get_basic(&variant_i, &value);
|
|
|
|
|
|
|
|
|
|
if (pa_streq(key, "Paired"))
|
|
|
|
|
d->paired = !!value;
|
|
|
|
|
else if (pa_streq(key, "Connected"))
|
|
|
|
|
d->connected = !!value;
|
|
|
|
|
else if (pa_streq(key, "Trusted"))
|
|
|
|
|
d->trusted = !!value;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_UINT32: {
|
|
|
|
|
|
|
|
|
|
uint32_t value;
|
|
|
|
|
dbus_message_iter_get_basic(&variant_i, &value);
|
|
|
|
|
|
|
|
|
|
if (pa_streq(key, "Class"))
|
|
|
|
|
d->class = (int) value;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_ARRAY: {
|
|
|
|
|
|
|
|
|
|
DBusMessageIter ai;
|
|
|
|
|
dbus_message_iter_recurse(&variant_i, &ai);
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&ai) == DBUS_TYPE_STRING &&
|
|
|
|
|
pa_streq(key, "UUIDs")) {
|
|
|
|
|
|
|
|
|
|
while (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_INVALID) {
|
|
|
|
|
struct uuid *node;
|
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&ai, &value);
|
|
|
|
|
node = uuid_new(value);
|
|
|
|
|
PA_LLIST_PREPEND(struct uuid, d->uuid_list, node);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_next(&ai))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-29 21:45:00 +02:00
|
|
|
static int get_device_properties(struct userdata *u, struct device *d) {
|
|
|
|
|
DBusError e;
|
|
|
|
|
DBusMessage *m = NULL, *r = NULL;
|
2008-10-01 01:16:43 +02:00
|
|
|
DBusMessageIter arg_i, element_i;
|
2008-09-29 21:45:00 +02:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(d);
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&e);
|
|
|
|
|
|
|
|
|
|
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->object_path, "org.bluez.Device", "GetProperties"));
|
|
|
|
|
|
|
|
|
|
r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(u->conn), m, -1, &e);
|
|
|
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
|
pa_log("org.bluez.Device.GetProperties failed: %s", e.message);
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_init(r, &arg_i)) {
|
|
|
|
|
pa_log("org.bluez.Device.GetProperties reply has no arguments");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_ARRAY) {
|
|
|
|
|
pa_log("org.bluez.Device.GetProperties argument is not an array");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&arg_i, &element_i);
|
|
|
|
|
while (dbus_message_iter_get_arg_type(&element_i) != DBUS_TYPE_INVALID) {
|
2008-10-01 01:16:43 +02:00
|
|
|
|
2008-09-29 21:45:00 +02:00
|
|
|
if (dbus_message_iter_get_arg_type(&element_i) == DBUS_TYPE_DICT_ENTRY) {
|
2008-10-01 01:16:43 +02:00
|
|
|
DBusMessageIter dict_i;
|
2008-09-29 21:45:00 +02:00
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&element_i, &dict_i);
|
|
|
|
|
|
2008-10-01 01:16:43 +02:00
|
|
|
if (parse_device_property(u, d, &dict_i) < 0)
|
|
|
|
|
goto finish;
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
2008-09-29 21:45:00 +02:00
|
|
|
|
|
|
|
|
if (!dbus_message_iter_next(&element_i))
|
|
|
|
|
break;
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
2008-07-22 10:07:30 -03:00
|
|
|
|
2008-09-29 21:45:00 +02:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
|
|
finish:
|
2008-07-22 10:07:30 -03:00
|
|
|
if (m)
|
|
|
|
|
dbus_message_unref(m);
|
|
|
|
|
if (r)
|
|
|
|
|
dbus_message_unref(r);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-07-22 10:07:30 -03:00
|
|
|
dbus_error_free(&e);
|
2008-10-01 01:16:43 +02:00
|
|
|
|
2008-09-29 21:45:00 +02:00
|
|
|
return ret;
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
static void load_module_for_device(struct userdata *u, struct device *d, const char *profile) {
|
|
|
|
|
char *args;
|
|
|
|
|
pa_module *pa_m;
|
|
|
|
|
struct module *m;
|
2008-07-17 16:29:49 -03:00
|
|
|
|
2008-07-22 10:07:30 -03:00
|
|
|
pa_assert(u);
|
2008-10-01 20:15:09 -03:00
|
|
|
pa_assert(d);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
get_device_properties(u, d);
|
2009-01-19 14:53:35 +02:00
|
|
|
args = pa_sprintf_malloc("sink_name=\"%s\" address=\"%s\" profile=\"%s\" path=\"%s\"", d->name, d->address, profile, d->object_path);
|
2008-10-01 20:15:09 -03:00
|
|
|
pa_m = pa_module_load(u->module->core, "module-bluetooth-device", args);
|
|
|
|
|
pa_xfree(args);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-10-09 19:31:43 -03:00
|
|
|
if (!pa_m) {
|
2008-10-01 20:15:09 -03:00
|
|
|
pa_log_debug("Failed to load module for device %s", d->object_path);
|
|
|
|
|
return;
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
m = module_new(profile, pa_m);
|
|
|
|
|
PA_LLIST_PREPEND(struct module, d->module_list, m);
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
|
|
|
|
|
2008-10-06 14:59:15 -03:00
|
|
|
static void unload_module_for_device(struct userdata *u, struct device *d, const char *profile) {
|
|
|
|
|
struct module *m;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(d);
|
|
|
|
|
|
|
|
|
|
if (!(m = module_find(d, profile)))
|
|
|
|
|
return;
|
|
|
|
|
|
2008-12-17 21:19:53 +01:00
|
|
|
pa_module_unload_request_by_index(u->module->core, m->index, TRUE);
|
2008-10-06 14:59:15 -03:00
|
|
|
|
|
|
|
|
PA_LLIST_REMOVE(struct module, d->module_list, m);
|
|
|
|
|
module_free(m);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-21 09:42:29 -03:00
|
|
|
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;
|
2008-10-01 01:16:43 +02:00
|
|
|
|
2008-07-21 09:42:29 -03:00
|
|
|
dbus_error_init(&err);
|
|
|
|
|
|
2008-09-11 01:40:18 +03:00
|
|
|
pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
|
2008-07-21 09:42:29 -03:00
|
|
|
dbus_message_get_interface(msg),
|
|
|
|
|
dbus_message_get_path(msg),
|
|
|
|
|
dbus_message_get_member(msg));
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
if (dbus_message_is_signal(msg, "org.bluez.Adapter", "DeviceRemoved")) {
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-07-21 09:42:29 -03:00
|
|
|
if (!dbus_message_iter_init(msg, &arg_i))
|
|
|
|
|
pa_log("dbus: message has no parameters");
|
|
|
|
|
else if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_OBJECT_PATH)
|
|
|
|
|
pa_log("dbus: argument is not object path");
|
|
|
|
|
else {
|
2008-09-29 21:45:00 +02:00
|
|
|
struct device *d;
|
|
|
|
|
|
2008-07-21 09:42:29 -03:00
|
|
|
dbus_message_iter_get_basic(&arg_i, &value);
|
2008-09-29 21:45:00 +02:00
|
|
|
pa_log_debug("hcid: device %s removed", value);
|
|
|
|
|
|
2008-10-01 01:16:43 +02:00
|
|
|
if ((d = device_find(u, value))) {
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_REMOVE(struct device, u->device_list, d);
|
2008-09-29 21:45:00 +02:00
|
|
|
device_free(d);
|
|
|
|
|
}
|
2008-07-21 09:42:29 -03:00
|
|
|
}
|
2008-10-01 01:16:43 +02:00
|
|
|
|
2008-10-03 12:15:26 -03:00
|
|
|
} else if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged") ||
|
|
|
|
|
dbus_message_is_signal(msg, "org.bluez.AudioSink", "PropertyChanged")) {
|
2008-10-01 11:35:51 -03:00
|
|
|
|
2008-10-01 12:16:16 -03:00
|
|
|
struct device *d;
|
2008-10-01 20:15:09 -03:00
|
|
|
const char *profile;
|
2008-10-03 12:15:26 -03:00
|
|
|
DBusMessageIter variant_i;
|
2008-10-06 14:59:15 -03:00
|
|
|
dbus_bool_t connected;
|
2008-10-03 12:15:26 -03:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2008-10-06 14:59:15 -03:00
|
|
|
if (!pa_streq(value, "Connected"))
|
|
|
|
|
goto done;
|
|
|
|
|
|
2008-10-03 12:15:26 -03:00
|
|
|
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);
|
|
|
|
|
|
2008-10-06 14:59:15 -03:00
|
|
|
if (dbus_message_iter_get_arg_type(&variant_i) != DBUS_TYPE_BOOLEAN) {
|
|
|
|
|
pa_log("Property value not a boolean.");
|
|
|
|
|
goto done;
|
2008-10-03 12:15:26 -03:00
|
|
|
}
|
2008-10-01 20:15:09 -03:00
|
|
|
|
2008-10-06 14:59:15 -03:00
|
|
|
dbus_message_iter_get_basic(&variant_i, &connected);
|
2008-10-01 20:15:09 -03:00
|
|
|
|
2008-10-03 12:15:26 -03:00
|
|
|
if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged"))
|
2008-10-01 20:15:09 -03:00
|
|
|
profile = "hsp";
|
|
|
|
|
else
|
|
|
|
|
profile = "a2dp";
|
2008-10-01 11:35:51 -03:00
|
|
|
|
2008-10-06 14:59:15 -03:00
|
|
|
d = device_find(u, dbus_message_get_path(msg));
|
|
|
|
|
|
|
|
|
|
if (connected) {
|
|
|
|
|
if (!d) {
|
|
|
|
|
d = device_new(dbus_message_get_path(msg));
|
|
|
|
|
PA_LLIST_PREPEND(struct device, u->device_list, d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
load_module_for_device(u, d, profile);
|
|
|
|
|
} else if (d)
|
|
|
|
|
unload_module_for_device(u, d, profile);
|
2008-07-21 09:42:29 -03:00
|
|
|
}
|
|
|
|
|
|
2008-10-03 12:15:26 -03:00
|
|
|
done:
|
2008-07-21 09:42:29 -03:00
|
|
|
dbus_error_free(&err);
|
2009-01-19 14:53:35 +02:00
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
2008-07-21 09:42:29 -03:00
|
|
|
}
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
void pa__done(pa_module* m) {
|
|
|
|
|
struct userdata *u;
|
2008-10-01 20:15:09 -03:00
|
|
|
struct device *i;
|
2009-01-19 19:58:41 +02:00
|
|
|
struct dbus_pending *p;
|
2008-07-17 16:29:49 -03:00
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
while ((p = u->dbus_pending_list)) {
|
|
|
|
|
PA_LLIST_REMOVE(struct dbus_pending, u->dbus_pending_list, p);
|
|
|
|
|
dbus_pending_free(p);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
while ((i = u->device_list)) {
|
|
|
|
|
PA_LLIST_REMOVE(struct device, u->device_list, i);
|
|
|
|
|
device_free(i);
|
2008-07-17 16:29:49 -03:00
|
|
|
}
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
if (u->dbus_data_slot != -1) {
|
|
|
|
|
dbus_pending_call_free_data_slot(&u->dbus_data_slot);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 19:52:02 +02:00
|
|
|
if (u->conn) {
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
dbus_bus_remove_match(pa_dbus_connection_get(u->conn), "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'", &error);
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
|
|
dbus_bus_remove_match(pa_dbus_connection_get(u->conn), "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'", &error);
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
|
|
dbus_bus_remove_match(pa_dbus_connection_get(u->conn), "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", &error);
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
|
|
dbus_connection_remove_filter(pa_dbus_connection_get(u->conn), filter_cb, u);
|
|
|
|
|
|
2008-09-29 21:45:00 +02:00
|
|
|
pa_dbus_connection_unref(u->conn);
|
2008-10-13 19:52:02 +02:00
|
|
|
}
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
pa_xfree(u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa__init(pa_module* m) {
|
|
|
|
|
DBusError err;
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
2008-07-23 11:12:57 -03:00
|
|
|
dbus_error_init(&err);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
|
|
|
|
m->userdata = u = pa_xnew(struct userdata, 1);
|
2009-01-19 19:58:41 +02:00
|
|
|
u->dbus_data_slot = -1;
|
2008-07-17 16:29:49 -03:00
|
|
|
u->module = m;
|
2008-10-01 20:15:09 -03:00
|
|
|
PA_LLIST_HEAD_INIT(struct device, u->device_list);
|
2009-01-19 19:58:41 +02:00
|
|
|
PA_LLIST_HEAD_INIT(DBusPendingCall, u->dbus_pending_list);
|
2008-07-17 16:29:49 -03:00
|
|
|
|
|
|
|
|
/* connect to the bus */
|
|
|
|
|
u->conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &err);
|
2008-09-29 21:45:00 +02:00
|
|
|
if (dbus_error_is_set(&err) || (u->conn == NULL) ) {
|
2008-07-17 16:29:49 -03:00
|
|
|
pa_log("Failed to get D-Bus connection: %s", err.message);
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
if (!dbus_pending_call_allocate_data_slot(&u->dbus_data_slot))
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2008-07-21 09:42:29 -03:00
|
|
|
/* 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");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-10-01 20:15:09 -03:00
|
|
|
dbus_bus_add_match(pa_dbus_connection_get(u->conn), "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'", &err);
|
2008-07-21 09:42:29 -03:00
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
|
pa_log_error("Unable to subscribe to org.bluez.Adapter signals: %s: %s", err.name, err.message);
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-03 12:15:26 -03:00
|
|
|
dbus_bus_add_match(pa_dbus_connection_get(u->conn), "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'", &err);
|
2008-10-01 11:29:50 -03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-03 12:15:26 -03:00
|
|
|
dbus_bus_add_match(pa_dbus_connection_get(u->conn), "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", &err);
|
2008-10-01 11:29:50 -03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 19:58:41 +02:00
|
|
|
lookup_devices(u);
|
|
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
dbus_error_free(&err);
|
|
|
|
|
pa__done(m);
|
2008-09-29 21:45:00 +02:00
|
|
|
|
2008-07-17 16:29:49 -03:00
|
|
|
return -1;
|
|
|
|
|
}
|