source: roaraudio/roard/container_framework.c @ 2664:e92e6a804a95

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

simple for cont_fw_new(), cont_fw_delete()

File size: 3.1 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
37int     cont_fw_new     (struct cont_fw_parent_inst ** inst) {
38 struct cont_fw_parent_inst * self;
39
40 if ( inst == NULL )
41  return -1;
42
43 if ( (self = malloc(sizeof(struct cont_fw_parent_inst))) == NULL ) {
44  *inst = NULL;
45  return -1;
46 }
47
48 memset(self, 0, sizeof(struct cont_fw_parent_inst));
49
50 *inst = self;
51 return 0;
52}
53
54int     cont_fw_delete  (struct cont_fw_parent_inst  * inst) {
55 int i;
56
57 if ( inst == NULL )
58  return -1;
59
60 // check if there are streams to close...
61 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
62  if ( inst->child[i] != NULL ) {
63   return -1;
64  }
65 }
66
67 free(inst);
68
69 return 0;
70}
71
72int     cont_fw_init_vio(struct roar_vio_calls * vio, void * inst) {
73 if ( vio == NULL )
74  return -1;
75
76 memset(vio, 0, sizeof(struct roar_vio_calls));
77 vio->inst = inst;
78
79 vio->read  = cont_fw_read;
80 vio->write = cont_fw_write;
81 vio->sync  = cont_fw_sync;
82 vio->close = cont_fw_close;
83
84 return 0;
85}
86
87ssize_t cont_fw_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
88 _BASIC();
89
90 if ( inst->parent->cb.read != NULL )
91  return inst->parent->cb.read(inst->parent, inst->inst, buf, count);
92
93 return -1;
94}
95
96ssize_t cont_fw_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
97 _BASIC();
98
99 if ( inst->parent->cb.write != NULL )
100  return inst->parent->cb.write(inst->parent, inst->inst, buf, count);
101
102 return -1;
103}
104
105off_t   cont_fw_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
106int     cont_fw_nonblock(struct roar_vio_calls * vio, int state);
107
108int     cont_fw_sync    (struct roar_vio_calls * vio) {
109 _BASIC();
110
111 if ( inst->parent->cb.flush != NULL )
112  return inst->parent->cb.flush(inst->parent, inst->inst);
113
114 return 0;
115}
116
117int     cont_fw_close   (struct roar_vio_calls * vio) {
118 _DECL();
119 int r = 0;
120
121 _PREP();
122
123 if ( cont_fw_sync(vio) == -1 )
124  r = -1;
125
126 return -1;
127 return  r;
128}
129
130int     cont_fw_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
131
132//ll
Note: See TracBrowser for help on using the repository browser.