static const char *control_access(snd_ctl_elem_info_t *info) { static char result[10]; char *res = result; *res++ = snd_ctl_elem_info_is_readable(info) ? 'r' : '-'; *res++ = snd_ctl_elem_info_is_writable(info) ? 'w' : '-'; *res++ = snd_ctl_elem_info_is_inactive(info) ? 'i' : '-'; *res++ = snd_ctl_elem_info_is_volatile(info) ? 'v' : '-'; *res++ = snd_ctl_elem_info_is_locked(info) ? 'l' : '-'; *res++ = snd_ctl_elem_info_is_tlv_readable(info) ? 'R' : '-'; *res++ = snd_ctl_elem_info_is_tlv_writable(info) ? 'W' : '-'; *res++ = snd_ctl_elem_info_is_tlv_commandable(info) ? 'C' : '-'; *res++ = '\0'; return result; }
/* * add the TLV string and dB ranges to comment fields */ static int add_tlv_comments(snd_ctl_t *handle, snd_ctl_elem_id_t *id, snd_ctl_elem_info_t *info, snd_config_t *comment) { unsigned int tlv[MAX_USER_TLV_SIZE]; unsigned int *db; long dbmin, dbmax; int err; if (snd_ctl_elem_tlv_read(handle, id, tlv, sizeof(tlv)) < 0) return 0; /* ignore error */ if (snd_ctl_elem_info_is_tlv_writable(info)) { char *s = tlv_to_str(tlv); if (s) { err = snd_config_string_add(comment, "tlv", s); if (err < 0) { error("snd_config_string_add: %s", snd_strerror(err)); return err; } free(s); } } err = snd_tlv_parse_dB_info(tlv, sizeof(tlv), &db); if (err <= 0) return 0; snd_tlv_get_dB_range(db, snd_ctl_elem_info_get_min(info), snd_ctl_elem_info_get_max(info), &dbmin, &dbmax); if (err < 0) return err; snd_config_integer_add(comment, "dbmin", dbmin); snd_config_integer_add(comment, "dbmax", dbmax); return 0; }
static int execute_cset(snd_ctl_t *ctl, const char *cset, unsigned int type) { const char *pos; int err; snd_ctl_elem_id_t *id; snd_ctl_elem_value_t *value; snd_ctl_elem_info_t *info; unsigned int *res = NULL; snd_ctl_elem_id_malloc(&id); snd_ctl_elem_value_malloc(&value); snd_ctl_elem_info_malloc(&info); err = __snd_ctl_ascii_elem_id_parse(id, cset, &pos); if (err < 0) goto __fail; while (*pos && isspace(*pos)) pos++; if (!*pos) { uc_error("undefined value for cset >%s<", cset); err = -EINVAL; goto __fail; } snd_ctl_elem_info_set_id(info, id); err = snd_ctl_elem_info(ctl, info); if (err < 0) goto __fail; if (type == SEQUENCE_ELEMENT_TYPE_CSET_TLV) { if (!snd_ctl_elem_info_is_tlv_writable(info)) { err = -EINVAL; goto __fail; } err = read_tlv_file(&res, pos); if (err < 0) goto __fail; err = snd_ctl_elem_tlv_write(ctl, id, res); if (err < 0) goto __fail; } else { snd_ctl_elem_value_set_id(value, id); err = snd_ctl_elem_read(ctl, value); if (err < 0) goto __fail; if (type == SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE) err = binary_file_parse(value, info, pos); else err = snd_ctl_ascii_value_parse(ctl, value, info, pos); if (err < 0) goto __fail; err = snd_ctl_elem_write(ctl, value); if (err < 0) goto __fail; } err = 0; __fail: if (id != NULL) free(id); if (value != NULL) free(value); if (info != NULL) free(info); if (res != NULL) free(res); return err; }