Pass the profile object instead of the profile name to pa_card_set_profile()

When setting attribute foo, or in this case the card profile, in my
opinion the thing passed to the set_foo() function should be of the
type of foo, not a string identifier that can be used to search for
the actual foo in set_foo().

This is mostly a question of taste, but there's at least some small
benefit from passing the actual object: often the profile object is
already available when calling pa_card_set_profile(), so passing the
card name would cause unnecessary searching when pa_card_set_profile()
needs to look up the profile from the hashmap.
This commit is contained in:
Tanu Kaskinen 2013-11-20 15:42:26 +02:00
parent bee86af3cc
commit ce304d6208
12 changed files with 38 additions and 24 deletions

View file

@ -4666,8 +4666,9 @@ static void command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag,
static void command_set_card_profile(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
uint32_t idx = PA_INVALID_INDEX;
const char *name = NULL, *profile = NULL;
const char *name = NULL, *profile_name = NULL;
pa_card *card = NULL;
pa_card_profile *profile;
int ret;
pa_native_connection_assert_ref(c);
@ -4675,7 +4676,7 @@ static void command_set_card_profile(pa_pdispatch *pd, uint32_t command, uint32_
if (pa_tagstruct_getu32(t, &idx) < 0 ||
pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_gets(t, &profile) < 0 ||
pa_tagstruct_gets(t, &profile_name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
return;
@ -4684,6 +4685,7 @@ static void command_set_card_profile(pa_pdispatch *pd, uint32_t command, uint32_
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, (idx != PA_INVALID_INDEX) ^ (name != NULL), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, profile_name, tag, PA_ERR_INVALID);
if (idx != PA_INVALID_INDEX)
card = pa_idxset_get_by_index(c->protocol->core->cards, idx);
@ -4692,6 +4694,10 @@ static void command_set_card_profile(pa_pdispatch *pd, uint32_t command, uint32_
CHECK_VALIDITY(c->pstream, card, tag, PA_ERR_NOENTITY);
profile = pa_hashmap_get(card->profiles, profile_name);
CHECK_VALIDITY(c->pstream, profile, tag, PA_ERR_NOENTITY);
if ((ret = pa_card_set_profile(card, profile, true)) < 0) {
pa_pstream_send_error(c->pstream, tag, -ret);
return;