[PATCH v2 6/9] device-port: Add "linked" flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/20/2013 07:24 PM, Tanu Kaskinen wrote:
> The flag will be used in the upcoming pa_device_port_update_proplist()
> function.

If the flag's function is to protect against an initial change 
notification, does it really work? init_eld_ctls is called after 
pa_card_new in module-alsa-card.c.

If we need a flag at all, I'd prefer to keep it in the card struct 
rather than the port. That seems cleaner to me.

> ---
>   src/pulsecore/card.c        |   25 ++++++++++++++++++++-----
>   src/pulsecore/device-port.c |   12 ++++++++++++
>   src/pulsecore/device-port.h |    6 ++++++
>   3 files changed, 38 insertions(+), 5 deletions(-)
>
> diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
> index ae81fcb..8ae3567 100644
> --- a/src/pulsecore/card.c
> +++ b/src/pulsecore/card.c
> @@ -229,12 +229,17 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
>       pa_device_init_icon(c->proplist, TRUE);
>       pa_device_init_intended_roles(c->proplist);
>
> +    /* The rest could be separated into pa_card_put(), if a need arises. */
> +
>       pa_assert_se(pa_idxset_put(core->cards, c, &c->index) >= 0);
> +    pa_log_info("Created card %u \"%s\"", c->index, c->name);
>
> -    pa_log_info("Created %u \"%s\"", c->index, c->name);
> -    pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW, c->index);
> +    PA_HASHMAP_FOREACH(port, c->ports, state)
> +        pa_device_port_put(port);
>
> +    pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW, c->index);
>       pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_PUT], c);
> +
>       return c;
>   }
>
> @@ -247,14 +252,24 @@ void pa_card_free(pa_card *c) {
>       core = c->core;
>
>       pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_UNLINK], c);
> +    pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
>
> -    pa_namereg_unregister(core, c->name);
> +    if (c->ports) {
> +        pa_device_port *port;
> +        void *state;
> +
> +        PA_HASHMAP_FOREACH(port, c->ports, state)
> +            pa_device_port_unlink(port);
> +    }
>
>       pa_idxset_remove_by_data(c->core->cards, c, NULL);
>
> -    pa_log_info("Freed %u \"%s\"", c->index, c->name);
> +    /* Everything above could be separated into pa_card_unlink(), if a need
> +     * arises. */
>
> -    pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
> +    pa_namereg_unregister(core, c->name);
> +
> +    pa_log_info("Freeing card %u \"%s\"", c->index, c->name);
>
>       pa_assert(pa_idxset_isempty(c->sinks));
>       pa_idxset_free(c->sinks, NULL);
> diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
> index 3934c9c..ad885d3 100644
> --- a/src/pulsecore/device-port.c
> +++ b/src/pulsecore/device-port.c
> @@ -75,6 +75,18 @@ pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *des
>       return p;
>   }
>
> +void pa_device_port_put(pa_device_port *port) {
> +    pa_assert(port);
> +
> +    port->linked = true;
> +}
> +
> +void pa_device_port_unlink(pa_device_port *port) {
> +    pa_assert(port);
> +
> +    port->linked = false;
> +}
> +
>   void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
>       uint32_t state;
>       pa_core *core;
> diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
> index 673f67f..be7dd4c 100644
> --- a/src/pulsecore/device-port.h
> +++ b/src/pulsecore/device-port.h
> @@ -54,6 +54,8 @@ struct pa_device_port {
>       pa_bool_t is_output:1;
>       int64_t latency_offset;
>
> +    bool linked;
> +
>       /* .. followed by some implementation specific data */
>   };
>
> @@ -62,6 +64,10 @@ struct pa_device_port {
>   pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, size_t extra);
>   void pa_device_port_free(pa_device_port *p);
>
> +/* Called from card.c, nobody else should call these. */
> +void pa_device_port_put(pa_device_port *port);
> +void pa_device_port_unlink(pa_device_port *port);
> +
>   /* The port's available status has changed */
>   void pa_device_port_set_available(pa_device_port *p, pa_available_t available);
>
>



-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux