Home | History | Annotate | Line # | Download | only in audiocfg
main.c revision 1.1
      1  1.1  mrg /* $NetBSD: main.c,v 1.1 2010/08/30 02:19:47 mrg Exp $ */
      2  1.1  mrg 
      3  1.1  mrg /*
      4  1.1  mrg  * Copyright (c) 2010 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.1  mrg  * All rights reserved.
      6  1.1  mrg  *
      7  1.1  mrg  * Redistribution and use in source and binary forms, with or without
      8  1.1  mrg  * modification, are permitted provided that the following conditions
      9  1.1  mrg  * are met:
     10  1.1  mrg  * 1. Redistributions of source code must retain the above copyright
     11  1.1  mrg  *    notice, this list of conditions and the following disclaimer.
     12  1.1  mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  mrg  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  mrg  *    documentation and/or other materials provided with the distribution.
     15  1.1  mrg  *
     16  1.1  mrg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  mrg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  mrg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  mrg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  mrg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  mrg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  mrg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  mrg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  mrg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  mrg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  mrg  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  mrg  */
     28  1.1  mrg 
     29  1.1  mrg #include <errno.h>
     30  1.1  mrg #include <fcntl.h>
     31  1.1  mrg #include <limits.h>
     32  1.1  mrg #include <stdio.h>
     33  1.1  mrg #include <stdlib.h>
     34  1.1  mrg #include <unistd.h>
     35  1.1  mrg 
     36  1.1  mrg #include "audiodev.h"
     37  1.1  mrg #include "drvctl.h"
     38  1.1  mrg 
     39  1.1  mrg static void
     40  1.1  mrg usage(const char *p)
     41  1.1  mrg {
     42  1.1  mrg 	fprintf(stderr, "usage: %s [index]\n", p);
     43  1.1  mrg 	exit(EXIT_FAILURE);
     44  1.1  mrg }
     45  1.1  mrg 
     46  1.1  mrg int
     47  1.1  mrg main(int argc, char *argv[])
     48  1.1  mrg {
     49  1.1  mrg 	struct audiodev *adev;
     50  1.1  mrg 	unsigned int n, i;
     51  1.1  mrg 
     52  1.1  mrg 	if (audiodev_refresh() == -1)
     53  1.1  mrg 		return EXIT_FAILURE;
     54  1.1  mrg 
     55  1.1  mrg 	switch (argc) {
     56  1.1  mrg 	case 1:
     57  1.1  mrg 		n = audiodev_count();
     58  1.1  mrg 		for (i = 0; i < n; i++) {
     59  1.1  mrg 			adev = audiodev_get(i);
     60  1.1  mrg 			printf("%u: [%c] %s: %s\n",
     61  1.1  mrg 			    i, adev->defaultdev ? '*' : ' ',
     62  1.1  mrg 			    adev->xname, adev->audio_device.name);
     63  1.1  mrg 		}
     64  1.1  mrg 		break;
     65  1.1  mrg 	case 2:
     66  1.1  mrg 		if (*argv[1] < '0' || *argv[1] > '9')
     67  1.1  mrg 			usage(argv[0]);
     68  1.1  mrg 			/* NOTREACHED */
     69  1.1  mrg 		errno = 0;
     70  1.1  mrg 		i = strtoul(argv[1], NULL, 10);
     71  1.1  mrg 		if (errno)
     72  1.1  mrg 			usage(argv[0]);
     73  1.1  mrg 			/* NOTREACHED */
     74  1.1  mrg 		adev = audiodev_get(i);
     75  1.1  mrg 		if (adev == NULL) {
     76  1.1  mrg 			fprintf(stderr, "no such device\n");
     77  1.1  mrg 			return EXIT_FAILURE;
     78  1.1  mrg 		}
     79  1.1  mrg 		printf("setting default audio device to %s\n", adev->xname);
     80  1.1  mrg 		if (audiodev_set_default(adev) == -1) {
     81  1.1  mrg 			perror("couldn't set default device");
     82  1.1  mrg 			return EXIT_FAILURE;
     83  1.1  mrg 		}
     84  1.1  mrg 		break;
     85  1.1  mrg 	default:
     86  1.1  mrg 		usage(argv[0]);
     87  1.1  mrg 		/* NOTREACHED */
     88  1.1  mrg 	}
     89  1.1  mrg 
     90  1.1  mrg 	return EXIT_SUCCESS;
     91  1.1  mrg }
     92