[pulseaudio-discuss] [PATCH v0 01/11] card: Support adding profiles dynamically

Tanu Kaskinen tanuk at iki.fi
Mon Oct 22 08:18:58 PDT 2012


On Mon, 2012-10-22 at 10:46 +0200, Mikel Astiz wrote:
> +int pa_card_add_profile(pa_card *c, struct pa_card_profile *profile) {
> +    pa_assert(c);
> +    pa_assert(profile);
> +
> +    if (pa_hashmap_get(c->profiles, profile->name)) {
> +        pa_log_error("Card %s already has profile %s", c->name, profile->name);
> +        return -1;
> +    }
> +
> +    /* take ownership of the profile */
> +    pa_hashmap_put(c->profiles, profile->name, profile);

pa_hashmap_put() will fail if the key already exists in the hashmap, so
the pa_hashmap_get() step is redundant. Also, I can see no situation
where it wouldn't be a programming error to try to add an already
existing profile to a card, so I'd go with an assertion instead of
returning an error on failure.

-- 
Tanu



More information about the pulseaudio-discuss mailing list