From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx> Card profiles -specially the ones registered with pa_card_add_profile()- might need to create new ports during the lifetime of the card. --- src/pulsecore/card.c | 25 +++++++++++++++++++++++++ src/pulsecore/card.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c index 79fe41c..25128eb 100644 --- a/src/pulsecore/card.c +++ b/src/pulsecore/card.c @@ -94,6 +94,31 @@ int pa_card_add_profile(pa_card *c, struct pa_card_profile *profile) { return 0; } +int pa_card_add_ports(pa_card *c, pa_hashmap *ports) { + pa_device_port *p; + void *state; + + pa_assert(c); + pa_assert(ports); + + PA_HASHMAP_FOREACH(p, ports, state) + if (pa_hashmap_get(c->ports, p->name)) { + pa_log_error("Card %s already has port %s", c->name, p->name); + return -1; + } + + /* take ownership of the ports */ + PA_HASHMAP_FOREACH(p, ports, state) + pa_hashmap_put(c->ports, p->name, p); + + while ((p = pa_hashmap_steal_first(ports)) != NULL) + pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p); + + pa_device_port_hashmap_free(ports); + + return 0; +} + void pa_card_new_data_set_profile(pa_card_new_data *data, const char *profile) { pa_assert(data); diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h index d181b10..51a8e6b 100644 --- a/src/pulsecore/card.h +++ b/src/pulsecore/card.h @@ -101,6 +101,7 @@ pa_card *pa_card_new(pa_core *c, pa_card_new_data *data); void pa_card_free(pa_card *c); int pa_card_add_profile(pa_card *c, struct pa_card_profile *profile); +int pa_card_add_ports(pa_card *c, pa_hashmap *ports); int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save); -- 1.7.11.7