|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \file confmisc.c
|
|
Packit |
4a16fb |
* \ingroup Configuration
|
|
Packit |
4a16fb |
* \brief Configuration helper functions
|
|
Packit |
4a16fb |
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
Packit |
4a16fb |
* \author Jaroslav Kysela <perex@perex.cz>
|
|
Packit |
4a16fb |
* \date 2000-2001
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Configuration helper functions.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* See the \ref conffunc page for more details.
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
/*
|
|
Packit |
4a16fb |
* Miscellaneous configuration helper functions
|
|
Packit |
4a16fb |
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>,
|
|
Packit |
4a16fb |
* Jaroslav Kysela <perex@perex.cz>
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* This library is free software; you can redistribute it and/or modify
|
|
Packit |
4a16fb |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit |
4a16fb |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
4a16fb |
* the License, or (at your option) any later version.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
4a16fb |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
4a16fb |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
4a16fb |
* GNU Lesser General Public License for more details.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
4a16fb |
* License along with this library; if not, write to the Free Software
|
|
Packit |
4a16fb |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/*! \page conffunc
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
\section conffunc_ref Function reference
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
The getenv function - snd_func_getenv() - obtains
|
|
Packit |
4a16fb |
an environment value. The result is a string.
|
|
Packit |
4a16fb |
The igetenv function - snd_func_igetenv() - obtains
|
|
Packit |
4a16fb |
an environment value. The result is an integer.
|
|
Packit |
4a16fb |
The concat function - snd_func_concat() - merges all specified
|
|
Packit |
4a16fb |
strings. The result is a string.
|
|
Packit |
4a16fb |
The iadd function - snd_func_iadd() - sum all specified integers.
|
|
Packit |
4a16fb |
The result is an integer.
|
|
Packit |
4a16fb |
The imul function - snd_func_imul() - multiply all specified integers.
|
|
Packit |
4a16fb |
The result is an integer.
|
|
Packit |
4a16fb |
The datadir function - snd_func_datadir() - returns the
|
|
Packit |
4a16fb |
ALSA data directory. The result is a string.
|
|
Packit |
4a16fb |
The refer function - snd_func_refer() - copies the referred
|
|
Packit |
4a16fb |
configuration. The result has the same type as the referred node.
|
|
Packit |
4a16fb |
The card_inum function - snd_func_card_inum() - returns
|
|
Packit |
4a16fb |
a card number (integers).
|
|
Packit |
4a16fb |
The card_driver function - snd_func_card_driver() - returns
|
|
Packit |
4a16fb |
a driver identification. The result is a string.
|
|
Packit |
4a16fb |
The card_id function - snd_func_card_id() - returns
|
|
Packit |
4a16fb |
a card identification. The result is a string.
|
|
Packit |
4a16fb |
The card_name function - snd_func_card_name() - returns
|
|
Packit |
4a16fb |
a card's name. The result is a string.
|
|
Packit |
4a16fb |
The pcm_id function - snd_func_pcm_id() - returns
|
|
Packit |
4a16fb |
a pcm identification. The result is a string.
|
|
Packit |
4a16fb |
The private_string function - snd_func_private_string() - returns the
|
|
Packit |
4a16fb |
string from the private_data node.
|
|
Packit |
4a16fb |
The private_card_driver function - snd_func_private_card_driver() -
|
|
Packit |
4a16fb |
returns the driver identification from the private_data node.
|
|
Packit |
4a16fb |
The result is a string.
|
|
Packit |
4a16fb |
The private_pcm_subdevice function - snd_func_private_pcm_subdevice() -
|
|
Packit |
4a16fb |
returns the PCM subdevice number from the private_data node.
|
|
Packit |
4a16fb |
The result is a string.
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#include <stdlib.h>
|
|
Packit |
4a16fb |
#include <stdio.h>
|
|
Packit |
4a16fb |
#include <string.h>
|
|
Packit |
4a16fb |
#include <ctype.h>
|
|
Packit |
4a16fb |
#include "local.h"
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Gets the boolean value from the given ASCII string.
|
|
Packit |
4a16fb |
* \param ascii The string to be parsed.
|
|
Packit |
4a16fb |
* \return 0 or 1 if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_config_get_bool_ascii(const char *ascii)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
unsigned int k;
|
|
Packit |
4a16fb |
static const struct {
|
|
Packit |
4a16fb |
const char str[8];
|
|
Packit |
4a16fb |
int val;
|
|
Packit |
4a16fb |
} b[] = {
|
|
Packit |
4a16fb |
{ "0", 0 },
|
|
Packit |
4a16fb |
{ "1", 1 },
|
|
Packit |
4a16fb |
{ "false", 0 },
|
|
Packit |
4a16fb |
{ "true", 1 },
|
|
Packit |
4a16fb |
{ "no", 0 },
|
|
Packit |
4a16fb |
{ "yes", 1 },
|
|
Packit |
4a16fb |
{ "off", 0 },
|
|
Packit |
4a16fb |
{ "on", 1 },
|
|
Packit |
4a16fb |
};
|
|
Packit |
4a16fb |
for (k = 0; k < sizeof(b) / sizeof(*b); k++) {
|
|
Packit |
4a16fb |
if (strcasecmp(b[k].str, ascii) == 0)
|
|
Packit |
4a16fb |
return b[k].val;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Gets the boolean value from a configuration node.
|
|
Packit |
4a16fb |
* \param conf Handle to the configuration node to be parsed.
|
|
Packit |
4a16fb |
* \return 0 or 1 if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_config_get_bool(const snd_config_t *conf)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
long v;
|
|
Packit |
4a16fb |
const char *str, *id;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_get_id(conf, &id;;
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
err = snd_config_get_integer(conf, &v);
|
|
Packit |
4a16fb |
if (err >= 0) {
|
|
Packit |
4a16fb |
if (v < 0 || v > 1) {
|
|
Packit |
4a16fb |
_invalid_value:
|
|
Packit |
4a16fb |
SNDERR("Invalid value for %s", id);
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return v;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_string(conf, &str);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("Invalid type for %s", id);
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_bool_ascii(str);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
goto _invalid_value;
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Gets the control interface index from the given ASCII string.
|
|
Packit |
4a16fb |
* \param ascii The string to be parsed.
|
|
Packit |
4a16fb |
* \return The control interface index if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_config_get_ctl_iface_ascii(const char *ascii)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
long v;
|
|
Packit |
4a16fb |
snd_ctl_elem_iface_t idx;
|
|
Packit |
4a16fb |
if (isdigit(ascii[0])) {
|
|
Packit |
4a16fb |
if (safe_strtol(ascii, &v) >= 0) {
|
|
Packit |
4a16fb |
if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST)
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
return v;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++) {
|
|
Packit |
4a16fb |
if (strcasecmp(snd_ctl_elem_iface_name(idx), ascii) == 0)
|
|
Packit |
4a16fb |
return idx;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Gets the control interface index from a configuration node.
|
|
Packit |
4a16fb |
* \param conf Handle to the configuration node to be parsed.
|
|
Packit |
4a16fb |
* \return The control interface index if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_config_get_ctl_iface(const snd_config_t *conf)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
long v;
|
|
Packit |
4a16fb |
const char *str, *id;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_get_id(conf, &id;;
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
err = snd_config_get_integer(conf, &v);
|
|
Packit |
4a16fb |
if (err >= 0) {
|
|
Packit |
4a16fb |
if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST) {
|
|
Packit |
4a16fb |
_invalid_value:
|
|
Packit |
4a16fb |
SNDERR("Invalid value for %s", id);
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return v;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_string(conf, &str);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("Invalid type for %s", id);
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_ctl_iface_ascii(str);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
goto _invalid_value;
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/*
|
|
Packit |
4a16fb |
* Helper functions for the configuration file
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns an environment value.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with definitions for \c vars and
|
|
Packit |
4a16fb |
* \c default.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return Zero if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func getenv
|
|
Packit |
4a16fb |
vars [ MY_CARD CARD C ]
|
|
Packit |
4a16fb |
default 0
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n, *d;
|
|
Packit |
4a16fb |
snd_config_iterator_t i, next;
|
|
Packit |
4a16fb |
const char *res, *id;
|
|
Packit |
4a16fb |
char *def = NULL;
|
|
Packit |
4a16fb |
int idx = 0, err, hit;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_search(src, "vars", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field vars not found");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating vars");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_search(src, "default", &d);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field default not found");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(d, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating default");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_ascii(d, &def;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error getting field default");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
do {
|
|
Packit |
4a16fb |
hit = 0;
|
|
Packit |
4a16fb |
snd_config_for_each(i, next, n) {
|
|
Packit |
4a16fb |
snd_config_t *n = snd_config_iterator_entry(i);
|
|
Packit |
4a16fb |
const char *ptr;
|
|
Packit |
4a16fb |
long i;
|
|
Packit |
4a16fb |
if (snd_config_get_id(n, &id) < 0)
|
|
Packit |
4a16fb |
continue;
|
|
Packit |
4a16fb |
if (snd_config_get_type(n) != SND_CONFIG_TYPE_STRING) {
|
|
Packit |
4a16fb |
SNDERR("field %s is not a string", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = safe_strtol(id, &i);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("id of field %s is not an integer", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (i == idx) {
|
|
Packit |
4a16fb |
idx++;
|
|
Packit |
4a16fb |
err = snd_config_get_string(n, &ptr);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("invalid string for id %s", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
res = getenv(ptr);
|
|
Packit |
4a16fb |
if (res != NULL && *res != '\0')
|
|
Packit |
4a16fb |
goto __ok;
|
|
Packit |
4a16fb |
hit = 1;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
} while (hit);
|
|
Packit |
4a16fb |
res = def;
|
|
Packit |
4a16fb |
__ok:
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id, res);
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
free(def);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_getenv, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns an integer environment value.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type integer) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with definitions for \c vars and
|
|
Packit |
4a16fb |
* \c default.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return Zero if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func igetenv
|
|
Packit |
4a16fb |
vars [ MY_DEVICE DEVICE D ]
|
|
Packit |
4a16fb |
default 0
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_igetenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *d;
|
|
Packit |
4a16fb |
const char *str, *id;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
long v;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_func_getenv(&d, root, src, private_data);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
err = snd_config_get_string(d, &str);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
snd_config_delete(d);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = safe_strtol(str, &v);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
snd_config_delete(d);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
snd_config_delete(d);
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
err = snd_config_imake_integer(dst, id, v);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_igetenv, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Merges the given strings.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a definition for \c strings.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example (result is "a1b2c3"):
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func concat
|
|
Packit |
4a16fb |
strings [ "a1" "b2" "c3" ]
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n;
|
|
Packit |
4a16fb |
snd_config_iterator_t i, next;
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
char *res = NULL, *tmp;
|
|
Packit |
4a16fb |
int idx = 0, len = 0, len1, err, hit;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_search(src, "strings", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field strings not found");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating strings");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
do {
|
|
Packit |
4a16fb |
hit = 0;
|
|
Packit |
4a16fb |
snd_config_for_each(i, next, n) {
|
|
Packit |
4a16fb |
snd_config_t *n = snd_config_iterator_entry(i);
|
|
Packit |
4a16fb |
char *ptr;
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
long i;
|
|
Packit |
4a16fb |
if (snd_config_get_id(n, &id) < 0)
|
|
Packit |
4a16fb |
continue;
|
|
Packit |
4a16fb |
err = safe_strtol(id, &i);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("id of field %s is not an integer", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (i == idx) {
|
|
Packit |
4a16fb |
idx++;
|
|
Packit |
4a16fb |
err = snd_config_get_ascii(n, &ptr);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("invalid ascii string for id %s", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
len1 = strlen(ptr);
|
|
Packit |
4a16fb |
tmp = realloc(res, len + len1 + 1);
|
|
Packit |
4a16fb |
if (tmp == NULL) {
|
|
Packit |
4a16fb |
free(ptr);
|
|
Packit |
4a16fb |
free(res);
|
|
Packit |
4a16fb |
err = -ENOMEM;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
memcpy(tmp + len, ptr, len1);
|
|
Packit |
4a16fb |
free(ptr);
|
|
Packit |
4a16fb |
len += len1;
|
|
Packit |
4a16fb |
tmp[len] = '\0';
|
|
Packit |
4a16fb |
res = tmp;
|
|
Packit |
4a16fb |
hit = 1;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
} while (hit);
|
|
Packit |
4a16fb |
if (res == NULL) {
|
|
Packit |
4a16fb |
SNDERR("empty string is not accepted");
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id, res);
|
|
Packit |
4a16fb |
free(res);
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_concat, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int snd_func_iops(snd_config_t **dst,
|
|
Packit |
4a16fb |
snd_config_t *root,
|
|
Packit |
4a16fb |
snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data,
|
|
Packit |
4a16fb |
int op)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n;
|
|
Packit |
4a16fb |
snd_config_iterator_t i, next;
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
char *res = NULL;
|
|
Packit |
4a16fb |
long result = 0, val;
|
|
Packit |
4a16fb |
int idx = 0, err, hit;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_search(src, "integers", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field integers not found");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating integers");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
do {
|
|
Packit |
4a16fb |
hit = 0;
|
|
Packit |
4a16fb |
snd_config_for_each(i, next, n) {
|
|
Packit |
4a16fb |
snd_config_t *n = snd_config_iterator_entry(i);
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
long i;
|
|
Packit |
4a16fb |
if (snd_config_get_id(n, &id) < 0)
|
|
Packit |
4a16fb |
continue;
|
|
Packit |
4a16fb |
err = safe_strtol(id, &i);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("id of field %s is not an integer", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (i == idx) {
|
|
Packit |
4a16fb |
idx++;
|
|
Packit |
4a16fb |
err = snd_config_get_integer(n, &val;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("invalid integer for id %s", id);
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
switch (op) {
|
|
Packit |
4a16fb |
case 0: result += val; break;
|
|
Packit |
4a16fb |
case 1: result *= val; break;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
hit = 1;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
} while (hit);
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_integer(dst, id, result);
|
|
Packit |
4a16fb |
free(res);
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Sum the given integers.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type integer) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a definition for \c integers.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example (result is 10):
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func iadd
|
|
Packit |
4a16fb |
integers [ 2 3 5 ]
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_iadd(snd_config_t **dst, snd_config_t *root,
|
|
Packit |
4a16fb |
snd_config_t *src, snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
return snd_func_iops(dst, root, src, private_data, 0);
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_iadd, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Multiply the given integers.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type integer) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a definition for \c integers.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example (result is 12):
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func imul
|
|
Packit |
4a16fb |
integers [ 2 3 2 ]
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_imul(snd_config_t **dst, snd_config_t *root,
|
|
Packit |
4a16fb |
snd_config_t *src, snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
return snd_func_iops(dst, root, src, private_data, 1);
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_imul, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the ALSA data directory.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node. Not used.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example (result is "/usr/share/alsa" using the default paths):
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func datadir
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_datadir(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
|
|
Packit |
4a16fb |
snd_config_t *src, snd_config_t *private_data ATTRIBUTE_UNUSED)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
return snd_config_imake_string(dst, id, snd_config_topdir());
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_datadir, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int open_ctl(long card, snd_ctl_t **ctl)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
char name[16];
|
|
Packit |
4a16fb |
snprintf(name, sizeof(name), "hw:%li", card);
|
|
Packit |
4a16fb |
name[sizeof(name)-1] = '\0';
|
|
Packit |
4a16fb |
return snd_ctl_open(ctl, name, 0);
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#if 0
|
|
Packit |
4a16fb |
static int string_from_integer(char **dst, long v)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
char str[32];
|
|
Packit |
4a16fb |
char *res;
|
|
Packit |
4a16fb |
sprintf(str, "%li", v);
|
|
Packit |
4a16fb |
res = strdup(str);
|
|
Packit |
4a16fb |
if (res == NULL)
|
|
Packit |
4a16fb |
return -ENOMEM;
|
|
Packit |
4a16fb |
*dst = res;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the string from \c private_data.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node (type string,
|
|
Packit |
4a16fb |
* id "string").
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func private_string
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_private_string(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
|
|
Packit |
4a16fb |
snd_config_t *src, snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
const char *str, *id;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
if (private_data == NULL)
|
|
Packit |
4a16fb |
return snd_config_copy(dst, src);
|
|
Packit |
4a16fb |
err = snd_config_test_id(private_data, "string");
|
|
Packit |
4a16fb |
if (err) {
|
|
Packit |
4a16fb |
SNDERR("field string not found");
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_string(private_data, &str);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field string is not a string");
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id, str);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_private_string, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
int snd_determine_driver(int card, char **driver)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_ctl_t *ctl = NULL;
|
|
Packit |
4a16fb |
snd_ctl_card_info_t info = {0};
|
|
Packit |
4a16fb |
char *res = NULL;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
assert(card >= 0 && card <= SND_MAX_CARDS);
|
|
Packit |
4a16fb |
err = open_ctl(card, &ctl;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not open control for card %i", card);
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_ctl_card_info(ctl, &info;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
res = strdup(snd_ctl_card_info_get_driver(&info));
|
|
Packit |
4a16fb |
if (res == NULL)
|
|
Packit |
4a16fb |
err = -ENOMEM;
|
|
Packit |
4a16fb |
else {
|
|
Packit |
4a16fb |
*driver = res;
|
|
Packit |
4a16fb |
err = 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
if (ctl)
|
|
Packit |
4a16fb |
snd_ctl_close(ctl);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the driver identification from \c private_data.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node (type integer,
|
|
Packit |
4a16fb |
* id "card").
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func private_card_driver
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_private_card_driver(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
char *driver;
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
long card;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_test_id(private_data, "card");
|
|
Packit |
4a16fb |
if (err) {
|
|
Packit |
4a16fb |
SNDERR("field card not found");
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_integer(private_data, &card;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field card is not an integer");
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if ((err = snd_determine_driver(card, &driver)) < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id, driver);
|
|
Packit |
4a16fb |
free(driver);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_private_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int parse_card(snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n;
|
|
Packit |
4a16fb |
char *str;
|
|
Packit |
4a16fb |
int card, err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_search(src, "card", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field card not found");
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating card");
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_ascii(n, &str);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field card is not an integer or a string");
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
card = snd_card_get_index(str);
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
SNDERR("cannot find card '%s'", str);
|
|
Packit |
4a16fb |
free(str);
|
|
Packit |
4a16fb |
return card;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the card number as integer.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a \c card definition.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func card_inum
|
|
Packit |
4a16fb |
card '0'
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_card_inum(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
int card, err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
card = parse_card(root, src, private_data);
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
return card;
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_integer(dst, id, card);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_card_inum, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the driver identification for a card.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a \c card definition.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func card_driver
|
|
Packit |
4a16fb |
card 0
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_card_driver(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *val;
|
|
Packit |
4a16fb |
int card, err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
card = parse_card(root, src, private_data);
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
return card;
|
|
Packit |
4a16fb |
err = snd_config_imake_integer(&val, "card", card);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
err = snd_func_private_card_driver(dst, root, src, val);
|
|
Packit |
4a16fb |
snd_config_delete(val);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the identification of a card.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a \c card definition.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func card_id
|
|
Packit |
4a16fb |
card 0
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_ctl_t *ctl = NULL;
|
|
Packit |
4a16fb |
snd_ctl_card_info_t info = {0};
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
int card, err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
card = parse_card(root, src, private_data);
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
return card;
|
|
Packit |
4a16fb |
err = open_ctl(card, &ctl;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not open control for card %i", card);
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_ctl_card_info(ctl, &info;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id,
|
|
Packit |
4a16fb |
snd_ctl_card_info_get_id(&info));
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
if (ctl)
|
|
Packit |
4a16fb |
snd_ctl_close(ctl);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_card_id, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the name of a card.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with a \c card definition.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func card_name
|
|
Packit |
4a16fb |
card 0
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_card_name(snd_config_t **dst, snd_config_t *root,
|
|
Packit |
4a16fb |
snd_config_t *src, snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_ctl_t *ctl = NULL;
|
|
Packit |
4a16fb |
snd_ctl_card_info_t info = {0};
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
int card, err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
card = parse_card(root, src, private_data);
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
return card;
|
|
Packit |
4a16fb |
err = open_ctl(card, &ctl;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not open control for card %i", card);
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_ctl_card_info(ctl, &info;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_safe_string(dst, id,
|
|
Packit |
4a16fb |
snd_ctl_card_info_get_name(&info));
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
if (ctl)
|
|
Packit |
4a16fb |
snd_ctl_close(ctl);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_card_name, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#ifdef BUILD_PCM
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the pcm identification of a device.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with definitions for \c card,
|
|
Packit |
4a16fb |
* \c device and (optionally) \c subdevice.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func pcm_id
|
|
Packit |
4a16fb |
card 0
|
|
Packit |
4a16fb |
device 0
|
|
Packit |
4a16fb |
subdevice 0 # optional
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n;
|
|
Packit |
4a16fb |
snd_ctl_t *ctl = NULL;
|
|
Packit |
4a16fb |
snd_pcm_info_t info = {0};
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
long card, device, subdevice = 0;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
card = parse_card(root, src, private_data);
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
return card;
|
|
Packit |
4a16fb |
err = snd_config_search(src, "device", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field device not found");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating device");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_integer(n, &device);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field device is not an integer");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (snd_config_search(src, "subdevice", &n) >= 0) {
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating subdevice");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_integer(n, &subdevice);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field subdevice is not an integer");
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = open_ctl(card, &ctl;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not open control for card %li", card);
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
snd_pcm_info_set_device(&info, device);
|
|
Packit |
4a16fb |
snd_pcm_info_set_subdevice(&info, subdevice);
|
|
Packit |
4a16fb |
err = snd_ctl_pcm_info(ctl, &info;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
|
|
Packit |
4a16fb |
goto __error;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id,
|
|
Packit |
4a16fb |
snd_pcm_info_get_id(&info));
|
|
Packit |
4a16fb |
__error:
|
|
Packit |
4a16fb |
if (ctl)
|
|
Packit |
4a16fb |
snd_ctl_close(ctl);
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_pcm_id, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the pcm card and device arguments (in form CARD=N,DEV=M)
|
|
Packit |
4a16fb |
* for pcm specified by class and index.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type string) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with definitions for \c class
|
|
Packit |
4a16fb |
* and \c index.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func pcm_args_by_class
|
|
Packit |
4a16fb |
class 0
|
|
Packit |
4a16fb |
index 0
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n;
|
|
Packit |
4a16fb |
snd_ctl_t *ctl = NULL;
|
|
Packit |
4a16fb |
snd_pcm_info_t info = {0};
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
int card = -1, dev;
|
|
Packit |
4a16fb |
long class, index;
|
|
Packit |
4a16fb |
int idx = 0;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_search(src, "class", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field class not found");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating class");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_integer(n, &class);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field class is not an integer");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_search(src, "index", &n);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field index not found");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating index");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_integer(n, &index);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field index is not an integer");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
while(1) {
|
|
Packit |
4a16fb |
err = snd_card_next(&card;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not get next card");
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (card < 0)
|
|
Packit |
4a16fb |
break;
|
|
Packit |
4a16fb |
err = open_ctl(card, &ctl;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not open control for card %i", card);
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
dev = -1;
|
|
Packit |
4a16fb |
while(1) {
|
|
Packit |
4a16fb |
err = snd_ctl_pcm_next_device(ctl, &dev;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("could not get next pcm for card %i", card);
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (dev < 0)
|
|
Packit |
4a16fb |
break;
|
|
Packit |
4a16fb |
snd_pcm_info_set_device(&info, dev);
|
|
Packit |
4a16fb |
err = snd_ctl_pcm_info(ctl, &info;;
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
continue;
|
|
Packit |
4a16fb |
if (snd_pcm_info_get_class(&info) == (snd_pcm_class_t)class &&
|
|
Packit |
4a16fb |
index == idx++)
|
|
Packit |
4a16fb |
goto __out;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
snd_ctl_close(ctl);
|
|
Packit |
4a16fb |
ctl = NULL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = -ENODEV;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
__out:
|
|
Packit |
4a16fb |
if (ctl)
|
|
Packit |
4a16fb |
snd_ctl_close(ctl);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
if((err = snd_config_get_id(src, &id)) >= 0) {
|
|
Packit |
4a16fb |
char name[32];
|
|
Packit |
4a16fb |
snprintf(name, sizeof(name), "CARD=%i,DEV=%i", card, dev);
|
|
Packit |
4a16fb |
err = snd_config_imake_string(dst, id, name);
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_pcm_args_by_class, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Returns the PCM subdevice from \c private_data.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with type integer) at the address specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node (type pointer,
|
|
Packit |
4a16fb |
* id "pcm_handle").
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func private_pcm_subdevice
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
|
|
Packit |
4a16fb |
snd_config_t *src, snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_pcm_info_t info = {0};
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
const void *data;
|
|
Packit |
4a16fb |
snd_pcm_t *pcm;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
if (private_data == NULL)
|
|
Packit |
4a16fb |
return snd_config_copy(dst, src);
|
|
Packit |
4a16fb |
err = snd_config_test_id(private_data, "pcm_handle");
|
|
Packit |
4a16fb |
if (err) {
|
|
Packit |
4a16fb |
SNDERR("field pcm_handle not found");
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_pointer(private_data, &data);
|
|
Packit |
4a16fb |
pcm = (snd_pcm_t *)data;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("field pcm_handle is not a pointer");
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_pcm_info(pcm, &info;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_imake_integer(dst, id,
|
|
Packit |
4a16fb |
snd_pcm_info_get_subdevice(&info));
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_private_pcm_subdevice, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#endif /* BUILD_PCM */
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
/**
|
|
Packit |
4a16fb |
* \brief Copies the specified configuration node.
|
|
Packit |
4a16fb |
* \param dst The function puts the handle to the result configuration node
|
|
Packit |
4a16fb |
* (with the same type as the specified node) at the address
|
|
Packit |
4a16fb |
* specified by \p dst.
|
|
Packit |
4a16fb |
* \param root Handle to the root source node.
|
|
Packit |
4a16fb |
* \param src Handle to the source node, with definitions for \c name and
|
|
Packit |
4a16fb |
* (optionally) \c file.
|
|
Packit |
4a16fb |
* \param private_data Handle to the \c private_data node.
|
|
Packit |
4a16fb |
* \return A non-negative value if successful, otherwise a negative error code.
|
|
Packit |
4a16fb |
* \note The root source node can be modified!
|
|
Packit |
4a16fb |
*
|
|
Packit |
4a16fb |
* Example:
|
|
Packit |
4a16fb |
\code
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
@func refer
|
|
Packit |
4a16fb |
file "/etc/myconf.conf" # optional
|
|
Packit |
4a16fb |
name "id1.id2.id3"
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
\endcode
|
|
Packit |
4a16fb |
*/
|
|
Packit |
4a16fb |
int snd_func_refer(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
|
Packit |
4a16fb |
snd_config_t *private_data)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
snd_config_t *n;
|
|
Packit |
4a16fb |
const char *file = NULL, *name = NULL;
|
|
Packit |
4a16fb |
int err;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
err = snd_config_search(src, "file", &n);
|
|
Packit |
4a16fb |
if (err >= 0) {
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating file");
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_string(n, &file;;
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("file is not a string");
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_search(src, "name", &n);
|
|
Packit |
4a16fb |
if (err >= 0) {
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("error evaluating name");
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_get_string(n, &name);
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("name is not a string");
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (!name) {
|
|
Packit |
4a16fb |
err = -EINVAL;
|
|
Packit |
4a16fb |
SNDERR("name is not specified");
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (file) {
|
|
Packit |
4a16fb |
snd_input_t *input;
|
|
Packit |
4a16fb |
err = snd_input_stdio_open(&input, file, "r");
|
|
Packit |
4a16fb |
if (err < 0) {
|
|
Packit |
4a16fb |
SNDERR("Unable to open file %s: %s", file, snd_strerror(err));
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_load(root, input);
|
|
Packit |
4a16fb |
snd_input_close(input);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
goto _end;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
err = snd_config_search_definition(root, NULL, name, dst);
|
|
Packit |
4a16fb |
if (err >= 0) {
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
err = snd_config_get_id(src, &id;;
|
|
Packit |
4a16fb |
if (err >= 0)
|
|
Packit |
4a16fb |
err = snd_config_set_id(*dst, id);
|
|
Packit |
4a16fb |
} else {
|
|
Packit |
4a16fb |
err = snd_config_search(src, "default", &n);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
SNDERR("Unable to find definition '%s'", name);
|
|
Packit |
4a16fb |
else {
|
|
Packit |
4a16fb |
const char *id;
|
|
Packit |
4a16fb |
err = snd_config_evaluate(n, root, private_data, NULL);
|
|
Packit |
4a16fb |
if (err < 0)
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
if ((err = snd_config_copy(dst, n)) >= 0) {
|
|
Packit |
4a16fb |
if ((err = snd_config_get_id(src, &id)) < 0 ||
|
|
Packit |
4a16fb |
(err = snd_config_set_id(*dst, id)) < 0)
|
|
Packit |
4a16fb |
snd_config_delete(*dst);
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
_end:
|
|
Packit |
4a16fb |
return err;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(snd_func_refer, SND_CONFIG_DLSYM_VERSION_EVALUATE);
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#ifndef DOC_HIDDEN
|
|
Packit |
4a16fb |
int _snd_conf_generic_id(const char *id)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
static const char ids[3][8] = { "comment", "type", "hint" };
|
|
Packit |
4a16fb |
unsigned int k;
|
|
Packit |
4a16fb |
for (k = 0; k < sizeof(ids) / sizeof(ids[0]); ++k) {
|
|
Packit |
4a16fb |
if (strcmp(id, ids[k]) == 0)
|
|
Packit |
4a16fb |
return 1;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
#endif
|