[RFC,1/4] card: New API pa_card_profile_has_available_ports

Submitted by João Paulo Rechi Vita on Aug. 8, 2018, 5 a.m.

Details

Message ID 20180808050052.32327-2-jprvita@endlessm.com
State New
Headers show
Series "Audio routing fixes and improvements" ( rev: 1 ) in PulseAudio

Not browsing as part of any series.

Commit Message

João Paulo Rechi Vita Aug. 8, 2018, 5 a.m.
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(+)

Patch hide | download patch | download mbox

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) {
+    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);

Comments

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);
On Wed, Oct 3, 2018 at 2:36 AM Tanu Kaskinen <tanuk@iki.fi> wrote:
>
> 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.
>

Agreed, I'm going to resubmit this as a gitlab MR (which IIUC is now
the preferred way for patch submissions and CR).

Thanks,

--
João Paulo Rechi Vita
http://about.me/jprvita