return err;
}
+static int add_auto_value(snd_use_case_mgr_t *uc_mgr, const char *key, char *value)
+{
+ char *s;
+ int err;
+
+ err = get_value1(uc_mgr, &value, &uc_mgr->value_list, key);
+ if (err == -ENOENT) {
+ s = strdup(value);
+ if (s == NULL)
+ return -ENOMEM;
+ return uc_mgr_add_value(&uc_mgr->value_list, key, s);
+ } else if (err < 0) {
+ return err;
+ }
+ free(value);
+ return 0;
+}
+
+static int add_auto_values(snd_use_case_mgr_t *uc_mgr)
+{
+ struct ctl_list *ctl_list;
+ const char *id;
+ char buf[40];
+ int err;
+
+ ctl_list = uc_mgr_get_one_ctl(uc_mgr);
+ if (ctl_list) {
+ id = snd_ctl_card_info_get_id(ctl_list->ctl_info);
+ snprintf(buf, sizeof(buf), "hw:%s", id);
+ err = add_auto_value(uc_mgr, "PlaybackCTL", buf);
+ if (err < 0)
+ return err;
+ err = add_auto_value(uc_mgr, "CaptureCTL", buf);
+ if (err < 0)
+ return err;
+ }
+ return 0;
+}
+
/**
* \brief Init sound card use case manager.
* \param uc_mgr Returned use case manager pointer
goto err;
}
+ err = add_auto_values(mgr);
+ if (err < 0)
+ goto err;
+
*uc_mgr = mgr;
return 0;
return 0;
}
+/*
+ *
+ */
+int uc_mgr_add_value(struct list_head *base, const char *key, char *val)
+{
+ struct ucm_value *curr;
+
+ curr = calloc(1, sizeof(struct ucm_value));
+ if (curr == NULL)
+ return -ENOMEM;
+ curr->name = strdup(key);
+ if (curr->name == NULL) {
+ free(curr);
+ return -ENOMEM;
+ }
+ list_add_tail(&curr->list, base);
+ curr->data = val;
+ return 0;
+}
+
/*
* Parse values.
*
struct list_head *base,
snd_config_t *cfg)
{
- struct ucm_value *curr;
snd_config_iterator_t i;
snd_config_t *n;
- char buf[64];
- long l;
- long long ll;
- double d;
+ char *s;
snd_config_type_t type;
int err;
continue;
}
- /* alloc new value */
- curr = calloc(1, sizeof(struct ucm_value));
- if (curr == NULL)
- return -ENOMEM;
- list_add_tail(&curr->list, base);
- curr->name = strdup(id);
- if (curr->name == NULL)
- return -ENOMEM;
type = snd_config_get_type(n);
switch (type) {
case SND_CONFIG_TYPE_INTEGER:
- snd_config_get_integer(n, &l);
- snprintf(buf, sizeof(buf), "%li", l);
-__buf:
- curr->data = malloc(strlen(buf) + 1);
- if (curr->data == NULL)
- return -ENOMEM;
- strcpy(curr->data, buf);
- break;
case SND_CONFIG_TYPE_INTEGER64:
- snd_config_get_integer64(n, &ll);
- snprintf(buf, sizeof(buf), "%lli", ll);
- goto __buf;
case SND_CONFIG_TYPE_REAL:
- snd_config_get_real(n, &d);
- snprintf(buf, sizeof(buf), "%-16g", d);
- goto __buf;
+ err = snd_config_get_ascii(n, &s);
+ if (err < 0) {
+ uc_error("error: unable to parse value for id '%s': %s!", id, snd_strerror(err));
+ return err;
+ }
+ break;
case SND_CONFIG_TYPE_STRING:
- err = parse_string(n, &curr->data);
+ err = parse_string(n, &s);
if (err < 0) {
uc_error("error: unable to parse a string for id '%s'!", id);
return err;
uc_error("error: invalid type %i in Value compound '%s'", type, id);
return -EINVAL;
}
+ err = uc_mgr_add_value(base, id, s);
+ if (err < 0)
+ return err;
}
return 0;