]> git.alsa-project.org Git - alsa-lib.git/commitdiff
added the "optional" field for sctl.
authorTakashi Iwai <tiwai@suse.de>
Tue, 25 Feb 2003 16:57:21 +0000 (16:57 +0000)
committerTakashi Iwai <tiwai@suse.de>
Tue, 25 Feb 2003 16:57:21 +0000 (16:57 +0000)
if the control is not loaded properly, it's ignored without errors.

src/control/setup.c

index a5307df500ccb50641c4c26667af3166797cabf1..44c9866f0c5daf15635a44f196d0a33f1f462ac5 100644 (file)
@@ -396,6 +396,7 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
        long subdevice = -1;
        int lock = 0;
        int preserve = 0;
+       int optional = 0;
        snd_config_t *value = NULL, *mask = NULL;
        snd_sctl_elem_t *elem = NULL;
        int err;
@@ -485,6 +486,19 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
                        mask = n;
                        continue;
                }
+               if (strcmp(id, "optional") == 0) {
+                       if ((err = snd_config_get_ascii(n, &tmp)) < 0) {
+                               SNDERR("field %s has an invalid type", id);
+                               goto _err;
+                       }
+                       err = snd_config_get_bool_ascii(tmp);
+                       if (err < 0) {
+                               SNDERR("field %s is not a boolean", id);
+                               goto _err;
+                       }
+                       optional = err;
+                       continue;
+               }
                SNDERR("Unknown field %s", id);
                return -EINVAL;
        }
@@ -530,7 +544,8 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
        snd_ctl_elem_info_set_id(elem->info, elem->id);
        err = snd_ctl_elem_info(h->ctl, elem->info);
        if (err < 0) {
-               SNDERR("Cannot obtain info for CTL elem (%s,'%s',%li,%li,%li): %s", snd_ctl_elem_iface_name(iface), name, index, device, subdevice, snd_strerror(err));
+               if (! optional)
+                       SNDERR("Cannot obtain info for CTL elem (%s,'%s',%li,%li,%li): %s", snd_ctl_elem_iface_name(iface), name, index, device, subdevice, snd_strerror(err));
                goto _err;
        }
        snd_ctl_elem_value_set_id(elem->val, elem->id);
@@ -566,6 +581,8 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
                if (elem->old)
                        snd_ctl_elem_value_free(elem->old);
                free(elem);
+               if (err != -ENOMEM && optional)
+                       err = 0; /* ignore the error */
        }
        if (conf)
                snd_config_delete(conf);