The new field makes it easier to check whether any audio profiles are connected. That information is needed by the discovery module for deciding whether a new device module should be loaded. The device module should use this information too to unload itself at the right time, but that's currently not implemented. --- src/modules/bluetooth/bluetooth-util.c | 36 +++++++++++++++++++++ src/modules/bluetooth/bluetooth-util.h | 2 ++ src/modules/bluetooth/module-bluetooth-discover.c | 6 +--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 06b4348..19b44dd 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -133,6 +133,7 @@ static pa_bluetooth_device* device_new(const char *path) { d->audio_source_state = PA_BT_AUDIO_STATE_INVALID; d->headset_state = PA_BT_AUDIO_STATE_INVALID; d->hfgw_state = PA_BT_AUDIO_STATE_INVALID; + d->any_audio_profile_connected = false; for (i = 0; i < PA_BLUETOOTH_DEVICE_HOOK_MAX; i++) pa_hook_init(&d->hooks[i], d); @@ -495,6 +496,26 @@ static pa_bluetooth_device *found_device(pa_bluetooth_discovery *y, const char* return d; } +static void device_update_any_audio_profile_connected(pa_bluetooth_device *d) { + bool old; + + pa_assert(d); + + old = d->any_audio_profile_connected; + d->any_audio_profile_connected = d->audio_sink_state >= PA_BT_AUDIO_STATE_CONNECTED || + d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED || + d->headset_state >= PA_BT_AUDIO_STATE_CONNECTED || + d->hfgw_state >= PA_BT_AUDIO_STATE_CONNECTED; + + if (d->any_audio_profile_connected == old) + return; + + if (d->any_audio_profile_connected) + pa_log_debug("Device %s has now at least one audio profile connected.", d->path); + else + pa_log_debug("Device %s doesn't have any audio profiles connected anymore.", d->path); +} + static void get_properties_reply(DBusPendingCall *pending, void *userdata) { DBusMessage *r; DBusMessageIter arg_i, element_i; @@ -572,18 +593,25 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) { if (parse_audio_property(y, &d->headset_state, &dict_i) < 0) goto finish; + device_update_any_audio_profile_connected(d); + } else if (dbus_message_has_interface(p->message, "org.bluez.AudioSink")) { if (parse_audio_property(y, &d->audio_sink_state, &dict_i) < 0) goto finish; + device_update_any_audio_profile_connected(d); + } else if (dbus_message_has_interface(p->message, "org.bluez.AudioSource")) { if (parse_audio_property(y, &d->audio_source_state, &dict_i) < 0) goto finish; + device_update_any_audio_profile_connected(d); + } else if (dbus_message_has_interface(p->message, "org.bluez.HandsfreeGateway")) { if (parse_audio_property(y, &d->hfgw_state, &dict_i) < 0) goto finish; + device_update_any_audio_profile_connected(d); } } @@ -840,17 +868,25 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us if (parse_audio_property(y, &d->headset_state, &arg_i) < 0) goto fail; + device_update_any_audio_profile_connected(d); + } else if (dbus_message_has_interface(m, "org.bluez.AudioSink")) { if (parse_audio_property(y, &d->audio_sink_state, &arg_i) < 0) goto fail; + device_update_any_audio_profile_connected(d); + } else if (dbus_message_has_interface(m, "org.bluez.AudioSource")) { if (parse_audio_property(y, &d->audio_source_state, &arg_i) < 0) goto fail; + device_update_any_audio_profile_connected(d); + } else if (dbus_message_has_interface(m, "org.bluez.HandsfreeGateway")) { if (parse_audio_property(y, &d->hfgw_state, &arg_i) < 0) goto fail; + + device_update_any_audio_profile_connected(d); } run_callback(y, d, FALSE); diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h index 3846498..41cb890 100644 --- a/src/modules/bluetooth/bluetooth-util.h +++ b/src/modules/bluetooth/bluetooth-util.h @@ -126,6 +126,8 @@ struct pa_bluetooth_device { /* HandsfreeGateway state */ pa_bt_audio_state_t hfgw_state; + bool any_audio_profile_connected; + pa_hook hooks[PA_BLUETOOTH_DEVICE_HOOK_MAX]; }; diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c index 8d64834..58335e2 100644 --- a/src/modules/bluetooth/module-bluetooth-discover.c +++ b/src/modules/bluetooth/module-bluetooth-discover.c @@ -74,11 +74,7 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const mi = pa_hashmap_get(u->hashmap, d->path); - if (!d->dead && - (d->audio_sink_state >= PA_BT_AUDIO_STATE_CONNECTED || - d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED || - d->headset_state >= PA_BT_AUDIO_STATE_CONNECTED || - d->hfgw_state >= PA_BT_AUDIO_STATE_CONNECTED)) { + if (!d->dead && d->any_audio_profile_connected) { if (!mi) { pa_module *m = NULL; -- 1.7.10.4