mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
conf: introduce snd_config_get_card() function
It's helper for the "card" entries parsing. It reduces the code in most of open_hw functions. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
b9a4997e92
commit
19ad9bdc49
9 changed files with 59 additions and 83 deletions
|
|
@ -187,6 +187,7 @@ snd_config_t *snd_config_iterator_entry(const snd_config_iterator_t iterator);
|
||||||
|
|
||||||
int snd_config_get_bool_ascii(const char *ascii);
|
int snd_config_get_bool_ascii(const char *ascii);
|
||||||
int snd_config_get_bool(const snd_config_t *conf);
|
int snd_config_get_bool(const snd_config_t *conf);
|
||||||
|
int snd_config_get_card(const snd_config_t *conf);
|
||||||
int snd_config_get_ctl_iface_ascii(const char *ascii);
|
int snd_config_get_ctl_iface_ascii(const char *ascii);
|
||||||
int snd_config_get_ctl_iface(const snd_config_t *conf);
|
int snd_config_get_ctl_iface(const snd_config_t *conf);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -142,6 +143,35 @@ int snd_config_get_bool(const snd_config_t *conf)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Gets the card number from a configuration node.
|
||||||
|
* \param conf Handle to the configuration node to be parsed.
|
||||||
|
* \return The card number if successful, otherwise a negative error code.
|
||||||
|
*/
|
||||||
|
int snd_config_get_card(const snd_config_t *conf)
|
||||||
|
{
|
||||||
|
const char *str, *id;
|
||||||
|
long v;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if ((err = snd_config_get_integer(conf, &v)) < 0) {
|
||||||
|
if ((err = snd_config_get_string(conf, &str)) < 0) {
|
||||||
|
snd_config_get_id(conf, &id);
|
||||||
|
SNDERR("Invalid field %s", id);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
err = snd_card_get_index(str);
|
||||||
|
if (err < 0) {
|
||||||
|
SNDERR("Cannot get card index for %s", str);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
v = err;
|
||||||
|
}
|
||||||
|
if (v < 0 || v > INT_MAX)
|
||||||
|
return -EINVAL;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Gets the control interface index from the given ASCII string.
|
* \brief Gets the control interface index from the given ASCII string.
|
||||||
* \param ascii The string to be parsed.
|
* \param ascii The string to be parsed.
|
||||||
|
|
|
||||||
|
|
@ -441,7 +441,6 @@ int _snd_ctl_hw_open(snd_ctl_t **handlep, char *name, snd_config_t *root ATTRIBU
|
||||||
{
|
{
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
long card = -1;
|
long card = -1;
|
||||||
const char *str;
|
|
||||||
int err;
|
int err;
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
|
|
@ -451,15 +450,10 @@ int _snd_ctl_hw_open(snd_ctl_t **handlep, char *name, snd_config_t *root ATTRIBU
|
||||||
if (_snd_conf_generic_id(id))
|
if (_snd_conf_generic_id(id))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
err = snd_config_get_integer(n, &card);
|
err = snd_config_get_card(n);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
err = snd_config_get_string(n, &str);
|
return err;
|
||||||
if (err < 0)
|
card = err;
|
||||||
return -EINVAL;
|
|
||||||
card = snd_card_get_index(str);
|
|
||||||
if (card < 0)
|
|
||||||
return card;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,6 @@ int _snd_hwdep_hw_open(snd_hwdep_t **hwdep, char *name,
|
||||||
{
|
{
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
long card = -1, device = 0;
|
long card = -1, device = 0;
|
||||||
const char *str;
|
|
||||||
int err;
|
int err;
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
|
|
@ -161,15 +160,10 @@ int _snd_hwdep_hw_open(snd_hwdep_t **hwdep, char *name,
|
||||||
if (_snd_conf_generic_id(id))
|
if (_snd_conf_generic_id(id))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
err = snd_config_get_integer(n, &card);
|
err = snd_config_get_card(n);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
err = snd_config_get_string(n, &str);
|
return err;
|
||||||
if (err < 0)
|
card = err;
|
||||||
return -EINVAL;
|
|
||||||
card = snd_card_get_index(str);
|
|
||||||
if (card < 0)
|
|
||||||
return card;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "device") == 0) {
|
if (strcmp(id, "device") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -1834,19 +1834,10 @@ static int _snd_pcm_direct_get_slave_ipc_offset(snd_config_t *root,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
err = snd_config_get_integer(n, &card);
|
err = snd_config_get_card(n);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
err = snd_config_get_string(n, &str);
|
return err;
|
||||||
if (err < 0) {
|
card = err;
|
||||||
SNDERR("Invalid type for %s", id);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
card = snd_card_get_index(str);
|
|
||||||
if (card < 0) {
|
|
||||||
SNDERR("Invalid value for %s", id);
|
|
||||||
return card;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "device") == 0) {
|
if (strcmp(id, "device") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -1816,21 +1816,10 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||||
if (snd_pcm_conf_generic_id(id))
|
if (snd_pcm_conf_generic_id(id))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
err = snd_config_get_integer(n, &card);
|
err = snd_config_get_card(n);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
err = snd_config_get_string(n, &str);
|
goto fail;
|
||||||
if (err < 0) {
|
card = err;
|
||||||
SNDERR("Invalid type for %s", id);
|
|
||||||
err = -EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
card = snd_card_get_index(str);
|
|
||||||
if (card < 0) {
|
|
||||||
SNDERR("Invalid value for %s", id);
|
|
||||||
err = card;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "device") == 0) {
|
if (strcmp(id, "device") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -1000,21 +1000,10 @@ int _snd_pcm_parse_control_id(snd_config_t *conf, snd_ctl_elem_id_t *ctl_id,
|
||||||
if (strcmp(id, "comment") == 0)
|
if (strcmp(id, "comment") == 0)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
const char *str;
|
err = snd_config_get_card(n);
|
||||||
long v;
|
if (err < 0)
|
||||||
if ((err = snd_config_get_integer(n, &v)) < 0) {
|
goto _err;
|
||||||
if ((err = snd_config_get_string(n, &str)) < 0) {
|
*cardp = err;
|
||||||
SNDERR("Invalid field %s", id);
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
*cardp = snd_card_get_index(str);
|
|
||||||
if (*cardp < 0) {
|
|
||||||
SNDERR("Cannot get index for %s", str);
|
|
||||||
err = *cardp;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
*cardp = v;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "iface") == 0 || strcmp(id, "interface") == 0) {
|
if (strcmp(id, "iface") == 0 || strcmp(id, "interface") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,6 @@ int _snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||||
{
|
{
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
long card = -1, device = 0, subdevice = -1;
|
long card = -1, device = 0, subdevice = -1;
|
||||||
const char *str;
|
|
||||||
int err;
|
int err;
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
|
|
@ -331,15 +330,10 @@ int _snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||||
if (snd_rawmidi_conf_generic_id(id))
|
if (snd_rawmidi_conf_generic_id(id))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
err = snd_config_get_integer(n, &card);
|
err = snd_config_get_card(n);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
err = snd_config_get_string(n, &str);
|
return err;
|
||||||
if (err < 0)
|
card = err;
|
||||||
return -EINVAL;
|
|
||||||
card = snd_card_get_index(str);
|
|
||||||
if (card < 0)
|
|
||||||
return card;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "device") == 0) {
|
if (strcmp(id, "device") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,6 @@ int _snd_timer_hw_open(snd_timer_t **timer, char *name,
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
long dev_class = SND_TIMER_CLASS_GLOBAL, dev_sclass = SND_TIMER_SCLASS_NONE;
|
long dev_class = SND_TIMER_CLASS_GLOBAL, dev_sclass = SND_TIMER_SCLASS_NONE;
|
||||||
long card = 0, device = 0, subdevice = 0;
|
long card = 0, device = 0, subdevice = 0;
|
||||||
const char *str;
|
|
||||||
int err;
|
int err;
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
|
|
@ -310,15 +309,10 @@ int _snd_timer_hw_open(snd_timer_t **timer, char *name,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "card") == 0) {
|
if (strcmp(id, "card") == 0) {
|
||||||
err = snd_config_get_integer(n, &card);
|
err = snd_config_get_card(n);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
err = snd_config_get_string(n, &str);
|
return err;
|
||||||
if (err < 0)
|
card = err;
|
||||||
return -EINVAL;
|
|
||||||
card = snd_card_get_index(str);
|
|
||||||
if (card < 0)
|
|
||||||
return card;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "device") == 0) {
|
if (strcmp(id, "device") == 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue