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

@ -261,23 +261,18 @@ void pa_card_free(pa_card *c) {
pa_xfree(c);
}
int pa_card_set_profile(pa_card *c, const char *name, bool save) {
pa_card_profile *profile;
int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save) {
int r;
pa_assert(c);
pa_assert(profile);
pa_assert(profile->card == c);
if (!c->set_profile) {
pa_log_debug("set_profile() operation not implemented for card %u \"%s\"", c->index, c->name);
return -PA_ERR_NOTIMPLEMENTED;
}
if (!name)
return -PA_ERR_NOENTITY;
if (!(profile = pa_hashmap_get(c->profiles, name)))
return -PA_ERR_NOENTITY;
if (c->active_profile == profile) {
c->save_profile = c->save_profile || save;
return 0;