source: roaraudio/libroar/vio_jumbo.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

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