On Tue, 2018-08-07 at 22:00 -0700, João Paulo Rechi Vita wrote: > New function to check if a card has any ports with a certain > availability for a specific direction. > > This was built uppon previous work by Mario Sanchez Prada. > --- > src/pulsecore/card.c | 18 ++++++++++++++++++ > src/pulsecore/card.h | 3 +++ > 2 files changed, 21 insertions(+) > > diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c > index c785f00a7..a3c732341 100644 > --- a/src/pulsecore/card.c > +++ b/src/pulsecore/card.c > @@ -79,6 +79,24 @@ void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available) > pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED], c); > } > > +bool pa_card_profile_has_available_ports(pa_card_profile *c, pa_direction_t direction, pa_available_t available) { I think pa_card_profile_has_ports_with_availability() would be a better name, because the function can return false even if the profile has available ports, which is confusing with the current name. Nitpicking: I'd prefer "cp" (or "profile") as the card profile variable name, because I associate "c" with pa_card, so reading "c->name" caused slight confusion for me. > + pa_card *card; > + pa_device_port *port; > + void *state; > + > + pa_assert(c); > + > + card = c->card; > + pa_assert(card); > + > + PA_HASHMAP_FOREACH(port, card->ports, state) { > + if (pa_hashmap_get(port->profiles, c->name) && port->direction == direction && port->available == available) > + return true; > + } > + > + return false; > +} > + > pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) { > pa_assert(data); > > diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h > index 09284f6ff..50f106c5e 100644 > --- a/src/pulsecore/card.h > +++ b/src/pulsecore/card.h > @@ -119,6 +119,9 @@ void pa_card_profile_free(pa_card_profile *c); > /* The profile's available status has changed */ > void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available); > > +/* Check if card has any ports with a certain availability for a specific direction */ > +bool pa_card_profile_has_available_ports(pa_card_profile *c, pa_direction_t direction, pa_available_t available); > + > pa_card_new_data *pa_card_new_data_init(pa_card_new_data *data); > void pa_card_new_data_set_name(pa_card_new_data *data, const char *name); > void pa_card_new_data_set_preferred_port(pa_card_new_data *data, pa_direction_t direction, pa_device_port *port); -- Tanu https://www.patreon.com/tanuk https://liberapay.com/tanuk _______________________________________________ pulseaudio-discuss mailing list pulseaudio-discuss@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss