[2122] | 1 | //driver.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012 |
---|
[2122] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[2122] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <roaraudio.h> |
---|
| 27 | #include "driver.h" |
---|
[2348] | 28 | #include "autodetected.h" |
---|
| 29 | |
---|
| 30 | #ifdef ROAR_HAVE_AD_ESDFW |
---|
| 31 | #include "driver_esdfw.h" |
---|
| 32 | #endif |
---|
[2122] | 33 | |
---|
[5615] | 34 | static int roar_cdriver_null(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir, struct roar_keyval * para, ssize_t paralen) { |
---|
[2130] | 35 | ROAR_DBG("roar_cdriver_null(calls=%p, name='%s', dev='%s', info=%p{...}, dir=%i(?)) = ?", calls, name, dev, info, dir); |
---|
| 36 | |
---|
[5615] | 37 | (void)name, (void)dev, (void)info, (void)dir, (void)para, (void)paralen; |
---|
[5270] | 38 | |
---|
[2130] | 39 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
[5388] | 40 | calls->flags = ROAR_VIO_FLAGS_NONE; |
---|
| 41 | calls->refc = 1; |
---|
[2130] | 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 | |
---|
[5615] | 49 | struct { |
---|
| 50 | const char * name; |
---|
| 51 | int (*open)(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir); |
---|
| 52 | int (*open2)(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir, struct roar_keyval * para, ssize_t paralen); |
---|
| 53 | } _g_roar_cdriver[] = { |
---|
| 54 | {"null", NULL, roar_cdriver_null}, |
---|
| 55 | {"roar", roar_cdriver_roar, NULL}, |
---|
[2219] | 56 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
[5615] | 57 | {"oss", roar_cdriver_oss, NULL}, |
---|
[2219] | 58 | #endif |
---|
[2348] | 59 | #ifdef ROAR_HAVE_AD_ESDFW |
---|
| 60 | #include "driver_esdfw.c" |
---|
| 61 | #endif |
---|
[5615] | 62 | {NULL, NULL, NULL} |
---|
[2123] | 63 | }; |
---|
| 64 | |
---|
[4604] | 65 | |
---|
[5615] | 66 | static int roar_cdriver_open_default(struct roar_vio_calls * calls, const char * dev, struct roar_audio_info * info, int dir, struct roar_keyval * para, ssize_t paralen) { |
---|
[4604] | 67 | const char * names[] = { |
---|
| 68 | // native APIs: |
---|
| 69 | "oss", |
---|
| 70 | // Virtual APIs: |
---|
| 71 | "roar", |
---|
| 72 | // Dummys: |
---|
| 73 | "null" |
---|
| 74 | }; |
---|
| 75 | size_t i; |
---|
| 76 | int ret; |
---|
| 77 | |
---|
| 78 | if ( dev != NULL ) { |
---|
| 79 | 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); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | for (i = 0; i < (sizeof(names)/sizeof(*names)); i++) { |
---|
[5615] | 83 | ret = roar_cdriver_open2(calls, names[i], dev, info, dir, para, paralen); |
---|
[4604] | 84 | if ( ret != -1 ) |
---|
| 85 | return ret; |
---|
| 86 | } |
---|
| 87 | |
---|
[5615] | 88 | // roar_error is still set to the error of the last tested driver. |
---|
[4604] | 89 | return -1; |
---|
| 90 | } |
---|
| 91 | |
---|
[5616] | 92 | int roar_cdriver_open2(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir, struct roar_keyval * para, ssize_t paralen) { |
---|
[2123] | 93 | int i; |
---|
[2349] | 94 | char *delm; |
---|
[2123] | 95 | |
---|
[4604] | 96 | if ( name == NULL ) |
---|
[5615] | 97 | return roar_cdriver_open_default(calls, dev, info, dir, para, paralen); |
---|
[4604] | 98 | |
---|
[2123] | 99 | for (i = 0; _g_roar_cdriver[i].name != NULL; i++) { |
---|
[2348] | 100 | ROAR_DBG("roar_cdriver_open(*): _g_roar_cdriver[i].name='%s' <cmp> name='%s'", _g_roar_cdriver[i].name, name); |
---|
[2349] | 101 | |
---|
[5615] | 102 | if ( !strcmp(_g_roar_cdriver[i].name, name) ) { |
---|
| 103 | if ( _g_roar_cdriver[i].open2 != NULL ) |
---|
| 104 | return _g_roar_cdriver[i].open2(calls, name, dev, info, dir, para, paralen); |
---|
| 105 | if ( _g_roar_cdriver[i].open != NULL ) |
---|
| 106 | return _g_roar_cdriver[i].open(calls, name, dev, info, dir); |
---|
| 107 | } |
---|
[2349] | 108 | |
---|
| 109 | if ( (delm = strstr(_g_roar_cdriver[i].name, ":")) != NULL ) { |
---|
| 110 | ROAR_DBG("roar_cdriver_open(*): delm+1='%s' <cmp> name='%s'", delm+1, name); |
---|
[5615] | 111 | if ( !strcmp(delm+1, name) ) { |
---|
| 112 | if ( _g_roar_cdriver[i].open2 != NULL ) |
---|
| 113 | return _g_roar_cdriver[i].open2(calls, name, dev, info, dir, para, paralen); |
---|
| 114 | if ( _g_roar_cdriver[i].open != NULL ) |
---|
| 115 | return _g_roar_cdriver[i].open(calls, name, dev, info, dir); |
---|
| 116 | } |
---|
[2349] | 117 | } |
---|
| 118 | |
---|
[2123] | 119 | } |
---|
| 120 | |
---|
[5615] | 121 | roar_err_set(ROAR_ERROR_NOENT); |
---|
[2123] | 122 | return -1; |
---|
| 123 | } |
---|
| 124 | |
---|
[5626] | 125 | ssize_t roar_cdriver_list (const char ** list, size_t len, size_t offset) { |
---|
[5615] | 126 | size_t i; |
---|
| 127 | size_t idx = 0; |
---|
| 128 | |
---|
| 129 | if ( list == NULL ) { |
---|
| 130 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 131 | return -1; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | if ( len == 0 ) |
---|
| 135 | return 0; |
---|
| 136 | |
---|
| 137 | if ( offset >= (sizeof(_g_roar_cdriver)/sizeof(*_g_roar_cdriver)) ) |
---|
| 138 | return 0; |
---|
| 139 | |
---|
| 140 | for (i = offset; _g_roar_cdriver[i].name != NULL; i++) { |
---|
| 141 | list[idx++] = _g_roar_cdriver[i].name; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | return idx; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | int roar_cdriver_open(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir) { |
---|
| 148 | return roar_cdriver_open2(calls, name, dev, info, dir, NULL, -1); |
---|
| 149 | } |
---|
| 150 | |
---|
[2122] | 151 | //ll |
---|