source: roaraudio/libroar/vio_stack.c @ 3063:955233719a84

Last change on this file since 3063:955233719a84 was 3063:955233719a84, checked in by phi, 14 years ago

use memory functions from libroar, not libc, fixed a small memory leak

File size: 4.6 KB
Line 
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
37int     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 = roar_mm_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->ctl      = roar_vio_stack_ctl;
52 calls->read     = roar_vio_stack_read;
53 calls->write    = roar_vio_stack_write;
54 calls->lseek    = roar_vio_stack_lseek;
55 calls->nonblock = roar_vio_stack_nonblock;
56 calls->sync     = roar_vio_stack_sync;
57
58 return 0;
59}
60
61int     roar_vio_stack_add     (struct roar_vio_calls * calls, struct roar_vio_calls * vio) {
62 struct roar_vio_stack * self;
63
64 if ( calls == NULL || vio == NULL )
65  return -1;
66
67 if ( (self = calls->inst) == NULL )
68  return -1;
69
70 if ( self->next == ROAR_VIO_STACK_MAX )
71  return -1;
72
73 self->cur = self->calls[self->next++] = vio;
74
75 return 0;
76}
77
78int     roar_vio_stack_close   (struct roar_vio_calls * vio) {
79 struct roar_vio_stack * self;
80 int i;
81
82 if ( vio == NULL )
83  return -1;
84
85 if ( (self = vio->inst) == NULL )
86  return -1;
87
88 if ( self->cur != NULL ) {
89  if ( roar_vio_close(self->cur) == -1 )
90   return -1;
91
92  for (i = 0; i < self->next; i++)
93   free(self->calls[i]);
94 }
95
96 roar_mm_free(self);
97
98 return 0;
99}
100
101int     roar_vio_stack_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
102 if (vio == NULL || cmd == -1)
103  return -1;
104
105 switch (cmd) {
106  case ROAR_VIO_CTL_GET_FH:
107  case ROAR_VIO_CTL_GET_READ_FH:
108  case ROAR_VIO_CTL_GET_WRITE_FH:
109  case ROAR_VIO_CTL_SELECT:
110    return roar_vio_ctl(((struct roar_vio_stack*)(vio->inst))->cur, cmd, data);
111   break;
112 }
113
114 return -1;
115}
116
117
118ssize_t roar_vio_stack_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
119 if ( vio == NULL )
120  return -1;
121
122 if ( vio->inst == NULL )
123  return -1;
124
125 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
126  return -1;
127
128 return roar_vio_read(((struct roar_vio_stack*)(vio->inst))->cur, buf, count);
129}
130
131ssize_t roar_vio_stack_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
132 if ( vio == NULL )
133  return -1;
134
135 if ( vio->inst == NULL )
136  return -1;
137
138 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
139  return -1;
140
141 return roar_vio_write(((struct roar_vio_stack*)(vio->inst))->cur, buf, count);
142}
143
144off_t   roar_vio_stack_lseek   (struct roar_vio_calls * vio, off_t offset, int whence) {
145 if ( vio == NULL )
146  return -1;
147
148 if ( vio->inst == NULL )
149  return -1;
150
151 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
152  return -1;
153
154 return roar_vio_lseek(((struct roar_vio_stack*)(vio->inst))->cur, offset, whence);
155}
156
157int     roar_vio_stack_nonblock(struct roar_vio_calls * vio, int state) {
158 if ( vio == NULL )
159  return -1;
160
161 if ( vio->inst == NULL )
162  return -1;
163
164 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
165  return -1;
166
167 return roar_vio_nonblock(((struct roar_vio_stack*)(vio->inst))->cur, state);
168}
169
170int     roar_vio_stack_sync    (struct roar_vio_calls * vio) {
171 if ( vio == NULL )
172  return -1;
173
174 if ( vio->inst == NULL )
175  return -1;
176
177 if ( ((struct roar_vio_stack*)(vio->inst))->cur == NULL )
178  return -1;
179
180 return roar_vio_sync(((struct roar_vio_stack*)(vio->inst))->cur);
181}
182
183//ll
Note: See TracBrowser for help on using the repository browser.