1 | //driver.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012 |
---|
5 | * |
---|
6 | * This file is part of roarclients a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include <roaraudio.h> |
---|
27 | #include "driver.h" |
---|
28 | #include "autodetected.h" |
---|
29 | |
---|
30 | #ifdef ROAR_HAVE_AD_ESDFW |
---|
31 | #include "driver_esdfw.h" |
---|
32 | #endif |
---|
33 | |
---|
34 | int roar_cdriver_null(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir) { |
---|
35 | ROAR_DBG("roar_cdriver_null(calls=%p, name='%s', dev='%s', info=%p{...}, dir=%i(?)) = ?", calls, name, dev, info, dir); |
---|
36 | |
---|
37 | (void)name, (void)dev, (void)info, (void)dir; |
---|
38 | |
---|
39 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
40 | calls->flags = ROAR_VIO_FLAGS_NONE; |
---|
41 | calls->refc = 1; |
---|
42 | calls->read = roar_vio_null_rw; |
---|
43 | calls->write = roar_vio_null_rw; |
---|
44 | |
---|
45 | ROAR_DBG("roar_cdriver_null(calls=%p, name='%s', dev='%s', info=%p{...}, dir=%i(?)) = 0", calls, name, dev, info, dir); |
---|
46 | return 0; |
---|
47 | } |
---|
48 | |
---|
49 | struct roar_cdriver _g_roar_cdriver[] = { |
---|
50 | {"null", roar_cdriver_null}, |
---|
51 | {"roar", roar_cdriver_roar}, |
---|
52 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
53 | {"oss", roar_cdriver_oss}, |
---|
54 | #endif |
---|
55 | #ifdef ROAR_HAVE_AD_ESDFW |
---|
56 | #include "driver_esdfw.c" |
---|
57 | #endif |
---|
58 | {NULL, NULL} |
---|
59 | }; |
---|
60 | |
---|
61 | |
---|
62 | static int roar_cdriver_open_default(struct roar_vio_calls * calls, const char * dev, struct roar_audio_info * info, int dir) { |
---|
63 | const char * names[] = { |
---|
64 | // native APIs: |
---|
65 | "oss", |
---|
66 | // Virtual APIs: |
---|
67 | "roar", |
---|
68 | // Dummys: |
---|
69 | "null" |
---|
70 | }; |
---|
71 | size_t i; |
---|
72 | int ret; |
---|
73 | |
---|
74 | if ( dev != NULL ) { |
---|
75 | ROAR_WARN("roar_cdriver_open_default(calls=%p, dev='%s', info=%p, dir=%i): Try to open given device without driver name is a bad thing to do. This is normaly a Application error.", calls, dev, info, dir); |
---|
76 | } |
---|
77 | |
---|
78 | for (i = 0; i < (sizeof(names)/sizeof(*names)); i++) { |
---|
79 | ret = roar_cdriver_open(calls, names[i], dev, info, dir); |
---|
80 | if ( ret != -1 ) |
---|
81 | return ret; |
---|
82 | } |
---|
83 | |
---|
84 | return -1; |
---|
85 | } |
---|
86 | |
---|
87 | int roar_cdriver_open(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir) { |
---|
88 | int i; |
---|
89 | char *delm; |
---|
90 | |
---|
91 | if ( name == NULL ) |
---|
92 | return roar_cdriver_open_default(calls, dev, info, dir); |
---|
93 | |
---|
94 | for (i = 0; _g_roar_cdriver[i].name != NULL; i++) { |
---|
95 | ROAR_DBG("roar_cdriver_open(*): _g_roar_cdriver[i].name='%s' <cmp> name='%s'", _g_roar_cdriver[i].name, name); |
---|
96 | |
---|
97 | if ( !strcmp(_g_roar_cdriver[i].name, name) ) |
---|
98 | return _g_roar_cdriver[i].open(calls, name, dev, info, dir); |
---|
99 | |
---|
100 | if ( (delm = strstr(_g_roar_cdriver[i].name, ":")) != NULL ) { |
---|
101 | ROAR_DBG("roar_cdriver_open(*): delm+1='%s' <cmp> name='%s'", delm+1, name); |
---|
102 | if ( !strcmp(delm+1, name) ) |
---|
103 | return _g_roar_cdriver[i].open(calls, name, dev, info, dir); |
---|
104 | } |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | return -1; |
---|
109 | } |
---|
110 | |
---|
111 | //ll |
---|