bluetooth: Use transport state instead of profile states

The transport state also reflects the state of the audio interface. The
state redundancy can thus be minimized by always using the first one,
and avoiding the use of profile-specific states with the exception of
finding out the initial state of a transport.
This commit is contained in:
Mikel Astiz 2012-12-14 15:14:37 +01:00 committed by Tanu Kaskinen
parent 468c67bb62
commit d2bd3aa444
2 changed files with 14 additions and 3 deletions

View file

@ -1087,7 +1087,7 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
return false; return false;
for (i = 0; i < PA_BLUETOOTH_PROFILE_COUNT; i++) for (i = 0; i < PA_BLUETOOTH_PROFILE_COUNT; i++)
if (d->profile_state[i] >= PA_BT_AUDIO_STATE_CONNECTED) if (d->transports[i])
return true; return true;
return false; return false;
@ -1257,6 +1257,7 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
enum profile p; enum profile p;
DBusMessageIter args, props; DBusMessageIter args, props;
DBusMessage *r; DBusMessage *r;
bool old_any_connected;
dbus_message_iter_init(m, &args); dbus_message_iter_init(m, &args);
@ -1330,6 +1331,8 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
goto fail; goto fail;
} }
old_any_connected = pa_bluetooth_device_any_audio_connected(d);
sender = dbus_message_get_sender(m); sender = dbus_message_get_sender(m);
t = transport_new(d, sender, path, p, config, size); t = transport_new(d, sender, path, p, config, size);
@ -1343,6 +1346,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
pa_assert_se(r = dbus_message_new_method_return(m)); pa_assert_se(r = dbus_message_new_method_return(m));
if (old_any_connected != pa_bluetooth_device_any_audio_connected(d))
run_callback(d, FALSE);
return r; return r;
fail: fail:
@ -1368,12 +1374,17 @@ static DBusMessage *endpoint_clear_configuration(DBusConnection *c, DBusMessage
} }
if ((t = pa_hashmap_get(y->transports, path))) { if ((t = pa_hashmap_get(y->transports, path))) {
bool old_any_connected = t->device ? pa_bluetooth_device_any_audio_connected(t->device) : false;
pa_log_debug("Clearing transport %s profile %d", t->path, t->profile); pa_log_debug("Clearing transport %s profile %d", t->path, t->profile);
t->device->transports[t->profile] = NULL; t->device->transports[t->profile] = NULL;
pa_hashmap_remove(y->transports, t->path); pa_hashmap_remove(y->transports, t->path);
t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED; t->state = PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED;
pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t); pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
transport_free(t); transport_free(t);
if (t->device && old_any_connected != pa_bluetooth_device_any_audio_connected(t->device))
run_callback(t->device, FALSE);
} }
pa_assert_se(r = dbus_message_new_method_return(m)); pa_assert_se(r = dbus_message_new_method_return(m));

View file

@ -2094,7 +2094,7 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
if (*d != PROFILE_OFF) { if (*d != PROFILE_OFF) {
const pa_bluetooth_device *device = u->device; const pa_bluetooth_device *device = u->device;
if (device->profile_state[*d] < PA_BT_AUDIO_STATE_CONNECTED) { if (!device->transports[*d]) {
pa_log_warn("Profile not connected, refused to switch profile to %s", new_profile->name); pa_log_warn("Profile not connected, refused to switch profile to %s", new_profile->name);
return -PA_ERR_IO; return -PA_ERR_IO;
} }
@ -2357,7 +2357,7 @@ static int add_card(struct userdata *u) {
d = PA_CARD_PROFILE_DATA(u->card->active_profile); d = PA_CARD_PROFILE_DATA(u->card->active_profile);
if (*d != PROFILE_OFF && (device->profile_state[*d] < PA_BT_AUDIO_STATE_CONNECTED)) { if (*d != PROFILE_OFF && !device->transports[*d]) {
pa_log_warn("Default profile not connected, selecting off profile"); pa_log_warn("Default profile not connected, selecting off profile");
u->card->active_profile = pa_hashmap_get(u->card->profiles, "off"); u->card->active_profile = pa_hashmap_get(u->card->profiles, "off");
u->card->save_profile = FALSE; u->card->save_profile = FALSE;