change iface argument for namehint function to const char *

remove snd_ctl_iface_conf_name function
This commit is contained in:
Jaroslav Kysela 2006-10-27 13:31:32 +02:00
parent 252fd43461
commit 03389a444b
6 changed files with 33 additions and 49 deletions

View file

@ -214,7 +214,7 @@ int snd_card_get_index(const char *name);
int snd_card_get_name(int card, char **name); int snd_card_get_name(int card, char **name);
int snd_card_get_longname(int card, char **name); int snd_card_get_longname(int card, char **name);
int snd_device_name_hint(int card, snd_ctl_elem_iface_t iface, char ***hints); int snd_device_name_hint(int card, const char *iface, char ***hints);
int snd_device_name_free_hint(char **hints); int snd_device_name_free_hint(char **hints);
int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode); int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode);

View file

@ -294,5 +294,4 @@ ALSA_1.0.14 {
snd_device_name_hint; snd_device_name_hint;
snd_device_name_free_hint; snd_device_name_free_hint;
snd_ctl_iface_conf_name;
} ALSA_1.0.12; } ALSA_1.0.12;

View file

@ -973,16 +973,6 @@ static const char *snd_ctl_elem_iface_names[] = {
IFACE(SEQUENCER), IFACE(SEQUENCER),
}; };
static const char *snd_ctl_iface_conf_names[] = {
IFACE1(CARD, card),
IFACE1(HWDEP, hwdep),
IFACE1(MIXER, mixer),
IFACE1(PCM, pcm),
IFACE1(RAWMIDI, rawmidi),
IFACE1(TIMER, timer),
IFACE1(SEQUENCER, seq),
};
static const char *snd_ctl_event_type_names[] = { static const char *snd_ctl_event_type_names[] = {
EVENT(ELEM), EVENT(ELEM),
}; };
@ -1010,17 +1000,6 @@ const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface)
return snd_ctl_elem_iface_names[iface]; return snd_ctl_elem_iface_names[iface];
} }
/**
* \brief get configuration name of related interface
* \param iface ala CTL interface identification
* \return ascii name of configuration interface
*/
const char *snd_ctl_iface_conf_name(snd_ctl_elem_iface_t iface)
{
assert(iface <= SND_CTL_ELEM_IFACE_LAST);
return snd_ctl_iface_conf_names[iface];
}
/** /**
* \brief get name of a CTL event type * \brief get name of a CTL event type
* \param type CTL event type * \param type CTL event type

View file

@ -32,6 +32,7 @@ struct hint_list {
char **list; char **list;
unsigned int count; unsigned int count;
unsigned int allocated; unsigned int allocated;
const char *siface;
snd_ctl_elem_iface_t iface; snd_ctl_elem_iface_t iface;
snd_ctl_t *ctl; snd_ctl_t *ctl;
snd_ctl_card_info_t *info; snd_ctl_card_info_t *info;
@ -388,21 +389,18 @@ static next_devices_t next_devices[] = {
}; };
#endif #endif
static int add_card(struct hint_list *list, int card, snd_ctl_elem_iface_t iface) static int add_card(struct hint_list *list, int card)
{ {
int err, ok; int err, ok;
snd_config_t *conf, *n; snd_config_t *conf, *n;
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
const char *str, *base; const char *str;
char ctl_name[16]; char ctl_name[16];
snd_ctl_card_info_t *info; snd_ctl_card_info_t *info;
snd_ctl_card_info_alloca(&info); snd_ctl_card_info_alloca(&info);
list->info = info; list->info = info;
if (iface > SND_CTL_ELEM_IFACE_LAST) err = snd_config_search(snd_config, list->siface, &conf);
return -EINVAL;
base = snd_ctl_iface_conf_name(iface);
err = snd_config_search(snd_config, base, &conf);
if (err < 0) if (err < 0)
return err; return err;
sprintf(ctl_name, "hw:%i", card); sprintf(ctl_name, "hw:%i", card);
@ -416,18 +414,18 @@ static int add_card(struct hint_list *list, int card, snd_ctl_elem_iface_t iface
n = snd_config_iterator_entry(i); n = snd_config_iterator_entry(i);
if (snd_config_get_id(n, &str) < 0) if (snd_config_get_id(n, &str) < 0)
continue; continue;
if (next_devices[iface] != NULL) { if (next_devices[list->iface] != NULL) {
list->card = card; list->card = card;
list->device = -1; list->device = -1;
err = next_devices[iface](list->ctl, &list->device); err = next_devices[list->iface](list->ctl, &list->device);
if (list->device < 0) if (list->device < 0)
err = -EINVAL; err = -EINVAL;
ok = 0; ok = 0;
while (err >= 0 && list->device >= 0) { while (err >= 0 && list->device >= 0) {
err = try_config(list, base, str); err = try_config(list, list->siface, str);
if (err < 0) if (err < 0)
break; break;
err = next_devices[iface](list->ctl, &list->device); err = next_devices[list->iface](list->ctl, &list->device);
ok++; ok++;
} }
if (ok) if (ok)
@ -439,11 +437,11 @@ static int add_card(struct hint_list *list, int card, snd_ctl_elem_iface_t iface
continue; continue;
if (err < 0) { if (err < 0) {
list->device = -1; list->device = -1;
err = try_config(list, base, str); err = try_config(list, list->siface, str);
} }
if (err < 0) { if (err < 0) {
list->card = -1; list->card = -1;
err = try_config(list, base, str); err = try_config(list, list->siface, str);
} }
if (err == -ENOMEM) if (err == -ENOMEM)
goto __error; goto __error;
@ -457,7 +455,7 @@ static int add_card(struct hint_list *list, int card, snd_ctl_elem_iface_t iface
/** /**
* \brief Return string list with device name hints. * \brief Return string list with device name hints.
* \param card Card number or -1 (means all cards) * \param card Card number or -1 (means all cards)
* \param iface Interface identification * \param iface Interface identification (like "pcm", "rawmidi", "timer", "seq")
* \param hints Result - array of string with device name hints * \param hints Result - array of string with device name hints
* \result zero if success, otherwise a negative error code * \result zero if success, otherwise a negative error code
* *
@ -475,7 +473,7 @@ static int add_card(struct hint_list *list, int card, snd_ctl_elem_iface_t iface
* Special variables: defaults.namehint.showall specifies if all device * Special variables: defaults.namehint.showall specifies if all device
* definitions are accepted (boolean type). * definitions are accepted (boolean type).
*/ */
int snd_device_name_hint(int card, snd_ctl_elem_iface_t iface, char ***hints) int snd_device_name_hint(int card, const char *iface, char ***hints)
{ {
struct hint_list list; struct hint_list list;
char ehints[24]; char ehints[24];
@ -491,13 +489,27 @@ int snd_device_name_hint(int card, snd_ctl_elem_iface_t iface, char ***hints)
return err; return err;
list.list = NULL; list.list = NULL;
list.count = list.allocated = 0; list.count = list.allocated = 0;
list.iface = iface; list.siface = iface;
if (strcmp(iface, "card") == 0)
list.iface = SND_CTL_ELEM_IFACE_CARD;
else if (strcmp(iface, "pcm") == 0)
list.iface = SND_CTL_ELEM_IFACE_PCM;
else if (strcmp(iface, "rawmidi") == 0)
list.iface = SND_CTL_ELEM_IFACE_RAWMIDI;
else if (strcmp(iface, "timer") == 0)
list.iface = SND_CTL_ELEM_IFACE_TIMER;
else if (strcmp(iface, "seq") == 0)
list.iface = SND_CTL_ELEM_IFACE_SEQUENCER;
else if (strcmp(iface, "hwdep") == 0)
list.iface = SND_CTL_ELEM_IFACE_HWDEP;
else
return -EINVAL;
list.show_all = 0; list.show_all = 0;
list.longname = NULL; list.longname = NULL;
if (snd_config_search(snd_config, "defaults.namehint.showall", &conf) >= 0) if (snd_config_search(snd_config, "defaults.namehint.showall", &conf) >= 0)
list.show_all = snd_config_get_bool(conf) > 0; list.show_all = snd_config_get_bool(conf) > 0;
if (card >= 0) { if (card >= 0) {
err = add_card(&list, card, iface); err = add_card(&list, card);
} else { } else {
err = snd_card_next(&card); err = snd_card_next(&card);
if (err < 0) if (err < 0)
@ -506,7 +518,7 @@ int snd_device_name_hint(int card, snd_ctl_elem_iface_t iface, char ***hints)
err = snd_card_get_longname(card, &list.longname); err = snd_card_get_longname(card, &list.longname);
if (err < 0) if (err < 0)
goto __error; goto __error;
err = add_card(&list, card, iface); err = add_card(&list, card);
if (err < 0) if (err < 0)
goto __error; goto __error;
err = snd_card_next(&card); err = snd_card_next(&card);
@ -514,7 +526,7 @@ int snd_device_name_hint(int card, snd_ctl_elem_iface_t iface, char ***hints)
goto __error; goto __error;
} }
} }
sprintf(ehints, "namehint.%s", snd_ctl_iface_conf_name(iface)); sprintf(ehints, "namehint.%s", list.siface);
err = snd_config_search(snd_config, ehints, &conf); err = snd_config_search(snd_config, ehints, &conf);
if (err >= 0) { if (err >= 0) {
snd_config_for_each(i, next, conf) { snd_config_for_each(i, next, conf) {

View file

@ -836,7 +836,7 @@ static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
#ifndef PIC #ifndef PIC
extern void *snd_seq_open_symbols(void); extern void *snd_seq_open_symbols(void);
#endif #endif
void *h; void *h = NULL;
if (snd_config_get_type(seq_conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(seq_conf) != SND_CONFIG_TYPE_COMPOUND) {
if (name) if (name)
SNDERR("Invalid type for SEQ %s definition", name); SNDERR("Invalid type for SEQ %s definition", name);

View file

@ -4,18 +4,12 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *iface = "pcm"; const char *iface = "pcm";
snd_ctl_elem_iface_t niface;
char **hints, **n; char **hints, **n;
int err; int err;
if (argc > 1) if (argc > 1)
iface = argv[1]; iface = argv[1];
for (niface = 0; niface < SND_CTL_ELEM_IFACE_LAST; niface++) err = snd_device_name_hint(-1, iface, &hints);
if (strcmp(snd_ctl_iface_conf_name(niface), iface) == 0)
break;
if (niface > SND_CTL_ELEM_IFACE_LAST)
errx(1, "interface %s dnoes not exist", iface);
err = snd_device_name_hint(-1, niface, &hints);
if (err < 0) if (err < 0)
errx(1, "snd_device_name_hint error: %s", snd_strerror(err)); errx(1, "snd_device_name_hint error: %s", snd_strerror(err));
n = hints; n = hints;