3 * \ingroup Configuration
4 * \brief Configuration helper functions
5 * \author Abramo Bagnara <abramo@alsa-project.org>
6 * \author Jaroslav Kysela <perex@perex.cz>
9 * Configuration helper functions.
11 * See the \ref conffunc page for more details.
14 * Miscellaneous configuration helper functions
15 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>,
16 * Jaroslav Kysela <perex@perex.cz>
19 * This library is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as
21 * published by the Free Software Foundation; either version 2.1 of
22 * the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 \section conffunc_ref Function reference
40 <LI>The getenv function - snd_func_getenv() - obtains
41 an environment value. The result is a string.
42 <LI>The igetenv function - snd_func_igetenv() - obtains
43 an environment value. The result is an integer.
44 <LI>The concat function - snd_func_concat() - merges all specified
45 strings. The result is a string.
46 <LI>The iadd function - snd_func_iadd() - sum all specified integers.
47 The result is an integer.
48 <LI>The imul function - snd_func_imul() - multiply all specified integers.
49 The result is an integer.
50 <LI>The datadir function - snd_func_datadir() - returns the
51 ALSA data directory. The result is a string.
52 <LI>The refer function - snd_func_refer() - copies the referred
53 configuration. The result has the same type as the referred node.
54 <LI>The card_inum function - snd_func_card_inum() - returns
55 a card number (integers).
56 <LI>The card_driver function - snd_func_card_driver() - returns
57 a driver identification. The result is a string.
58 <LI>The card_id function - snd_func_card_id() - returns
59 a card identification. The result is a string.
60 <LI>The card_name function - snd_func_card_name() - returns
61 a card's name. The result is a string.
62 <LI>The pcm_id function - snd_func_pcm_id() - returns
63 a pcm identification. The result is a string.
64 <LI>The private_string function - snd_func_private_string() - returns the
65 string from the private_data node.
66 <LI>The private_card_driver function - snd_func_private_card_driver() -
67 returns the driver identification from the private_data node.
68 The result is a string.
69 <LI>The private_pcm_subdevice function - snd_func_private_pcm_subdevice() -
70 returns the PCM subdevice number from the private_data node.
71 The result is a string.
84 * \brief Gets the boolean value from the given ASCII string.
85 * \param ascii The string to be parsed.
86 * \return 0 or 1 if successful, otherwise a negative error code.
88 int snd_config_get_bool_ascii(const char *ascii)
104 for (k = 0; k < sizeof(b) / sizeof(*b); k++) {
105 if (strcasecmp(b[k].str, ascii) == 0)
112 * \brief Gets the boolean value from a configuration node.
113 * \param conf Handle to the configuration node to be parsed.
114 * \return 0 or 1 if successful, otherwise a negative error code.
116 int snd_config_get_bool(const snd_config_t *conf)
119 const char *str, *id;
122 err = snd_config_get_id(conf, &id);
125 err = snd_config_get_integer(conf, &v);
127 if (v < 0 || v > 1) {
129 SNDERR("Invalid value for %s", id);
134 err = snd_config_get_string(conf, &str);
136 SNDERR("Invalid type for %s", id);
139 err = snd_config_get_bool_ascii(str);
146 * \brief Gets the control interface index from the given ASCII string.
147 * \param ascii The string to be parsed.
148 * \return The control interface index if successful, otherwise a negative error code.
150 int snd_config_get_ctl_iface_ascii(const char *ascii)
153 snd_ctl_elem_iface_t idx;
154 if (isdigit(ascii[0])) {
155 if (safe_strtol(ascii, &v) >= 0) {
156 if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST)
161 for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++) {
162 if (strcasecmp(snd_ctl_elem_iface_name(idx), ascii) == 0)
169 * \brief Gets the control interface index from a configuration node.
170 * \param conf Handle to the configuration node to be parsed.
171 * \return The control interface index if successful, otherwise a negative error code.
173 int snd_config_get_ctl_iface(const snd_config_t *conf)
176 const char *str, *id;
179 err = snd_config_get_id(conf, &id);
182 err = snd_config_get_integer(conf, &v);
184 if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST) {
186 SNDERR("Invalid value for %s", id);
191 err = snd_config_get_string(conf, &str);
193 SNDERR("Invalid type for %s", id);
196 err = snd_config_get_ctl_iface_ascii(str);
203 * Helper functions for the configuration file
207 * \brief Returns an environment value.
208 * \param dst The function puts the handle to the result configuration node
209 * (with type string) at the address specified by \p dst.
210 * \param root Handle to the root source node.
211 * \param src Handle to the source node, with definitions for \c vars and
213 * \param private_data Handle to the \c private_data node.
214 * \return Zero if successful, otherwise a negative error code.
220 vars [ MY_CARD CARD C ]
225 int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
226 snd_config_t *private_data)
229 snd_config_iterator_t i, next;
230 const char *res, *id;
232 int idx = 0, err, hit;
234 err = snd_config_search(src, "vars", &n);
236 SNDERR("field vars not found");
239 err = snd_config_evaluate(n, root, private_data, NULL);
241 SNDERR("error evaluating vars");
244 err = snd_config_search(src, "default", &d);
246 SNDERR("field default not found");
249 err = snd_config_evaluate(d, root, private_data, NULL);
251 SNDERR("error evaluating default");
254 err = snd_config_get_ascii(d, &def);
256 SNDERR("error getting field default");
261 snd_config_for_each(i, next, n) {
262 snd_config_t *n = snd_config_iterator_entry(i);
265 if (snd_config_get_id(n, &id) < 0)
267 if (snd_config_get_type(n) != SND_CONFIG_TYPE_STRING) {
268 SNDERR("field %s is not a string", id);
272 err = safe_strtol(id, &i);
274 SNDERR("id of field %s is not an integer", id);
280 err = snd_config_get_string(n, &ptr);
282 SNDERR("invalid string for id %s", id);
287 if (res != NULL && *res != '\0')
295 err = snd_config_get_id(src, &id);
297 err = snd_config_imake_string(dst, id, res);
303 SND_DLSYM_BUILD_VERSION(snd_func_getenv, SND_CONFIG_DLSYM_VERSION_EVALUATE);
307 * \brief Returns an integer environment value.
308 * \param dst The function puts the handle to the result configuration node
309 * (with type integer) at the address specified by \p dst.
310 * \param root Handle to the root source node.
311 * \param src Handle to the source node, with definitions for \c vars and
313 * \param private_data Handle to the \c private_data node.
314 * \return Zero if successful, otherwise a negative error code.
320 vars [ MY_DEVICE DEVICE D ]
325 int snd_func_igetenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
326 snd_config_t *private_data)
329 const char *str, *id;
333 err = snd_func_getenv(&d, root, src, private_data);
336 err = snd_config_get_string(d, &str);
338 snd_config_delete(d);
341 err = safe_strtol(str, &v);
343 snd_config_delete(d);
346 snd_config_delete(d);
347 err = snd_config_get_id(src, &id);
350 err = snd_config_imake_integer(dst, id, v);
356 SND_DLSYM_BUILD_VERSION(snd_func_igetenv, SND_CONFIG_DLSYM_VERSION_EVALUATE);
360 * \brief Merges the given strings.
361 * \param dst The function puts the handle to the result configuration node
362 * (with type string) at the address specified by \p dst.
363 * \param root Handle to the root source node.
364 * \param src Handle to the source node, with a definition for \c strings.
365 * \param private_data Handle to the \c private_data node.
366 * \return A non-negative value if successful, otherwise a negative error code.
368 * Example (result is "a1b2c3"):
372 strings [ "a1" "b2" "c3" ]
376 int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
377 snd_config_t *private_data)
380 snd_config_iterator_t i, next;
382 char *res = NULL, *tmp;
383 int idx = 0, len = 0, len1, err, hit;
385 err = snd_config_search(src, "strings", &n);
387 SNDERR("field strings not found");
390 err = snd_config_evaluate(n, root, private_data, NULL);
392 SNDERR("error evaluating strings");
397 snd_config_for_each(i, next, n) {
398 snd_config_t *n = snd_config_iterator_entry(i);
402 if (snd_config_get_id(n, &id) < 0)
404 err = safe_strtol(id, &i);
406 SNDERR("id of field %s is not an integer", id);
412 err = snd_config_get_ascii(n, &ptr);
414 SNDERR("invalid ascii string for id %s", id);
419 tmp = realloc(res, len + len1 + 1);
426 memcpy(tmp + len, ptr, len1);
436 SNDERR("empty string is not accepted");
440 err = snd_config_get_id(src, &id);
442 err = snd_config_imake_string(dst, id, res);
448 SND_DLSYM_BUILD_VERSION(snd_func_concat, SND_CONFIG_DLSYM_VERSION_EVALUATE);
452 static int snd_func_iops(snd_config_t **dst,
455 snd_config_t *private_data,
459 snd_config_iterator_t i, next;
462 long result = 0, val;
463 int idx = 0, err, hit;
465 err = snd_config_search(src, "integers", &n);
467 SNDERR("field integers not found");
470 err = snd_config_evaluate(n, root, private_data, NULL);
472 SNDERR("error evaluating integers");
477 snd_config_for_each(i, next, n) {
478 snd_config_t *n = snd_config_iterator_entry(i);
481 if (snd_config_get_id(n, &id) < 0)
483 err = safe_strtol(id, &i);
485 SNDERR("id of field %s is not an integer", id);
491 err = snd_config_get_integer(n, &val);
493 SNDERR("invalid integer for id %s", id);
498 case 0: result += val; break;
499 case 1: result *= val; break;
505 err = snd_config_get_id(src, &id);
507 err = snd_config_imake_integer(dst, id, result);
515 * \brief Sum the given integers.
516 * \param dst The function puts the handle to the result configuration node
517 * (with type integer) at the address specified by \p dst.
518 * \param root Handle to the root source node.
519 * \param src Handle to the source node, with a definition for \c integers.
520 * \param private_data Handle to the \c private_data node.
521 * \return A non-negative value if successful, otherwise a negative error code.
523 * Example (result is 10):
531 int snd_func_iadd(snd_config_t **dst, snd_config_t *root,
532 snd_config_t *src, snd_config_t *private_data)
534 return snd_func_iops(dst, root, src, private_data, 0);
537 SND_DLSYM_BUILD_VERSION(snd_func_iadd, SND_CONFIG_DLSYM_VERSION_EVALUATE);
541 * \brief Multiply the given integers.
542 * \param dst The function puts the handle to the result configuration node
543 * (with type integer) at the address specified by \p dst.
544 * \param root Handle to the root source node.
545 * \param src Handle to the source node, with a definition for \c integers.
546 * \param private_data Handle to the \c private_data node.
547 * \return A non-negative value if successful, otherwise a negative error code.
549 * Example (result is 12):
557 int snd_func_imul(snd_config_t **dst, snd_config_t *root,
558 snd_config_t *src, snd_config_t *private_data)
560 return snd_func_iops(dst, root, src, private_data, 1);
563 SND_DLSYM_BUILD_VERSION(snd_func_imul, SND_CONFIG_DLSYM_VERSION_EVALUATE);
567 * \brief Returns the ALSA data directory.
568 * \param dst The function puts the handle to the result configuration node
569 * (with type string) at the address specified by \p dst.
570 * \param root Handle to the root source node.
571 * \param src Handle to the source node.
572 * \param private_data Handle to the \c private_data node. Not used.
573 * \return A non-negative value if successful, otherwise a negative error code.
575 * Example (result is "/usr/share/alsa" using the default paths):
582 int snd_func_datadir(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
583 snd_config_t *src, snd_config_t *private_data ATTRIBUTE_UNUSED)
588 err = snd_config_get_id(src, &id);
591 return snd_config_imake_string(dst, id, ALSA_CONFIG_DIR);
594 SND_DLSYM_BUILD_VERSION(snd_func_datadir, SND_CONFIG_DLSYM_VERSION_EVALUATE);
597 static int open_ctl(long card, snd_ctl_t **ctl)
600 snprintf(name, sizeof(name), "hw:%li", card);
601 name[sizeof(name)-1] = '\0';
602 return snd_ctl_open(ctl, name, 0);
606 static int string_from_integer(char **dst, long v)
610 sprintf(str, "%li", v);
620 * \brief Returns the string from \c private_data.
621 * \param dst The function puts the handle to the result configuration node
622 * (with type string) at the address specified by \p dst.
623 * \param root Handle to the root source node.
624 * \param src Handle to the source node.
625 * \param private_data Handle to the \c private_data node (type string,
627 * \return A non-negative value if successful, otherwise a negative error code.
636 int snd_func_private_string(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
637 snd_config_t *src, snd_config_t *private_data)
640 const char *str, *id;
642 if (private_data == NULL)
643 return snd_config_copy(dst, src);
644 err = snd_config_test_id(private_data, "string");
646 SNDERR("field string not found");
649 err = snd_config_get_string(private_data, &str);
651 SNDERR("field string is not a string");
654 err = snd_config_get_id(src, &id);
656 err = snd_config_imake_string(dst, id, str);
660 SND_DLSYM_BUILD_VERSION(snd_func_private_string, SND_CONFIG_DLSYM_VERSION_EVALUATE);
664 int snd_determine_driver(int card, char **driver)
666 snd_ctl_t *ctl = NULL;
667 snd_ctl_card_info_t *info;
671 assert(card >= 0 && card <= 32);
672 err = open_ctl(card, &ctl);
674 SNDERR("could not open control for card %i", card);
677 snd_ctl_card_info_alloca(&info);
678 err = snd_ctl_card_info(ctl, info);
680 SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
683 res = strdup(snd_ctl_card_info_get_driver(info));
698 * \brief Returns the driver identification from \c private_data.
699 * \param dst The function puts the handle to the result configuration node
700 * (with type string) at the address specified by \p dst.
701 * \param root Handle to the root source node.
702 * \param src Handle to the source node.
703 * \param private_data Handle to the \c private_data node (type integer,
705 * \return A non-negative value if successful, otherwise a negative error code.
710 @func private_card_driver
714 int snd_func_private_card_driver(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *src,
715 snd_config_t *private_data)
722 err = snd_config_test_id(private_data, "card");
724 SNDERR("field card not found");
727 err = snd_config_get_integer(private_data, &card);
729 SNDERR("field card is not an integer");
732 if ((err = snd_determine_driver(card, &driver)) < 0)
734 err = snd_config_get_id(src, &id);
736 err = snd_config_imake_string(dst, id, driver);
741 SND_DLSYM_BUILD_VERSION(snd_func_private_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE);
744 static int parse_card(snd_config_t *root, snd_config_t *src,
745 snd_config_t *private_data)
751 err = snd_config_search(src, "card", &n);
753 SNDERR("field card not found");
756 err = snd_config_evaluate(n, root, private_data, NULL);
758 SNDERR("error evaluating card");
761 err = snd_config_get_ascii(n, &str);
763 SNDERR("field card is not an integer or a string");
766 card = snd_card_get_index(str);
768 SNDERR("cannot find card '%s'", str);
774 * \brief Returns the card number as integer.
775 * \param dst The function puts the handle to the result configuration node
776 * (with type string) at the address specified by \p dst.
777 * \param root Handle to the root source node.
778 * \param src Handle to the source node, with a \c card definition.
779 * \param private_data Handle to the \c private_data node.
780 * \return A non-negative value if successful, otherwise a negative error code.
790 int snd_func_card_inum(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
791 snd_config_t *private_data)
796 card = parse_card(root, src, private_data);
799 err = snd_config_get_id(src, &id);
801 err = snd_config_imake_integer(dst, id, card);
805 SND_DLSYM_BUILD_VERSION(snd_func_card_inum, SND_CONFIG_DLSYM_VERSION_EVALUATE);
809 * \brief Returns the driver identification for a card.
810 * \param dst The function puts the handle to the result configuration node
811 * (with type string) at the address specified by \p dst.
812 * \param root Handle to the root source node.
813 * \param src Handle to the source node, with a \c card definition.
814 * \param private_data Handle to the \c private_data node.
815 * \return A non-negative value if successful, otherwise a negative error code.
825 int snd_func_card_driver(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
826 snd_config_t *private_data)
831 card = parse_card(root, src, private_data);
834 err = snd_config_imake_integer(&val, "card", card);
837 err = snd_func_private_card_driver(dst, root, src, val);
838 snd_config_delete(val);
842 SND_DLSYM_BUILD_VERSION(snd_func_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE);
846 * \brief Returns the identification of a card.
847 * \param dst The function puts the handle to the result configuration node
848 * (with type string) at the address specified by \p dst.
849 * \param root Handle to the root source node.
850 * \param src Handle to the source node, with a \c card definition.
851 * \param private_data Handle to the \c private_data node.
852 * \return A non-negative value if successful, otherwise a negative error code.
862 int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
863 snd_config_t *private_data)
865 snd_ctl_t *ctl = NULL;
866 snd_ctl_card_info_t *info;
870 card = parse_card(root, src, private_data);
873 err = open_ctl(card, &ctl);
875 SNDERR("could not open control for card %i", card);
878 snd_ctl_card_info_alloca(&info);
879 err = snd_ctl_card_info(ctl, info);
881 SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
884 err = snd_config_get_id(src, &id);
886 err = snd_config_imake_string(dst, id,
887 snd_ctl_card_info_get_id(info));
894 SND_DLSYM_BUILD_VERSION(snd_func_card_id, SND_CONFIG_DLSYM_VERSION_EVALUATE);
898 * \brief Returns the name of a card.
899 * \param dst The function puts the handle to the result configuration node
900 * (with type string) at the address specified by \p dst.
901 * \param root Handle to the root source node.
902 * \param src Handle to the source node, with a \c card definition.
903 * \param private_data Handle to the \c private_data node.
904 * \return A non-negative value if successful, otherwise a negative error code.
914 int snd_func_card_name(snd_config_t **dst, snd_config_t *root,
915 snd_config_t *src, snd_config_t *private_data)
917 snd_ctl_t *ctl = NULL;
918 snd_ctl_card_info_t *info;
922 card = parse_card(root, src, private_data);
925 err = open_ctl(card, &ctl);
927 SNDERR("could not open control for card %i", card);
930 snd_ctl_card_info_alloca(&info);
931 err = snd_ctl_card_info(ctl, info);
933 SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
936 err = snd_config_get_id(src, &id);
938 err = snd_config_imake_string(dst, id,
939 snd_ctl_card_info_get_name(info));
946 SND_DLSYM_BUILD_VERSION(snd_func_card_name, SND_CONFIG_DLSYM_VERSION_EVALUATE);
952 * \brief Returns the pcm identification of a device.
953 * \param dst The function puts the handle to the result configuration node
954 * (with type string) at the address specified by \p dst.
955 * \param root Handle to the root source node.
956 * \param src Handle to the source node, with definitions for \c card,
957 * \c device and (optionally) \c subdevice.
958 * \param private_data Handle to the \c private_data node.
959 * \return A non-negative value if successful, otherwise a negative error code.
967 subdevice 0 # optional
971 int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
974 snd_ctl_t *ctl = NULL;
975 snd_pcm_info_t *info;
977 long card, device, subdevice = 0;
980 card = parse_card(root, src, private_data);
983 err = snd_config_search(src, "device", &n);
985 SNDERR("field device not found");
988 err = snd_config_evaluate(n, root, private_data, NULL);
990 SNDERR("error evaluating device");
993 err = snd_config_get_integer(n, &device);
995 SNDERR("field device is not an integer");
998 if (snd_config_search(src, "subdevice", &n) >= 0) {
999 err = snd_config_evaluate(n, root, private_data, NULL);
1001 SNDERR("error evaluating subdevice");
1004 err = snd_config_get_integer(n, &subdevice);
1006 SNDERR("field subdevice is not an integer");
1010 err = open_ctl(card, &ctl);
1012 SNDERR("could not open control for card %li", card);
1015 snd_pcm_info_alloca(&info);
1016 snd_pcm_info_set_device(info, device);
1017 snd_pcm_info_set_subdevice(info, subdevice);
1018 err = snd_ctl_pcm_info(ctl, info);
1020 SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
1023 err = snd_config_get_id(src, &id);
1025 err = snd_config_imake_string(dst, id, snd_pcm_info_get_id(info));
1032 SND_DLSYM_BUILD_VERSION(snd_func_pcm_id, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1036 * \brief Returns the pcm card and device arguments (in form CARD=N,DEV=M)
1037 * for pcm specified by class and index.
1038 * \param dst The function puts the handle to the result configuration node
1039 * (with type string) at the address specified by \p dst.
1040 * \param root Handle to the root source node.
1041 * \param src Handle to the source node, with definitions for \c class
1043 * \param private_data Handle to the \c private_data node.
1044 * \return A non-negative value if successful, otherwise a negative error code.
1049 @func pcm_args_by_class
1055 int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
1058 snd_ctl_t *ctl = NULL;
1059 snd_pcm_info_t *info;
1066 err = snd_config_search(src, "class", &n);
1068 SNDERR("field class not found");
1071 err = snd_config_evaluate(n, root, private_data, NULL);
1073 SNDERR("error evaluating class");
1076 err = snd_config_get_integer(n, &class);
1078 SNDERR("field class is not an integer");
1081 err = snd_config_search(src, "index", &n);
1083 SNDERR("field index not found");
1086 err = snd_config_evaluate(n, root, private_data, NULL);
1088 SNDERR("error evaluating index");
1091 err = snd_config_get_integer(n, &index);
1093 SNDERR("field index is not an integer");
1097 snd_pcm_info_alloca(&info);
1099 err = snd_card_next(&card);
1101 SNDERR("could not get next card");
1106 err = open_ctl(card, &ctl);
1108 SNDERR("could not open control for card %i", card);
1112 memset(info, 0, snd_pcm_info_sizeof());
1114 err = snd_ctl_pcm_next_device(ctl, &dev);
1116 SNDERR("could not get next pcm for card %i", card);
1121 snd_pcm_info_set_device(info, dev);
1122 err = snd_ctl_pcm_info(ctl, info);
1125 if (snd_pcm_info_get_class(info) == (snd_pcm_class_t)class &&
1139 if((err = snd_config_get_id(src, &id)) >= 0) {
1141 snprintf(name, sizeof(name), "CARD=%i,DEV=%i", card, dev);
1142 err = snd_config_imake_string(dst, id, name);
1147 SND_DLSYM_BUILD_VERSION(snd_func_pcm_args_by_class, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1151 * \brief Returns the PCM subdevice from \c private_data.
1152 * \param dst The function puts the handle to the result configuration node
1153 * (with type integer) at the address specified by \p dst.
1154 * \param root Handle to the root source node.
1155 * \param src Handle to the source node.
1156 * \param private_data Handle to the \c private_data node (type pointer,
1158 * \return A non-negative value if successful, otherwise a negative error code.
1163 @func private_pcm_subdevice
1167 int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
1168 snd_config_t *src, snd_config_t *private_data)
1170 snd_pcm_info_t *info;
1176 if (private_data == NULL)
1177 return snd_config_copy(dst, src);
1178 err = snd_config_test_id(private_data, "pcm_handle");
1180 SNDERR("field pcm_handle not found");
1183 err = snd_config_get_pointer(private_data, &data);
1184 pcm = (snd_pcm_t *)data;
1186 SNDERR("field pcm_handle is not a pointer");
1189 snd_pcm_info_alloca(&info);
1190 err = snd_pcm_info(pcm, info);
1192 SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
1195 err = snd_config_get_id(src, &id);
1197 err = snd_config_imake_integer(dst, id, snd_pcm_info_get_subdevice(info));
1201 SND_DLSYM_BUILD_VERSION(snd_func_private_pcm_subdevice, SND_CONFIG_DLSYM_VERSION_EVALUATE);
1204 #endif /* BUILD_PCM */
1207 * \brief Copies the specified configuration node.
1208 * \param dst The function puts the handle to the result configuration node
1209 * (with the same type as the specified node) at the address
1210 * specified by \p dst.
1211 * \param root Handle to the root source node.
1212 * \param src Handle to the source node, with definitions for \c name and
1213 * (optionally) \c file.
1214 * \param private_data Handle to the \c private_data node.
1215 * \return A non-negative value if successful, otherwise a negative error code.
1216 * \note The root source node can be modified!
1222 file "/etc/myconf.conf" # optional
1227 int snd_func_refer(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
1228 snd_config_t *private_data)
1231 const char *file = NULL, *name = NULL;
1234 err = snd_config_search(src, "file", &n);
1236 err = snd_config_evaluate(n, root, private_data, NULL);
1238 SNDERR("error evaluating file");
1241 err = snd_config_get_string(n, &file);
1243 SNDERR("file is not a string");
1247 err = snd_config_search(src, "name", &n);
1249 err = snd_config_evaluate(n, root, private_data, NULL);
1251 SNDERR("error evaluating name");
1254 err = snd_config_get_string(n, &name);
1256 SNDERR("name is not a string");
1262 SNDERR("name is not specified");
1267 err = snd_input_stdio_open(&input, file, "r");
1269 SNDERR("Unable to open file %s: %s", file, snd_strerror(err));
1272 err = snd_config_load(root, input);
1273 snd_input_close(input);
1277 err = snd_config_search_definition(root, NULL, name, dst);
1280 err = snd_config_get_id(src, &id);
1282 err = snd_config_set_id(*dst, id);
1284 err = snd_config_search(src, "default", &n);
1286 SNDERR("Unable to find definition '%s'", name);
1289 err = snd_config_evaluate(n, root, private_data, NULL);
1292 if ((err = snd_config_copy(dst, n)) >= 0) {
1293 if ((err = snd_config_get_id(src, &id)) < 0 ||
1294 (err = snd_config_set_id(*dst, id)) < 0)
1295 snd_config_delete(*dst);
1303 SND_DLSYM_BUILD_VERSION(snd_func_refer, SND_CONFIG_DLSYM_VERSION_EVALUATE);