]> code.delx.au - pulseaudio/commitdiff
bluetooth: Remove device_is_audio_ready()
authorMikel Astiz <mikel.astiz@bmw-carit.de>
Fri, 11 Jan 2013 10:07:48 +0000 (11:07 +0100)
committerTanu Kaskinen <tanuk@iki.fi>
Fri, 11 Jan 2013 19:51:10 +0000 (21:51 +0200)
The function was used to check whether the basic properties of the
Bluetooth device have been received. This can be simplified by just
checking d->device_info_valid, since the state of the audio interface
is only relevant inside pa_bluetooth_device_any_audio_connected(), which
is used to trigger the discovery callback.

While checking device_info_valid, special care must be taken with all
three possible values: when set to -1, it means some error was triggered
while getting the device properties. Therefore, these devices can also
be ignored outside bluetooth-util.

Besides that, the patch slightly modifies the behavior of the internal
API affecting pa_bluetooth_discovery_get_by_address() and
pa_bluetooth_discovery_get_by_path(), since they will return the device
no matter the state of the audio interface. This however makes sense and
should have no influence in the current codebase given that the modules
make use of devices only after the discovery hook has been triggered.

src/modules/bluetooth/bluetooth-util.c

index 149a476953ff108c1b03d1703fe4cf74ed833b12..48e12da8f45235fd5fb3549959773f6eea770a1d 100644 (file)
@@ -234,15 +234,6 @@ static void device_free(pa_bluetooth_device *d) {
     pa_xfree(d);
 }
 
-static pa_bool_t device_is_audio_ready(const pa_bluetooth_device *d) {
-    pa_assert(d);
-
-    if (!d->device_info_valid || d->audio_state == PA_BT_AUDIO_STATE_INVALID)
-        return false;
-
-    return true;
-}
-
 static const char *check_variant_property(DBusMessageIter *i) {
     const char *key;
 
@@ -611,7 +602,7 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D
 static void run_callback(pa_bluetooth_device *d, pa_bool_t dead) {
     pa_assert(d);
 
-    if (!device_is_audio_ready(d))
+    if (d->device_info_valid != 1)
         return;
 
     d->dead = dead;
@@ -1054,7 +1045,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_discover
 
     while ((d = pa_hashmap_iterate(y->devices, &state, NULL)))
         if (pa_streq(d->address, address))
-            return device_is_audio_ready(d) ? d : NULL;
+            return d->device_info_valid == 1 ? d : NULL;
 
     return NULL;
 }
@@ -1067,7 +1058,7 @@ pa_bluetooth_device* pa_bluetooth_discovery_get_by_path(pa_bluetooth_discovery *
     pa_assert(path);
 
     if ((d = pa_hashmap_get(y->devices, path)))
-        if (device_is_audio_ready(d))
+        if (d->device_info_valid == 1)
             return d;
 
     return NULL;
@@ -1078,7 +1069,10 @@ bool pa_bluetooth_device_any_audio_connected(const pa_bluetooth_device *d) {
 
     pa_assert(d);
 
-    if (d->dead || !device_is_audio_ready(d))
+    if (d->dead || d->device_info_valid != 1)
+        return false;
+
+    if (d->audio_state == PA_BT_AUDIO_STATE_INVALID)
         return false;
 
     /* Make sure audio_state is *not* in CONNECTING state before we fire the