source: roaraudio/libroar/vio_stack.c @ 4527:4b92f68e8956

Last change on this file since 4527:4b92f68e8956 was 4527:4b92f68e8956, checked in by phi, 14 years ago

implement ROAR_VIO_CTL_GET_NEXT

File size: 4.9 KB
Line 
1//vio_stack.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38int     roar_vio_open_stack    (struct roar_vio_calls * calls) {
39 struct roar_vio_stack * self;
40
41 if ( calls == NULL )
42  return -1;
43
44 if ( (self = roar_mm_malloc(sizeof(struct roar_vio_stack))) == NULL )
45  return -1;
46
47 memset(self,  0, sizeof(struct roar_vio_stack));
48 memset(calls, 0, sizeof(struct roar_vio_calls));
49
50 calls->inst     = self;
51 calls->close    = roar_vio_stack_close;
52 calls->ctl      = roar_vio_stack_ctl;
53 calls->read     = roar_vio_stack_read;
54 calls->write    = roar_vio_stack_write;
55 calls->lseek    = roar_vio_stack_lseek;
56 calls->nonblock = roar_vio_stack_nonblock;
57 calls->sync     = roar_vio_stack_sync;
58
59 return 0;
60}
61
62int     roar_vio_stack_add     (struct roar_vio_calls * calls, struct roar_vio_calls * vio) {
63 struct roar_vio_stack * self;
64
65 if ( calls == NULL || vio == NULL )
66  return -1;
67
68 if ( (self = calls->inst) == NULL )
69  return -1;
70
71 if ( self->next == ROAR_VIO_STACK_MAX )
72  return -1;
73
74 self->cur = self->calls[self->next++] = vio;
75
76 return 0;
77}
78
79int     roar_vio_stack_close   (struct roar_vio_calls * vio) {
80 struct roar_vio_stack * self;
81 int i;
82
83 if ( vio == NULL )
84  return -1;
85
86 if ( (self = vio->inst) == NULL )
87  return -1;
88
89 if ( self->cur != NULL ) {
90  if ( roar_vio_close(self->cur) == -1 )
91   return -1;
92
93  for (i = 0; i < self->next; i++)
94   free(self->calls[i]);
95 }
96
97 roar_mm_free(self);
98
99 return 0;
100}
101
102int     roar_vio_stack_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
103 if (vio == NULL || cmd == -1)
104  return -1;
105
106 switch (cmd) {
107  case ROAR_VIO_CTL_GET_NAME:
108    if ( data == NULL )
109     return -1;
110
111    *(char**)data = "stack";
112    return 0;
113   break;
114  case ROAR_VIO_CTL_GET_FH:
115  case ROAR_VIO_CTL_GET_READ_FH:
116  case ROAR_VIO_CTL_GET_WRITE_FH:
117  case ROAR_VIO_CTL_SELECT:
118    return roar_vio_ctl(((struct roar_vio_stack*)(vio->inst))->cur, cmd, data);
119   break;
120  case ROAR_VIO_CTL_GET_NEXT:
121    *(struct roar_vio_calls **)data = ((struct roar_vio_stack*)(vio->inst))->cur;
122    return 0;
123   break;
124 }
125
126 return roar_vio_ctl(((struct roar_vio_stack*)(vio->inst))->cur, cmd, data);
127}
128
129
130ssize_t roar_vio_stack_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
131 if ( vio == NULL )
132  return -1;
133
134 if ( vio->inst == NULL )
135  return -1;
136
137 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
138  return -1;
139
140 return roar_vio_read(((struct roar_vio_stack*)(vio->inst))->cur, buf, count);
141}
142
143ssize_t roar_vio_stack_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
144 if ( vio == NULL )
145  return -1;
146
147 if ( vio->inst == NULL )
148  return -1;
149
150 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
151  return -1;
152
153 return roar_vio_write(((struct roar_vio_stack*)(vio->inst))->cur, buf, count);
154}
155
156off_t   roar_vio_stack_lseek   (struct roar_vio_calls * vio, off_t offset, int whence) {
157 if ( vio == NULL )
158  return -1;
159
160 if ( vio->inst == NULL )
161  return -1;
162
163 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
164  return -1;
165
166 return roar_vio_lseek(((struct roar_vio_stack*)(vio->inst))->cur, offset, whence);
167}
168
169int     roar_vio_stack_nonblock(struct roar_vio_calls * vio, int state) {
170 if ( vio == NULL )
171  return -1;
172
173 if ( vio->inst == NULL )
174  return -1;
175
176 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
177  return -1;
178
179 return roar_vio_nonblock(((struct roar_vio_stack*)(vio->inst))->cur, state);
180}
181
182int     roar_vio_stack_sync    (struct roar_vio_calls * vio) {
183 if ( vio == NULL )
184  return -1;
185
186 if ( vio->inst == NULL )
187  return -1;
188
189 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
190  return -1;
191
192 return roar_vio_sync(((struct roar_vio_stack*)(vio->inst))->cur);
193}
194
195//ll
Note: See TracBrowser for help on using the repository browser.