bluetooth: Move device hooks into pa_bluetooth_hook_t

Centralize the Bluetooth hooks in one single place, starting with
the device hooks, while removing the duplicated ones (in this case
PA_BLUETOOTH_DEVICE_HOOK_REMOVED).
This commit is contained in:
Mikel Astiz 2012-12-06 15:55:28 +01:00 committed by Tanu Kaskinen
parent e425fd61b8
commit 689f9413ad
3 changed files with 22 additions and 25 deletions

View file

@ -112,7 +112,6 @@ static void uuid_free(pa_bluetooth_uuid *u) {
static pa_bluetooth_device* device_new(pa_bluetooth_discovery *discovery, const char *path) {
pa_bluetooth_device *d;
unsigned i;
pa_assert(discovery);
pa_assert(path);
@ -139,9 +138,6 @@ static pa_bluetooth_device* device_new(pa_bluetooth_discovery *discovery, const
d->headset_state = PA_BT_AUDIO_STATE_INVALID;
d->hfgw_state = PA_BT_AUDIO_STATE_INVALID;
for (i = 0; i < PA_BLUETOOTH_DEVICE_HOOK_MAX; i++)
pa_hook_init(&d->hooks[i], d);
return d;
}
@ -176,9 +172,6 @@ static void device_free(pa_bluetooth_device *d) {
transport_free(t);
}
for (i = 0; i < PA_BLUETOOTH_DEVICE_HOOK_MAX; i++)
pa_hook_done(&d->hooks[i]);
while ((u = d->uuids)) {
PA_LLIST_REMOVE(pa_bluetooth_uuid, d->uuids, u);
uuid_free(u);
@ -385,6 +378,7 @@ static int parse_device_property(pa_bluetooth_device *d, DBusMessageIter *i) {
while (dbus_message_iter_get_arg_type(&ai) != DBUS_TYPE_INVALID) {
pa_bluetooth_uuid *node;
const char *value;
struct pa_bluetooth_hook_uuid_data uuiddata;
dbus_message_iter_get_basic(&ai, &value);
@ -396,7 +390,9 @@ static int parse_device_property(pa_bluetooth_device *d, DBusMessageIter *i) {
node = uuid_new(value);
PA_LLIST_PREPEND(pa_bluetooth_uuid, d->uuids, node);
pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_UUID_ADDED], (char *) value);
uuiddata.device = d;
uuiddata.uuid = value;
pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_DEVICE_UUID_ADDED], &uuiddata);
/* Vudentz said the interfaces are here when the UUIDs are announced */
if (strcasecmp(HSP_AG_UUID, value) == 0 || strcasecmp(HFP_AG_UUID, value) == 0) {
@ -484,7 +480,6 @@ static void remove_all_devices(pa_bluetooth_discovery *y) {
pa_assert(y);
while ((d = pa_hashmap_steal_first(y->devices))) {
pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
run_callback(d, TRUE);
device_free(d);
}
@ -808,7 +803,6 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
pa_log_debug("Device %s removed", path);
if ((d = pa_hashmap_remove(y->devices, path))) {
pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
run_callback(d, TRUE);
device_free(d);
}

View file

@ -65,9 +65,15 @@ enum profile {
#define PA_BLUETOOTH_PROFILE_COUNT PROFILE_OFF
struct pa_bluetooth_hook_uuid_data {
pa_bluetooth_device *device;
const char *uuid;
};
/* Hook data: pa_bluetooth_discovery pointer. */
typedef enum pa_bluetooth_hook {
PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
PA_BLUETOOTH_HOOK_DEVICE_UUID_ADDED, /* Call data: pa_bluetooth_hook_uuid_data */
PA_BLUETOOTH_HOOK_MAX
} pa_bluetooth_hook_t;
@ -100,13 +106,6 @@ typedef enum pa_bt_audio_state {
PA_BT_AUDIO_STATE_PLAYING
} pa_bt_audio_state_t;
/* Hook data: pa_bluetooth_device pointer. */
typedef enum pa_bluetooth_device_hook {
PA_BLUETOOTH_DEVICE_HOOK_REMOVED, /* Call data: NULL. */
PA_BLUETOOTH_DEVICE_HOOK_UUID_ADDED, /* Call data: const char *uuid. */
PA_BLUETOOTH_DEVICE_HOOK_MAX
} pa_bluetooth_device_hook_t;
struct pa_bluetooth_device {
pa_bluetooth_discovery *discovery;
pa_bool_t dead;
@ -138,8 +137,6 @@ struct pa_bluetooth_device {
/* HandsfreeGateway state */
pa_bt_audio_state_t hfgw_state;
pa_hook hooks[PA_BLUETOOTH_DEVICE_HOOK_MAX];
};
pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);

View file

@ -2522,15 +2522,20 @@ static pa_bluetooth_device* find_device(struct userdata *u, const char *address,
}
/* Run from main thread */
static pa_hook_result_t uuid_added_cb(pa_bluetooth_device *d, const char *uuid, struct userdata *u) {
static pa_hook_result_t uuid_added_cb(pa_bluetooth_discovery *y, const struct pa_bluetooth_hook_uuid_data *data,
struct userdata *u) {
pa_card_profile *p;
pa_hashmap *new_ports;
pa_assert(d);
pa_assert(uuid);
pa_assert(data);
pa_assert(data->device);
pa_assert(data->uuid);
pa_assert(u);
p = create_card_profile(u, uuid);
if (data->device != u->device)
return PA_HOOK_OK;
p = create_card_profile(u, data->uuid);
if (!p)
return PA_HOOK_OK;
@ -2666,8 +2671,9 @@ int pa__init(pa_module* m) {
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
PA_HOOK_NORMAL, (pa_hook_cb_t) discovery_hook_cb, u);
u->uuid_added_slot = pa_hook_connect(&device->hooks[PA_BLUETOOTH_DEVICE_HOOK_UUID_ADDED], PA_HOOK_NORMAL,
(pa_hook_cb_t) uuid_added_cb, u);
u->uuid_added_slot =
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_UUID_ADDED),
PA_HOOK_NORMAL, (pa_hook_cb_t) uuid_added_cb, u);
/* Add the card structure. This will also initialize the default profile */
if (add_card(u) < 0)