source: roaraudio/roard/container_framework.c @ 2670:d3f4c73a13c3

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

call close callback

File size: 3.7 KB
Line 
1//container_framework.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *
6 *  This file is part of roard 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 *  RoarAudio 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 */
24
25#include "roard.h"
26
27#define _DECL()  struct cont_fw_child_vio_inst * inst
28#define _CHECK() if ( vio == NULL ) \
29                 return -1
30#define _CINST() if ( (inst = vio->inst) == NULL ) \
31                  return -1
32#define _PREP()  _CHECK(); \
33                 _CINST()
34#define _BASIC() _DECL();  \
35                 _PREP()
36
37// Parent:
38int     cont_fw_new     (struct cont_fw_parent_inst ** inst) {
39 struct cont_fw_parent_inst * self;
40
41 if ( inst == NULL )
42  return -1;
43
44 if ( (self = malloc(sizeof(struct cont_fw_parent_inst))) == NULL ) {
45  *inst = NULL;
46  return -1;
47 }
48
49 memset(self, 0, sizeof(struct cont_fw_parent_inst));
50
51 *inst = self;
52 return 0;
53}
54
55int     cont_fw_delete  (struct cont_fw_parent_inst  * inst) {
56 int i;
57
58 if ( inst == NULL )
59  return -1;
60
61 // check if there are streams to close...
62 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
63  if ( inst->child[i] != NULL ) {
64   return -1;
65  }
66 }
67
68 if ( inst->pcb.close != NULL )
69  inst->pcb.close(inst);
70
71 free(inst);
72
73 return 0;
74}
75
76int     cont_fw_set_uinst(struct cont_fw_parent_inst  * inst, void  * u_inst) {
77 if ( inst == NULL )
78  return -1;
79
80 inst->u_inst = u_inst;
81
82 return 0;
83}
84
85int     cont_fw_get_uinst(struct cont_fw_parent_inst  * inst, void ** u_inst) {
86 if ( inst == NULL || u_inst == NULL )
87  return -1;
88
89 *u_inst = inst->u_inst;
90
91 return 0;
92}
93
94// VIOs:
95int     cont_fw_new_child(struct cont_fw_parent_inst  * inst, int id) {
96 if ( inst == NULL )
97  return -1;
98
99 return -1;
100}
101
102int     cont_fw_init_vio(struct roar_vio_calls * vio, void * inst) {
103 if ( vio == NULL )
104  return -1;
105
106 memset(vio, 0, sizeof(struct roar_vio_calls));
107 vio->inst = inst;
108
109 vio->read  = cont_fw_read;
110 vio->write = cont_fw_write;
111 vio->sync  = cont_fw_sync;
112 vio->close = cont_fw_close;
113
114 return 0;
115}
116
117ssize_t cont_fw_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
118 _BASIC();
119
120 if ( inst->parent->ccb.read != NULL )
121  return inst->parent->ccb.read(inst->parent, inst, buf, count);
122
123 return -1;
124}
125
126ssize_t cont_fw_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
127 _BASIC();
128
129 if ( inst->parent->ccb.write != NULL )
130  return inst->parent->ccb.write(inst->parent, inst, buf, count);
131
132 return -1;
133}
134
135off_t   cont_fw_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
136int     cont_fw_nonblock(struct roar_vio_calls * vio, int state);
137
138int     cont_fw_sync    (struct roar_vio_calls * vio) {
139 _BASIC();
140
141 if ( inst->parent->ccb.flush != NULL )
142  return inst->parent->ccb.flush(inst->parent, inst);
143
144 return 0;
145}
146
147int     cont_fw_close   (struct roar_vio_calls * vio) {
148 _DECL();
149 int r = 0;
150
151 _PREP();
152
153 if ( cont_fw_sync(vio) == -1 )
154  r = -1;
155
156 if ( inst->parent->ccb.close != NULL )
157  return inst->parent->ccb.close(inst->parent, inst);
158
159 return  r;
160}
161
162int     cont_fw_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
163
164//ll
Note: See TracBrowser for help on using the repository browser.