static pa_bluetooth_device* device_new(const char *path) {
pa_bluetooth_device *d;
+ unsigned i;
d = pa_xnew(pa_bluetooth_device, 1);
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;
}
static void device_free(pa_bluetooth_device *d) {
pa_bluetooth_uuid *u;
pa_bluetooth_transport *t;
+ unsigned i;
pa_assert(d);
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)) {
PA_LLIST_REMOVE(pa_bluetooth_uuid, d->uuids, u);
uuid_free(u);
pa_assert(y);
while ((d = pa_hashmap_steal_first(y->devices))) {
+ pa_hook_fire(&d->hooks[PA_BLUETOOTH_DEVICE_HOOK_REMOVED], NULL);
run_callback(y, d, TRUE);
device_free(d);
}
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(y, d, TRUE);
device_free(d);
}
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_MAX
+} pa_bluetooth_device_hook_t;
+
struct pa_bluetooth_device {
pa_bool_t dead;
/* 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);