[pulseaudio-commits] src/modules

Tanu Kaskinen tanuk at kemper.freedesktop.org
Wed Jul 25 22:31:32 PDT 2012


 src/modules/bluetooth/bluetooth-util.c |   60 ++++++++++++---------------------
 1 file changed, 22 insertions(+), 38 deletions(-)

New commits:
commit 8a402a7d080ffff3ba4abaf5ded212e93022bfa3
Author: Mikel Astiz <mikel.astiz at bmw-carit.de>
Date:   Wed Jul 25 16:29:52 2012 +0200

    bluetooth: Refactor property parsing code
    
    Use a separate method to perform the common checks when a property needs
    to be parsed.

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index cc3b8c6..778eecb 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -184,31 +184,42 @@ static pa_bool_t device_is_audio(pa_bluetooth_device *d) {
           d->headset_state != PA_BT_AUDIO_STATE_INVALID)));
 }
 
-static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device *d, DBusMessageIter *i) {
+static const char *check_variant_property(DBusMessageIter *i) {
     const char *key;
-    DBusMessageIter variant_i;
 
-    pa_assert(y);
-    pa_assert(d);
     pa_assert(i);
 
     if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING) {
         pa_log("Property name not a string.");
-        return -1;
+        return NULL;
     }
 
     dbus_message_iter_get_basic(i, &key);
 
     if (!dbus_message_iter_next(i)) {
         pa_log("Property value missing");
-        return -1;
+        return NULL;
     }
 
     if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_VARIANT) {
         pa_log("Property value not a variant.");
-        return -1;
+        return NULL;
     }
 
+    return key;
+}
+
+static int parse_device_property(pa_bluetooth_discovery *y, pa_bluetooth_device *d, DBusMessageIter *i) {
+    const char *key;
+    DBusMessageIter variant_i;
+
+    pa_assert(y);
+    pa_assert(d);
+
+    key = check_variant_property(i);
+    if (key == NULL)
+        return -1;
+
     dbus_message_iter_recurse(i, &variant_i);
 
 /*     pa_log_debug("Parsing property org.bluez.Device.%s", key); */
@@ -327,24 +338,10 @@ static int parse_audio_property(pa_bluetooth_discovery *u, int *state, DBusMessa
 
     pa_assert(u);
     pa_assert(state);
-    pa_assert(i);
 
-    if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING) {
-        pa_log("Property name not a string.");
+    key = check_variant_property(i);
+    if (key == NULL)
         return -1;
-    }
-
-    dbus_message_iter_get_basic(i, &key);
-
-    if (!dbus_message_iter_next(i)) {
-        pa_log("Property value missing");
-        return -1;
-    }
-
-    if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_VARIANT) {
-        pa_log("Property value not a variant.");
-        return -1;
-    }
 
     dbus_message_iter_recurse(i, &variant_i);
 
@@ -735,22 +732,9 @@ int pa_bluetooth_transport_parse_property(pa_bluetooth_transport *t, DBusMessage
     const char *key;
     DBusMessageIter variant_i;
 
-    if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING) {
-        pa_log("Property name not a string.");
+    key = check_variant_property(i);
+    if (key == NULL)
         return -1;
-    }
-
-    dbus_message_iter_get_basic(i, &key);
-
-    if (!dbus_message_iter_next(i))  {
-        pa_log("Property value missing");
-        return -1;
-    }
-
-    if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_VARIANT) {
-        pa_log("Property value not a variant.");
-        return -1;
-    }
 
     dbus_message_iter_recurse(i, &variant_i);
 



More information about the pulseaudio-commits mailing list