source: roaraudio/libroar/vio_jumbo.c @ 2985:db2cf63584bc

Last change on this file since 2985:db2cf63584bc was 2985:db2cf63584bc, checked in by phi, 15 years ago

wrote the jumbo layer

File size: 4.0 KB
Line 
1//vio_jumbo.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_jumbo    (struct roar_vio_calls * calls, struct roar_vio_calls * vio, size_t buffersize) {
38 struct roar_vio_jumbo * self;
39
40 if ( (self = roar_mm_malloc(sizeof(struct roar_vio_jumbo))) == NULL ) {
41  return -1;
42 }
43
44 memset(self, 0, sizeof(struct roar_vio_jumbo));
45
46 self->backend = vio;
47
48 if ( roar_buffer_new(&(self->buffer), buffersize) == -1 ) {
49  roar_mm_free(self);
50  return -1;
51 }
52
53 memset(calls, 0, sizeof(struct roar_vio_calls));
54 calls->inst     = self;
55 calls->close    = roar_vio_jumbo_close;
56 calls->read     = roar_vio_jumbo_read;
57 calls->write    = roar_vio_jumbo_write;
58 calls->lseek    = roar_vio_jumbo_lseek;
59 calls->nonblock = roar_vio_jumbo_nonblock;
60 calls->sync     = roar_vio_jumbo_sync;
61 calls->ctl      = roar_vio_jumbo_ctl;
62
63 return 0;
64}
65
66int     roar_vio_jumbo_close   (struct roar_vio_calls * vio) {
67 struct roar_vio_jumbo * self = vio->inst;
68
69 if ( roar_vio_jumbo_sync(vio) == -1 )
70  return -1;
71
72 roar_buffer_free(self->buffer);
73 roar_mm_free(self);
74
75 return 0;
76}
77
78ssize_t roar_vio_jumbo_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
79 struct roar_vio_jumbo * self = vio->inst;
80
81 return roar_vio_read(self->backend, buf, count);
82}
83
84ssize_t roar_vio_jumbo_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
85 struct roar_vio_jumbo * self = vio->inst;
86 size_t   buflen;
87 void   * data;
88
89 if ( roar_buffer_get_len(self->buffer, &buflen) == -1 )
90  return -1;
91
92 if ( roar_buffer_get_data(self->buffer, &data) == -1 )
93  return -1;
94
95 if ( (self->pos + count) > buflen ) {
96  if ( roar_vio_jumbo_sync(vio) == -1 )
97   return -1;
98
99  memcpy(data, buf, count);
100  self->pos = count;
101 } else {
102  memcpy(data + self->pos, buf, count);
103  self->pos += count;
104 }
105
106 return 0;
107}
108
109off_t   roar_vio_jumbo_lseek   (struct roar_vio_calls * vio, off_t offset, int whence) {
110 struct roar_vio_jumbo * self = vio->inst;
111
112 if ( roar_vio_jumbo_sync(vio) == -1 )
113  return (off_t) -1;
114
115 return roar_vio_lseek(self->backend, offset, whence);
116}
117
118int     roar_vio_jumbo_nonblock(struct roar_vio_calls * vio, int state) {
119 struct roar_vio_jumbo * self = vio->inst;
120
121 return roar_vio_nonblock(self->backend, state);
122}
123
124int     roar_vio_jumbo_sync    (struct roar_vio_calls * vio) {
125 struct roar_vio_jumbo * self = vio->inst;
126 void                  * data;
127
128 if ( self->pos == 0 )
129  return 0;
130
131 if ( roar_buffer_get_data(self->buffer, &data) == -1 )
132  return -1;
133
134 // TODO: do this a bit more intelergent (RE?)
135 if ( roar_vio_write(self->backend, data, self->pos) != self->pos )
136  return -1;
137
138 self->pos = 0;
139
140 return 0;
141}
142
143int     roar_vio_jumbo_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
144 return -1;
145}
146
147//ll
Note: See TracBrowser for help on using the repository browser.