[1326] | 1 | //vio_stack.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 5 | * |
---|
| 6 | * This file is part of libroar 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 | * libroar 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | * NOTE for everyone want's to change something and send patches: |
---|
| 24 | * read README and HACKING! There a addition information on |
---|
| 25 | * the license of this document you need to read before you send |
---|
| 26 | * any patches. |
---|
| 27 | * |
---|
| 28 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 29 | * or libpulse*: |
---|
| 30 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 31 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 32 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #include "libroar.h" |
---|
| 36 | |
---|
[1327] | 37 | int roar_vio_open_stack (struct roar_vio_calls * calls) { |
---|
| 38 | struct roar_vio_stack * self; |
---|
| 39 | |
---|
| 40 | if ( calls == NULL ) |
---|
| 41 | return -1; |
---|
| 42 | |
---|
| 43 | if ( (self = malloc(sizeof(struct roar_vio_stack))) == NULL ) |
---|
| 44 | return -1; |
---|
| 45 | |
---|
| 46 | memset(self, 0, sizeof(struct roar_vio_stack)); |
---|
| 47 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 48 | |
---|
| 49 | calls->inst = self; |
---|
| 50 | calls->close = roar_vio_stack_close; |
---|
| 51 | calls->read = roar_vio_stack_read; |
---|
| 52 | calls->write = roar_vio_stack_write; |
---|
| 53 | calls->lseek = roar_vio_stack_lseek; |
---|
| 54 | calls->nonblock = roar_vio_stack_nonblock; |
---|
| 55 | calls->sync = roar_vio_stack_sync; |
---|
| 56 | |
---|
| 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | int roar_vio_stack_add (struct roar_vio_calls * calls, struct roar_vio_calls * vio) { |
---|
| 61 | struct roar_vio_stack * self; |
---|
| 62 | |
---|
| 63 | if ( calls == NULL || vio == NULL ) |
---|
| 64 | return -1; |
---|
| 65 | |
---|
| 66 | if ( (self = calls->inst) == NULL ) |
---|
| 67 | return -1; |
---|
| 68 | |
---|
| 69 | if ( self->next == ROAR_VIO_STACK_MAX ) |
---|
| 70 | return -1; |
---|
| 71 | |
---|
| 72 | self->cur = self->calls[self->next++] = vio; |
---|
| 73 | |
---|
| 74 | return 0; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | int roar_vio_stack_close (struct roar_vio_calls * vio) { |
---|
| 78 | struct roar_vio_stack * self; |
---|
| 79 | int i; |
---|
| 80 | |
---|
| 81 | if ( vio == NULL ) |
---|
| 82 | return -1; |
---|
| 83 | |
---|
| 84 | if ( (self = vio->inst) == NULL ) |
---|
| 85 | return -1; |
---|
| 86 | |
---|
| 87 | if ( self->cur != NULL ) { |
---|
| 88 | if ( roar_vio_close(self->cur) == -1 ) |
---|
| 89 | return -1; |
---|
| 90 | |
---|
| 91 | for (i = 0; i < self->next; i++) |
---|
| 92 | free(self->calls[i]); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | free(self); |
---|
| 96 | |
---|
| 97 | return 0; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | ssize_t roar_vio_stack_read (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 101 | if ( vio == NULL ) |
---|
| 102 | return -1; |
---|
| 103 | |
---|
| 104 | if ( vio->inst == NULL ) |
---|
| 105 | return -1; |
---|
| 106 | |
---|
| 107 | if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL ) |
---|
| 108 | return -1; |
---|
| 109 | |
---|
| 110 | return roar_vio_read(((struct roar_vio_stack*)(vio->inst))->cur, buf, count); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | ssize_t roar_vio_stack_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 114 | if ( vio == NULL ) |
---|
| 115 | return -1; |
---|
| 116 | |
---|
| 117 | if ( vio->inst == NULL ) |
---|
| 118 | return -1; |
---|
| 119 | |
---|
| 120 | if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL ) |
---|
| 121 | return -1; |
---|
| 122 | |
---|
| 123 | return roar_vio_write(((struct roar_vio_stack*)(vio->inst))->cur, buf, count); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | off_t roar_vio_stack_lseek (struct roar_vio_calls * vio, off_t offset, int whence) { |
---|
| 127 | if ( vio == NULL ) |
---|
| 128 | return -1; |
---|
| 129 | |
---|
| 130 | if ( vio->inst == NULL ) |
---|
| 131 | return -1; |
---|
| 132 | |
---|
| 133 | if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL ) |
---|
| 134 | return -1; |
---|
| 135 | |
---|
| 136 | return roar_vio_lseek(((struct roar_vio_stack*)(vio->inst))->cur, offset, whence); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | int roar_vio_stack_nonblock(struct roar_vio_calls * vio, int state) { |
---|
| 140 | if ( vio == NULL ) |
---|
| 141 | return -1; |
---|
| 142 | |
---|
| 143 | if ( vio->inst == NULL ) |
---|
| 144 | return -1; |
---|
| 145 | |
---|
| 146 | if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL ) |
---|
| 147 | return -1; |
---|
| 148 | |
---|
| 149 | return roar_vio_nonblock(((struct roar_vio_stack*)(vio->inst))->cur, state); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | int roar_vio_stack_sync (struct roar_vio_calls * vio) { |
---|
| 153 | if ( vio == NULL ) |
---|
| 154 | return -1; |
---|
| 155 | |
---|
| 156 | if ( vio->inst == NULL ) |
---|
| 157 | return -1; |
---|
| 158 | |
---|
| 159 | if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL ) |
---|
| 160 | return -1; |
---|
| 161 | |
---|
| 162 | return roar_vio_sync(((struct roar_vio_stack*)(vio->inst))->cur); |
---|
| 163 | } |
---|
| 164 | |
---|
[1326] | 165 | //ll |
---|