diff options
author | Mikel Astiz <mikel.astiz@bmw-carit.de> | 2012-08-31 12:50:56 +0200 |
---|---|---|
committer | Jaska Uimonen <jaska.uimonen@intel.com> | 2013-01-24 09:29:36 +0200 |
commit | 360852731ce0290ee657e13d7fa9ae0602f083d9 (patch) | |
tree | c132cabfe0d9222d0b41c9af031e527bb7d6961a | |
parent | df365d7b6e9c50f78c584ba6feaaab3dc61d9517 (diff) | |
download | pulseaudio-panda-360852731ce0290ee657e13d7fa9ae0602f083d9.tar.gz pulseaudio-panda-360852731ce0290ee657e13d7fa9ae0602f083d9.tar.bz2 pulseaudio-panda-360852731ce0290ee657e13d7fa9ae0602f083d9.zip |
bluetooth: Refactor parsing of signal PropertyChanged
Wrap the code parsing the PropertyChanged signal into a helper function
that will return the new state of the interface.
-rw-r--r-- | src/modules/bluetooth/module-bluetooth-device.c | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 1502b9f4..7b4164d2 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -1128,6 +1128,52 @@ finish: pa_log_debug("IO thread shutting down"); } +static pa_bt_audio_state_t parse_state_property_change(DBusMessage *m) { + DBusMessageIter iter; + DBusMessageIter variant; + const char *key; + const char *value; + pa_bt_audio_state_t state; + + if (!dbus_message_iter_init(m, &iter)) { + pa_log("Failed to parse PropertyChanged"); + return PA_BT_AUDIO_STATE_INVALID; + } + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { + pa_log("Property name not a string"); + return PA_BT_AUDIO_STATE_INVALID; + } + + dbus_message_iter_get_basic(&iter, &key); + + if (!pa_streq(key, "State")) + return PA_BT_AUDIO_STATE_INVALID; + + if (!dbus_message_iter_next(&iter)) { + pa_log("Property value missing"); + return PA_BT_AUDIO_STATE_INVALID; + } + + dbus_message_iter_recurse(&iter, &variant); + + if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_STRING) { + pa_log("Property value not a string"); + return PA_BT_AUDIO_STATE_INVALID; + } + + dbus_message_iter_get_basic(&variant, &value); + + pa_log_debug("dbus: %s property 'State' changed to value '%s'", dbus_message_get_interface(m), value); + + state = pa_bt_audio_state_from_string(value); + + if (state == PA_BT_AUDIO_STATE_INVALID) + pa_log("Unexpected value for property 'State': '%s'", value); + + return state; +} + /* Run from main thread */ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *userdata) { DBusError err; @@ -1181,39 +1227,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us } } } else if (dbus_message_is_signal(m, "org.bluez.HandsfreeGateway", "PropertyChanged")) { - const char *key; - DBusMessageIter iter; - DBusMessageIter variant; - pa_bt_audio_state_t state = PA_BT_AUDIO_STATE_INVALID; - - if (!dbus_message_iter_init(m, &iter)) { - pa_log("Failed to parse PropertyChanged: %s", err.message); - goto fail; - } - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { - pa_log("Property name not a string."); - goto fail; - } - - dbus_message_iter_get_basic(&iter, &key); - - if (!dbus_message_iter_next(&iter)) { - pa_log("Property value missing"); - goto fail; - } - - dbus_message_iter_recurse(&iter, &variant); - - if (dbus_message_iter_get_arg_type(&variant) == DBUS_TYPE_STRING) { - const char *value; - dbus_message_iter_get_basic(&variant, &value); - - if (pa_streq(key, "State")) { - pa_log_debug("dbus: HSHFAG property 'State' changed to value '%s'", value); - state = pa_bt_audio_state_from_string(value); - } - } + pa_bt_audio_state_t state = parse_state_property_change(m); switch(state) { case PA_BT_AUDIO_STATE_INVALID: |