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

@ -226,3 +226,9 @@ const char *pa_dbusiface_card_profile_get_name(pa_dbusiface_card_profile *p) {
return p->profile->name;
}
pa_card_profile *pa_dbusiface_card_profile_get_profile(pa_dbusiface_card_profile *p) {
pa_assert(p);
return p->profile;
}

View file

@ -45,5 +45,6 @@ void pa_dbusiface_card_profile_free(pa_dbusiface_card_profile *p);
const char *pa_dbusiface_card_profile_get_path(pa_dbusiface_card_profile *p);
const char *pa_dbusiface_card_profile_get_name(pa_dbusiface_card_profile *p);
pa_card_profile *pa_dbusiface_card_profile_get_profile(pa_dbusiface_card_profile *p);
#endif

View file

@ -336,7 +336,7 @@ static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, DB
return;
}
if ((r = pa_card_set_profile(c->card, pa_dbusiface_card_profile_get_name(new_active), true)) < 0) {
if ((r = pa_card_set_profile(c->card, pa_dbusiface_card_profile_get_profile(new_active), true)) < 0) {
pa_dbus_send_error(conn, msg, DBUS_ERROR_FAILED,
"Internal error in PulseAudio: pa_card_set_profile() failed with error code %i.", r);
return;