bluetooth: Move profile_to_string() to bluetooth-util

Move the function to the utility library where the enum is defined. At
same time avoid using the default clause in order to make sure the
compiler will complain if the enum type gets extended.
This commit is contained in:
Mikel Astiz 2012-12-14 15:14:31 +01:00 committed by Tanu Kaskinen
parent d6d6770a04
commit f5a4626ffb
3 changed files with 22 additions and 19 deletions

View file

@ -93,6 +93,23 @@ pa_bt_audio_state_t pa_bt_audio_state_from_string(const char* value) {
return PA_BT_AUDIO_STATE_INVALID; return PA_BT_AUDIO_STATE_INVALID;
} }
const char *pa_bt_profile_to_string(enum profile profile) {
switch(profile) {
case PROFILE_A2DP:
return "a2dp";
case PROFILE_A2DP_SOURCE:
return "a2dp_source";
case PROFILE_HSP:
return "hsp";
case PROFILE_HFGW:
return "hfgw";
case PROFILE_OFF:
pa_assert_not_reached();
}
pa_assert_not_reached();
}
static int profile_from_interface(const char *interface, enum profile *p) { static int profile_from_interface(const char *interface, enum profile *p) {
pa_assert(interface); pa_assert(interface);
pa_assert(p); pa_assert(p);

View file

@ -162,5 +162,6 @@ char *pa_bluetooth_cleanup_name(const char *name);
pa_bool_t pa_bluetooth_uuid_has(pa_bluetooth_uuid *uuids, const char *uuid); pa_bool_t pa_bluetooth_uuid_has(pa_bluetooth_uuid *uuids, const char *uuid);
pa_bt_audio_state_t pa_bt_audio_state_from_string(const char* value); pa_bt_audio_state_t pa_bt_audio_state_from_string(const char* value);
const char *pa_bt_profile_to_string(enum profile profile);
#endif #endif

View file

@ -1654,21 +1654,6 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_
} }
} }
static const char *profile_to_string(enum profile profile) {
switch(profile) {
case PROFILE_A2DP:
return "a2dp";
case PROFILE_A2DP_SOURCE:
return "a2dp_source";
case PROFILE_HSP:
return "hsp";
case PROFILE_HFGW:
return "hfgw";
default:
pa_assert_not_reached();
}
}
static int sink_set_port_cb(pa_sink *s, pa_device_port *p) { static int sink_set_port_cb(pa_sink *s, pa_device_port *p) {
return 0; return 0;
} }
@ -1688,7 +1673,7 @@ static int add_sink(struct userdata *u) {
u->sink = u->hsp.sco_sink; u->sink = u->hsp.sco_sink;
p = pa_proplist_new(); p = pa_proplist_new();
pa_proplist_sets(p, "bluetooth.protocol", profile_to_string(u->profile)); pa_proplist_sets(p, "bluetooth.protocol", pa_bt_profile_to_string(u->profile));
pa_proplist_update(u->sink->proplist, PA_UPDATE_MERGE, p); pa_proplist_update(u->sink->proplist, PA_UPDATE_MERGE, p);
pa_proplist_free(p); pa_proplist_free(p);
} else { } else {
@ -1699,7 +1684,7 @@ static int add_sink(struct userdata *u) {
data.driver = __FILE__; data.driver = __FILE__;
data.module = u->module; data.module = u->module;
pa_sink_new_data_set_sample_spec(&data, &u->sample_spec); pa_sink_new_data_set_sample_spec(&data, &u->sample_spec);
pa_proplist_sets(data.proplist, "bluetooth.protocol", profile_to_string(u->profile)); pa_proplist_sets(data.proplist, "bluetooth.protocol", pa_bt_profile_to_string(u->profile));
if (u->profile == PROFILE_HSP) if (u->profile == PROFILE_HSP)
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone"); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone");
data.card = u->card; data.card = u->card;
@ -1760,7 +1745,7 @@ static int add_source(struct userdata *u) {
if (USE_SCO_OVER_PCM(u)) { if (USE_SCO_OVER_PCM(u)) {
u->source = u->hsp.sco_source; u->source = u->hsp.sco_source;
pa_proplist_sets(u->source->proplist, "bluetooth.protocol", profile_to_string(u->profile)); pa_proplist_sets(u->source->proplist, "bluetooth.protocol", pa_bt_profile_to_string(u->profile));
} else { } else {
pa_source_new_data data; pa_source_new_data data;
pa_bool_t b; pa_bool_t b;
@ -1769,7 +1754,7 @@ static int add_source(struct userdata *u) {
data.driver = __FILE__; data.driver = __FILE__;
data.module = u->module; data.module = u->module;
pa_source_new_data_set_sample_spec(&data, &u->sample_spec); pa_source_new_data_set_sample_spec(&data, &u->sample_spec);
pa_proplist_sets(data.proplist, "bluetooth.protocol", profile_to_string(u->profile)); pa_proplist_sets(data.proplist, "bluetooth.protocol", pa_bt_profile_to_string(u->profile));
if (u->profile == PROFILE_HSP) if (u->profile == PROFILE_HSP)
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone"); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone");