[pulseaudio-discuss] [PATCH next v0 05/11] bluetooth: Refactor parse_audio_property() to support more properties

Tanu Kaskinen tanuk at iki.fi
Fri Dec 7 17:40:56 PST 2012


On Thu, 2012-12-06 at 15:55 +0100, Mikel Astiz wrote:
> @@ -475,8 +475,20 @@ static int parse_audio_property(pa_bluetooth_discovery *u, int *state, DBusMessa
>              dbus_message_iter_get_basic(&variant_i, &value);
>  
>              if (pa_streq(key, "State")) {
> -                *state = pa_bt_audio_state_from_string(value);
> +                pa_bt_audio_state_t state = pa_bt_audio_state_from_string(value);
> +
>                  pa_log_debug("dbus: property 'State' changed to value '%s'", value);
> +
> +                if (state == PA_BT_AUDIO_STATE_INVALID)
> +                    return -1;
> +
> +                /* A hackish p == PROFILE_OFF is used to represent org.bluez.Audio */
> +                if (p == PROFILE_OFF) {
> +                    d->audio_state = state;
> +                    break;
> +                }

I don't like this hack. See below for a suggestion for an alternative
solution.

> +
> +                d->profile_state[p] = state;
>              }
>  
>              break;
> @@ -609,16 +621,13 @@ static void get_properties_reply(DBusPendingCall *pending, void *userdata) {
>                      goto finish;
>  
>              } else if (dbus_message_has_interface(p->message, "org.bluez.Audio")) {
> -                if (parse_audio_property(y, &d->audio_state, &dict_i) < 0)
> +                if (parse_audio_property(d, PROFILE_OFF, &dict_i) < 0)
>                      goto finish;
>  
>              } else if (pa_bt_audio_profile_from_interface(dbus_message_get_interface(p->message), &profile)) {
> -                pa_bt_audio_state_t state;
> -
> -                if (parse_audio_property(y, &state, &dict_i) < 0)
> +                if (parse_audio_property(d, profile, &dict_i) < 0)
>                      goto finish;
>  
> -                d->profile_state[profile] = state;
>              }
>          }

We could have an enum for all BlueZ interfaces (or just for the audio
interfaces, but I think it's cleaner to cover all interfaces).
get_properties_reply() could then convert the interface string to an
enum value, and pass that value instead of a profile to
parse_audio_property().

Alternatively, the interface enum could be avoided by passing the
interface string to parse_audio_property(), but that would result in
more string comparisons.

-- 
Tanu



More information about the pulseaudio-discuss mailing list