bluetooth: Refactor code to helper function
authorMikel Astiz <mikel.astiz@bmw-carit.de>
Fri, 31 Aug 2012 10:50:55 +0000 (12:50 +0200)
committerJaska Uimonen <jaska.uimonen@intel.com>
Thu, 24 Jan 2013 07:29:36 +0000 (09:29 +0200)
Make code more readable by introducing the helper function
bt_transport_is_acquired(). This also adds assertions to check whether
the internal state is consistent.

src/modules/bluetooth/module-bluetooth-device.c

index 7b4164d..115416d 100644 (file)
@@ -279,12 +279,22 @@ static void setup_stream(struct userdata *u) {
                 TRUE);
 }
 
+static bool bt_transport_is_acquired(struct userdata *u) {
+    if (u->accesstype == NULL) {
+        pa_assert(u->stream_fd < 0);
+        return FALSE;
+    } else {
+        pa_assert(u->stream_fd >= 0);
+        return TRUE;
+    }
+}
+
 static void bt_transport_release(struct userdata *u) {
     const char *accesstype = "rw";
     const pa_bluetooth_transport *t;
 
     /* Ignore if already released */
-    if (!u->accesstype)
+    if (!bt_transport_is_acquired(u))
         return;
 
     pa_log_debug("Releasing transport %s", u->transport);
@@ -316,7 +326,7 @@ static int bt_transport_acquire(struct userdata *u, pa_bool_t start) {
     const char *accesstype = "rw";
     const pa_bluetooth_transport *t;
 
-    if (u->accesstype) {
+    if (bt_transport_is_acquired(u)) {
         if (start)
             goto done;
         return 0;