mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
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:
parent
c2c8475f0d
commit
37429cb07e
11 changed files with 34 additions and 20 deletions
|
|
@ -250,23 +250,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;
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ void pa_card_free(pa_card *c);
|
|||
|
||||
void pa_card_add_profile(pa_card *c, pa_card_profile *profile);
|
||||
|
||||
int pa_card_set_profile(pa_card *c, const char *name, bool save);
|
||||
int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save);
|
||||
|
||||
int pa_card_suspend(pa_card *c, bool suspend, pa_suspend_cause_t cause);
|
||||
|
||||
|
|
|
|||
|
|
@ -1634,6 +1634,7 @@ static int pa_cli_command_log_backtrace(pa_core *c, pa_tokenizer *t, pa_strbuf *
|
|||
static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail) {
|
||||
const char *n, *p;
|
||||
pa_card *card;
|
||||
pa_card_profile *profile;
|
||||
|
||||
pa_core_assert_ref(c);
|
||||
pa_assert(t);
|
||||
|
|
@ -1655,7 +1656,12 @@ static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *b
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pa_card_set_profile(card, p, true) < 0) {
|
||||
if (!(profile = pa_hashmap_get(card->profiles, p))) {
|
||||
pa_strbuf_printf(buf, "No such profile: %s\n", p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pa_card_set_profile(card, profile, true) < 0) {
|
||||
pa_strbuf_printf(buf, "Failed to set card profile to '%s'.\n", p);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4702,8 +4702,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);
|
||||
|
|
@ -4711,7 +4712,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;
|
||||
|
|
@ -4722,6 +4723,7 @@ static void command_set_card_profile(pa_pdispatch *pd, uint32_t command, uint32_
|
|||
CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
|
||||
CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
|
||||
CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, 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);
|
||||
|
|
@ -4730,6 +4732,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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue