OSDN Git Service

change iface argument for namehint function to const char *
authorJaroslav Kysela <perex@perex.cz>
Fri, 27 Oct 2006 11:31:32 +0000 (13:31 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 27 Oct 2006 11:31:32 +0000 (13:31 +0200)
remove snd_ctl_iface_conf_name function

include/control.h
src/Versions
src/control/control.c
src/control/namehint.c
src/seq/seq.c
test/namehint.c

index 8d8804a..97fb51a 100644 (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_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_ctl_open(snd_ctl_t **ctl, const char *name, int mode);
index 3b36224..1060b7c 100644 (file)
@@ -294,5 +294,4 @@ ALSA_1.0.14 {
 
     snd_device_name_hint;
     snd_device_name_free_hint;
-    snd_ctl_iface_conf_name;
 } ALSA_1.0.12;
index 838a3ef..1880eef 100644 (file)
@@ -973,16 +973,6 @@ static const char *snd_ctl_elem_iface_names[] = {
        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[] = {
        EVENT(ELEM),
 };
@@ -1011,17 +1001,6 @@ const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t 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
  * \param type CTL event type
  * \return ascii name of CTL event type
index 01dcf2d..e28163e 100644 (file)
@@ -32,6 +32,7 @@ struct hint_list {
        char **list;
        unsigned int count;
        unsigned int allocated;
+       const char *siface;
        snd_ctl_elem_iface_t iface;
        snd_ctl_t *ctl;
        snd_ctl_card_info_t *info;      
@@ -388,21 +389,18 @@ static next_devices_t next_devices[] = {
 };
 #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;
        snd_config_t *conf, *n;
        snd_config_iterator_t i, next;
-       const char *str, *base;
+       const char *str;
        char ctl_name[16];
        snd_ctl_card_info_t *info;
        
        snd_ctl_card_info_alloca(&info);
        list->info = info;
-       if (iface > SND_CTL_ELEM_IFACE_LAST)
-               return -EINVAL;
-       base = snd_ctl_iface_conf_name(iface);
-       err = snd_config_search(snd_config, base, &conf);
+       err = snd_config_search(snd_config, list->siface, &conf);
        if (err < 0)
                return err;
        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);
                if (snd_config_get_id(n, &str) < 0)
                        continue;
-               if (next_devices[iface] != NULL) {
+               if (next_devices[list->iface] != NULL) {
                        list->card = card;
                        list->device = -1;
-                       err = next_devices[iface](list->ctl, &list->device);
+                       err = next_devices[list->iface](list->ctl, &list->device);
                        if (list->device < 0)
                                err = -EINVAL;
                        ok = 0;
                        while (err >= 0 && list->device >= 0) {
-                               err = try_config(list, base, str);
+                               err = try_config(list, list->siface, str);
                                if (err < 0)
                                        break;
-                               err = next_devices[iface](list->ctl, &list->device);
+                               err = next_devices[list->iface](list->ctl, &list->device);
                                ok++;
                        }
                        if (ok)
@@ -439,11 +437,11 @@ static int add_card(struct hint_list *list, int card, snd_ctl_elem_iface_t iface
                        continue;
                if (err < 0) {
                        list->device = -1;
-                       err = try_config(list, base, str);
+                       err = try_config(list, list->siface, str);
                }
                if (err < 0) {
                        list->card = -1;
-                       err = try_config(list, base, str);
+                       err = try_config(list, list->siface, str);
                }
                if (err == -ENOMEM)
                        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.
  * \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
  * \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
  * 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;
        char ehints[24];
@@ -491,13 +489,27 @@ int snd_device_name_hint(int card, snd_ctl_elem_iface_t iface, char ***hints)
                return err;
        list.list = NULL;
        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.longname = NULL;
        if (snd_config_search(snd_config, "defaults.namehint.showall", &conf) >= 0)
                list.show_all = snd_config_get_bool(conf) > 0;
        if (card >= 0) {
-               err = add_card(&list, card, iface);
+               err = add_card(&list, card);
        } else {
                err = snd_card_next(&card);
                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);
                        if (err < 0)
                                goto __error;
-                       err = add_card(&list, card, iface);
+                       err = add_card(&list, card);
                        if (err < 0)
                                goto __error;
                        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;
                }
        }
-       sprintf(ehints, "namehint.%s", snd_ctl_iface_conf_name(iface));
+       sprintf(ehints, "namehint.%s", list.siface);
        err = snd_config_search(snd_config, ehints, &conf);
        if (err >= 0) {
                snd_config_for_each(i, next, conf) {
index a4ad5dc..4d39335 100644 (file)
@@ -836,7 +836,7 @@ static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
 #ifndef PIC
        extern void *snd_seq_open_symbols(void);
 #endif
-       void *h;
+       void *h = NULL;
        if (snd_config_get_type(seq_conf) != SND_CONFIG_TYPE_COMPOUND) {
                if (name)
                        SNDERR("Invalid type for SEQ %s definition", name);
index 3b9b2dc..e978d5c 100644 (file)
@@ -4,18 +4,12 @@
 int main(int argc, char *argv[])
 {
        const char *iface = "pcm";
-       snd_ctl_elem_iface_t niface;
        char **hints, **n;
        int err;
 
        if (argc > 1)
                iface = argv[1];
-       for (niface = 0; niface < SND_CTL_ELEM_IFACE_LAST; niface++)
-               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);
+       err = snd_device_name_hint(-1, iface, &hints);
        if (err < 0)
                errx(1, "snd_device_name_hint error: %s", snd_strerror(err));
        n = hints;