mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
bluetooth: Add hook to tell device was removed
Add a hook to report that the device was removed, and thus references to it should be released.
This commit is contained in:
parent
24c1892a1f
commit
97bdeaaacd
2 changed files with 18 additions and 0 deletions
|
|
@ -111,6 +111,7 @@ static void uuid_free(pa_bluetooth_uuid *u) {
|
||||||
|
|
||||||
static pa_bluetooth_device* device_new(const char *path) {
|
static pa_bluetooth_device* device_new(const char *path) {
|
||||||
pa_bluetooth_device *d;
|
pa_bluetooth_device *d;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
d = pa_xnew(pa_bluetooth_device, 1);
|
d = pa_xnew(pa_bluetooth_device, 1);
|
||||||
|
|
||||||
|
|
@ -135,6 +136,9 @@ static pa_bluetooth_device* device_new(const char *path) {
|
||||||
d->headset_state = PA_BT_AUDIO_STATE_INVALID;
|
d->headset_state = PA_BT_AUDIO_STATE_INVALID;
|
||||||
d->hfgw_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;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,6 +158,7 @@ static void transport_free(pa_bluetooth_transport *t) {
|
||||||
static void device_free(pa_bluetooth_device *d) {
|
static void device_free(pa_bluetooth_device *d) {
|
||||||
pa_bluetooth_uuid *u;
|
pa_bluetooth_uuid *u;
|
||||||
pa_bluetooth_transport *t;
|
pa_bluetooth_transport *t;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
pa_assert(d);
|
pa_assert(d);
|
||||||
|
|
||||||
|
|
@ -164,6 +169,9 @@ static void device_free(pa_bluetooth_device *d) {
|
||||||
|
|
||||||
pa_hashmap_free(d->transports, NULL, NULL);
|
pa_hashmap_free(d->transports, NULL, NULL);
|
||||||
|
|
||||||
|
for (i = 0; i < PA_BLUETOOTH_DEVICE_HOOK_MAX; i++)
|
||||||
|
pa_hook_done(&d->hooks[i]);
|
||||||
|
|
||||||
while ((u = d->uuids)) {
|
while ((u = d->uuids)) {
|
||||||
PA_LLIST_REMOVE(pa_bluetooth_uuid, d->uuids, u);
|
PA_LLIST_REMOVE(pa_bluetooth_uuid, d->uuids, u);
|
||||||
uuid_free(u);
|
uuid_free(u);
|
||||||
|
|
@ -465,6 +473,7 @@ static void remove_all_devices(pa_bluetooth_discovery *y) {
|
||||||
pa_assert(y);
|
pa_assert(y);
|
||||||
|
|
||||||
while ((d = pa_hashmap_steal_first(y->devices))) {
|
while ((d = pa_hashmap_steal_first(y->devices))) {
|
||||||
|
pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
|
||||||
run_callback(y, d, TRUE);
|
run_callback(y, d, TRUE);
|
||||||
device_free(d);
|
device_free(d);
|
||||||
}
|
}
|
||||||
|
|
@ -785,6 +794,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
|
||||||
pa_log_debug("Device %s removed", path);
|
pa_log_debug("Device %s removed", path);
|
||||||
|
|
||||||
if ((d = pa_hashmap_remove(y->devices, path))) {
|
if ((d = pa_hashmap_remove(y->devices, path))) {
|
||||||
|
pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
|
||||||
run_callback(y, d, TRUE);
|
run_callback(y, d, TRUE);
|
||||||
device_free(d);
|
device_free(d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,12 @@ typedef enum pa_bt_audio_state {
|
||||||
PA_BT_AUDIO_STATE_PLAYING
|
PA_BT_AUDIO_STATE_PLAYING
|
||||||
} pa_bt_audio_state_t;
|
} 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_MAX
|
||||||
|
} pa_bluetooth_device_hook_t;
|
||||||
|
|
||||||
struct pa_bluetooth_device {
|
struct pa_bluetooth_device {
|
||||||
pa_bool_t dead;
|
pa_bool_t dead;
|
||||||
|
|
||||||
|
|
@ -122,6 +128,8 @@ struct pa_bluetooth_device {
|
||||||
|
|
||||||
/* HandsfreeGateway state */
|
/* HandsfreeGateway state */
|
||||||
pa_bt_audio_state_t hfgw_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);
|
pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue