Mercurial > cpython-lru_cache-weakref
annotate Modules/sunaudiodev.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | 3d87cb1b3d17 |
| rev | line source |
|---|---|
| 885 | 1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
3 The Netherlands. |
| 885 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 885 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 885 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
15 permission. |
| 885 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4298
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 885 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 32 /* Sad objects */ | |
| 33 | |
| 34 #include "allobjects.h" | |
| 35 #include "modsupport.h" | |
| 36 #include "structmember.h" | |
| 37 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
38 #ifdef HAVE_SYS_AUDIOIO_H |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
39 #define SOLARIS |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
40 #endif |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
41 |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
42 #include <stropts.h> |
| 885 | 43 #include <sys/ioctl.h> |
| 1418 | 44 #ifdef SOLARIS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
45 #include <sys/audioio.h> |
| 1418 | 46 #else |
| 885 | 47 #include <sun/audioio.h> |
| 1418 | 48 #endif |
| 885 | 49 |
| 50 /* #define offsetof(str,mem) ((int)(((str *)0)->mem)) */ | |
| 51 | |
| 52 typedef struct { | |
| 53 OB_HEAD | |
| 54 int x_fd; /* The open file */ | |
| 55 int x_icount; /* # samples read */ | |
| 56 int x_ocount; /* # samples written */ | |
| 57 int x_isctl; /* True if control device */ | |
| 58 | |
| 59 } sadobject; | |
| 60 | |
| 61 typedef struct { | |
| 62 OB_HEAD | |
| 63 audio_info_t ai; | |
| 64 } sadstatusobject; | |
| 65 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
66 staticforward typeobject Sadtype; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
67 staticforward typeobject Sadstatustype; |
| 1418 | 68 static sadstatusobject *sads_alloc(); /* Forward */ |
| 885 | 69 |
| 70 static object *SunAudioError; | |
| 71 | |
| 72 static int dummy_for_dl; | |
| 73 | |
| 74 #define is_sadobject(v) ((v)->ob_type == &Sadtype) | |
| 75 #define is_sadstatusobject(v) ((v)->ob_type == &Sadstatustype) | |
| 76 | |
| 77 static sadobject * | |
| 78 newsadobject(arg) | |
| 79 object *arg; | |
| 80 { | |
| 81 sadobject *xp; | |
| 82 int fd; | |
| 83 char *mode; | |
| 84 int imode; | |
| 85 | |
| 86 /* Check arg for r/w/rw */ | |
| 87 if ( !getargs(arg, "s", &mode) ) | |
| 88 return 0; | |
| 89 if ( strcmp(mode, "r") == 0 ) | |
| 90 imode = 0; | |
| 91 else if ( strcmp(mode, "w") == 0 ) | |
| 92 imode = 1; | |
| 93 else if ( strcmp(mode, "rw") == 0 ) | |
| 94 imode = 2; | |
| 95 else if ( strcmp(mode, "control") == 0 ) | |
| 96 imode = -1; | |
| 97 else { | |
| 98 err_setstr(SunAudioError, | |
| 99 "Mode should be one of 'r', 'w', 'rw' or 'control'"); | |
| 100 return 0; | |
| 101 } | |
| 102 | |
| 103 /* Open the correct device */ | |
| 104 if ( imode < 0 ) | |
| 105 fd = open("/dev/audioctl", 2); /* XXXX Chaeck that this works */ | |
| 106 else | |
| 107 fd = open("/dev/audio", imode); | |
| 108 if ( fd < 0 ) { | |
| 109 err_errno(SunAudioError); | |
| 110 return NULL; | |
| 111 } | |
| 112 | |
| 113 /* Create and initialize the object */ | |
| 114 xp = NEWOBJ(sadobject, &Sadtype); | |
| 115 if (xp == NULL) | |
| 116 return NULL; | |
| 117 xp->x_fd = fd; | |
| 118 xp->x_icount = xp->x_ocount = 0; | |
| 119 xp->x_isctl = (imode < 0); | |
| 120 | |
| 121 return xp; | |
| 122 } | |
| 123 | |
| 124 /* Sad methods */ | |
| 125 | |
| 126 static void | |
| 127 sad_dealloc(xp) | |
| 128 sadobject *xp; | |
| 129 { | |
| 130 close(xp->x_fd); | |
| 131 DEL(xp); | |
| 132 } | |
| 133 | |
| 134 static object * | |
| 135 sad_read(self, args) | |
| 136 sadobject *self; | |
| 137 object *args; | |
| 138 { | |
| 139 int size, count; | |
| 140 char *cp; | |
| 141 object *rv; | |
| 142 | |
| 143 if ( !getargs(args, "i", &size) ) | |
| 144 return 0; | |
| 145 rv = newsizedstringobject(NULL, size); | |
| 146 if ( rv == NULL ) | |
| 147 return 0; | |
| 148 | |
| 149 cp = getstringvalue(rv); | |
| 150 | |
| 151 count = read(self->x_fd, cp, size); | |
| 152 if ( count < 0 ) { | |
| 153 DECREF(rv); | |
| 154 err_errno(SunAudioError); | |
| 155 return NULL; | |
| 156 } | |
| 157 if ( count != size ) | |
| 158 printf("sunaudio: funny read rv %d wtd %d\n", count, size); | |
| 159 self->x_icount += count; | |
| 160 return rv; | |
| 161 } | |
| 162 | |
| 163 static object * | |
| 164 sad_write(self, args) | |
| 165 sadobject *self; | |
| 166 object *args; | |
| 167 { | |
| 168 char *cp; | |
| 169 int count, size; | |
| 170 | |
| 171 if ( !getargs(args, "s#", &cp, &size) ) | |
| 172 return 0; | |
| 173 | |
| 174 count = write(self->x_fd, cp, size); | |
| 175 if ( count < 0 ) { | |
| 176 err_errno(SunAudioError); | |
| 177 return NULL; | |
| 178 } | |
| 179 if ( count != size ) | |
| 180 printf("sunaudio: funny write rv %d wanted %d\n", count, size); | |
| 181 self->x_ocount += count; | |
| 182 | |
| 183 INCREF(None); | |
| 184 return None; | |
| 185 } | |
| 186 | |
| 187 static object * | |
| 188 sad_getinfo(self, args) | |
| 189 sadobject *self; | |
| 190 object *args; | |
| 191 { | |
| 192 sadstatusobject *rv; | |
| 193 | |
| 194 if ( !getargs(args, "") ) | |
| 195 return NULL; | |
| 196 rv = sads_alloc(); | |
| 197 if ( ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0 ) { | |
| 198 err_errno(SunAudioError); | |
| 199 DECREF(rv); | |
| 200 return NULL; | |
| 201 } | |
| 202 return (object *)rv; | |
| 203 } | |
| 204 | |
| 205 static object * | |
| 206 sad_setinfo(self, arg) | |
| 207 sadobject *self; | |
| 208 sadstatusobject *arg; | |
| 209 { | |
| 210 if ( !is_sadstatusobject(arg) ) { | |
| 211 err_setstr(TypeError, "Must be sun audio status object"); | |
| 212 return NULL; | |
| 213 } | |
| 214 if ( ioctl(self->x_fd, AUDIO_SETINFO, &arg->ai) < 0 ) { | |
| 215 err_errno(SunAudioError); | |
| 216 return NULL; | |
| 217 } | |
| 218 INCREF(None); | |
| 219 return None; | |
| 220 } | |
| 221 | |
| 222 static object * | |
| 223 sad_ibufcount(self, args) | |
| 224 sadobject *self; | |
| 225 object *args; | |
| 226 { | |
| 227 audio_info_t ai; | |
| 228 object *rv; | |
| 229 | |
| 230 if ( !getargs(args, "") ) | |
| 231 return 0; | |
| 232 if ( ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0 ) { | |
| 233 err_errno(SunAudioError); | |
| 234 return NULL; | |
| 235 } | |
| 236 rv = newintobject(ai.record.samples - self->x_icount); | |
| 237 return rv; | |
| 238 } | |
| 239 | |
| 240 static object * | |
| 241 sad_obufcount(self, args) | |
| 242 sadobject *self; | |
| 243 object *args; | |
| 244 { | |
| 245 audio_info_t ai; | |
| 246 object *rv; | |
| 247 | |
| 248 if ( !getargs(args, "") ) | |
| 249 return 0; | |
| 250 if ( ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0 ) { | |
| 251 err_errno(SunAudioError); | |
| 252 return NULL; | |
| 253 } | |
| 254 rv = newintobject(self->x_ocount - ai.play.samples); | |
| 255 return rv; | |
| 256 } | |
| 257 | |
| 258 static object * | |
| 259 sad_drain(self, args) | |
| 260 sadobject *self; | |
| 261 object *args; | |
| 262 { | |
| 263 | |
| 264 if ( !getargs(args, "") ) | |
| 265 return 0; | |
| 266 if ( ioctl(self->x_fd, AUDIO_DRAIN, 0) < 0 ) { | |
| 267 err_errno(SunAudioError); | |
| 268 return NULL; | |
| 269 } | |
| 270 INCREF(None); | |
| 271 return None; | |
| 272 } | |
| 273 | |
| 1418 | 274 #ifdef SOLARIS |
| 275 static object * | |
| 276 sad_getdev(self, args) | |
| 277 sadobject *self; | |
| 278 object *args; | |
| 279 { | |
| 280 struct audio_device ad; | |
| 281 | |
| 282 if ( !getargs(args, "") ) | |
| 283 return 0; | |
| 284 if ( ioctl(self->x_fd, AUDIO_GETDEV, &ad) < 0 ) { | |
| 285 err_errno(SunAudioError); | |
| 286 return NULL; | |
| 287 } | |
| 288 return mkvalue("(sss)", ad.name, ad.version, ad.config); | |
| 289 } | |
| 290 #endif | |
| 291 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
292 static object * |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
293 sad_flush(self, args) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
294 sadobject *self; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
295 object *args; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
296 { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
297 |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
298 if ( !getargs(args, "") ) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
299 return 0; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
300 if ( ioctl(self->x_fd, I_FLUSH, FLUSHW) < 0 ) { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
301 err_errno(SunAudioError); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
302 return NULL; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
303 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
304 INCREF(None); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
305 return None; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
306 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
307 |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
308 static object * |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
309 sad_close(self, args) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
310 sadobject *self; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
311 object *args; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
312 { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
313 |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
314 if ( !getargs(args, "") ) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
315 return 0; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
316 if ( self->x_fd >= 0 ) { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
317 close(self->x_fd); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
318 self->x_fd = -1; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
319 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
320 INCREF(None); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
321 return None; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
322 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
323 |
| 885 | 324 static struct methodlist sad_methods[] = { |
|
2569
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
325 { "read", (method)sad_read }, |
|
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
326 { "write", (method)sad_write }, |
|
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
327 { "ibufcount", (method)sad_ibufcount }, |
|
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
328 { "obufcount", (method)sad_obufcount }, |
| 885 | 329 #define CTL_METHODS 4 |
|
2569
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
330 { "getinfo", (method)sad_getinfo }, |
|
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
331 { "setinfo", (method)sad_setinfo }, |
|
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
332 { "drain", (method)sad_drain }, |
|
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
333 { "flush", (method)sad_flush }, |
| 1418 | 334 #ifdef SOLARIS |
|
2569
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
335 { "getdev", (method)sad_getdev }, |
| 1418 | 336 #endif |
|
2569
7a3733732901
Added some (method) casts.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2061
diff
changeset
|
337 { "close", (method)sad_close }, |
| 885 | 338 {NULL, NULL} /* sentinel */ |
| 339 }; | |
| 340 | |
| 341 static object * | |
| 342 sad_getattr(xp, name) | |
| 343 sadobject *xp; | |
| 344 char *name; | |
| 345 { | |
| 346 if ( xp->x_isctl ) | |
| 347 return findmethod(sad_methods+CTL_METHODS, (object *)xp, name); | |
| 348 else | |
| 349 return findmethod(sad_methods, (object *)xp, name); | |
| 350 } | |
| 351 | |
| 352 /* ----------------------------------------------------------------- */ | |
| 353 | |
| 354 static sadstatusobject * | |
| 355 sads_alloc() { | |
| 356 sadstatusobject *rv; | |
| 357 | |
| 358 rv = NEWOBJ(sadstatusobject, &Sadstatustype); | |
| 359 return rv; | |
| 360 } | |
| 361 | |
| 362 static void | |
| 363 sads_dealloc(xp) | |
| 364 sadstatusobject *xp; | |
| 365 { | |
| 366 DEL(xp); | |
| 367 } | |
| 368 | |
| 369 #define OFF(x) offsetof(audio_info_t,x) | |
| 370 static struct memberlist sads_ml[] = { | |
| 371 { "i_sample_rate", T_UINT, OFF(record.sample_rate) }, | |
| 372 { "i_channels", T_UINT, OFF(record.channels) }, | |
| 373 { "i_precision", T_UINT, OFF(record.precision) }, | |
| 374 { "i_encoding", T_UINT, OFF(record.encoding) }, | |
| 375 { "i_gain", T_UINT, OFF(record.gain) }, | |
| 376 { "i_port", T_UINT, OFF(record.port) }, | |
| 377 { "i_samples", T_UINT, OFF(record.samples) }, | |
| 378 { "i_eof", T_UINT, OFF(record.eof) }, | |
| 379 { "i_pause", T_UBYTE, OFF(record.pause) }, | |
| 380 { "i_error", T_UBYTE, OFF(record.error) }, | |
| 381 { "i_waiting", T_UBYTE, OFF(record.waiting) }, | |
| 382 { "i_open", T_UBYTE, OFF(record.open) , RO}, | |
| 383 { "i_active", T_UBYTE, OFF(record.active) , RO}, | |
| 1418 | 384 #ifdef SOLARIS |
| 385 { "i_buffer_size", T_UINT, OFF(record.buffer_size) }, | |
| 386 { "i_balance", T_UBYTE, OFF(record.balance) }, | |
| 387 { "i_avail_ports", T_UINT, OFF(record.avail_ports) }, | |
| 388 #endif | |
| 885 | 389 |
| 390 { "o_sample_rate", T_UINT, OFF(play.sample_rate) }, | |
| 391 { "o_channels", T_UINT, OFF(play.channels) }, | |
| 392 { "o_precision", T_UINT, OFF(play.precision) }, | |
| 393 { "o_encoding", T_UINT, OFF(play.encoding) }, | |
| 394 { "o_gain", T_UINT, OFF(play.gain) }, | |
| 395 { "o_port", T_UINT, OFF(play.port) }, | |
| 396 { "o_samples", T_UINT, OFF(play.samples) }, | |
| 397 { "o_eof", T_UINT, OFF(play.eof) }, | |
| 398 { "o_pause", T_UBYTE, OFF(play.pause) }, | |
| 399 { "o_error", T_UBYTE, OFF(play.error) }, | |
| 400 { "o_waiting", T_UBYTE, OFF(play.waiting) }, | |
| 401 { "o_open", T_UBYTE, OFF(play.open) , RO}, | |
| 402 { "o_active", T_UBYTE, OFF(play.active) , RO}, | |
| 1418 | 403 #ifdef SOLARIS |
| 404 { "o_buffer_size", T_UINT, OFF(play.buffer_size) }, | |
| 405 { "o_balance", T_UBYTE, OFF(play.balance) }, | |
| 406 { "o_avail_ports", T_UINT, OFF(play.avail_ports) }, | |
| 407 #endif | |
| 885 | 408 |
| 409 { "monitor_gain", T_UINT, OFF(monitor_gain) }, | |
| 410 { NULL, 0, 0}, | |
| 411 }; | |
| 412 | |
| 413 static object * | |
| 414 sads_getattr(xp, name) | |
| 415 sadstatusobject *xp; | |
| 416 char *name; | |
| 417 { | |
| 418 return getmember((char *)&xp->ai, sads_ml, name); | |
| 419 } | |
| 420 | |
| 421 static int | |
| 422 sads_setattr(xp, name, v) | |
| 423 sadstatusobject *xp; | |
| 424 char *name; | |
| 425 object *v; | |
| 426 { | |
|
1031
7a11a70f7f44
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
Guido van Rossum <guido@python.org>
parents:
885
diff
changeset
|
427 |
|
7a11a70f7f44
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
Guido van Rossum <guido@python.org>
parents:
885
diff
changeset
|
428 if (v == NULL) { |
|
7a11a70f7f44
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
Guido van Rossum <guido@python.org>
parents:
885
diff
changeset
|
429 err_setstr(TypeError, |
|
7a11a70f7f44
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
Guido van Rossum <guido@python.org>
parents:
885
diff
changeset
|
430 "can't delete sun audio status attributes"); |
|
4298
6f7090a82645
Correct typo: return -1 for error, not 0
Guido van Rossum <guido@python.org>
parents:
2569
diff
changeset
|
431 return -1; |
|
1031
7a11a70f7f44
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
Guido van Rossum <guido@python.org>
parents:
885
diff
changeset
|
432 } |
| 885 | 433 return setmember((char *)&xp->ai, sads_ml, name, v); |
| 434 } | |
| 435 | |
| 436 /* ------------------------------------------------------------------- */ | |
| 437 | |
| 438 | |
| 439 static typeobject Sadtype = { | |
| 440 OB_HEAD_INIT(&Typetype) | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
441 0, /*ob_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
442 "sun_audio_device", /*tp_name*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
443 sizeof(sadobject), /*tp_size*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
444 0, /*tp_itemsize*/ |
| 885 | 445 /* methods */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
446 (destructor)sad_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
447 0, /*tp_print*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
448 (getattrfunc)sad_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
449 0, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
450 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
451 0, /*tp_repr*/ |
| 885 | 452 }; |
| 453 | |
| 454 static typeobject Sadstatustype = { | |
| 455 OB_HEAD_INIT(&Typetype) | |
| 456 0, /*ob_size*/ | |
| 457 "sun_audio_device_status", /*tp_name*/ | |
| 458 sizeof(sadstatusobject), /*tp_size*/ | |
| 459 0, /*tp_itemsize*/ | |
| 460 /* methods */ | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
461 (destructor)sads_dealloc, /*tp_dealloc*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
462 0, /*tp_print*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
463 (getattrfunc)sads_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
464 (setattrfunc)sads_setattr, /*tp_setattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
465 0, /*tp_compare*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
466 0, /*tp_repr*/ |
| 885 | 467 }; |
| 468 /* ------------------------------------------------------------------- */ | |
| 469 | |
| 470 static object * | |
| 471 sadopen(self, args) | |
| 472 object *self; | |
| 473 object *args; | |
| 474 { | |
| 475 object *rv; | |
| 476 | |
| 477 rv = (object *)newsadobject(args); | |
| 478 return rv; | |
| 479 } | |
| 480 | |
| 481 static struct methodlist sunaudiodev_methods[] = { | |
| 482 { "open", sadopen }, | |
| 483 { 0, 0 }, | |
| 484 }; | |
| 485 | |
| 486 void | |
| 487 initsunaudiodev() { | |
| 488 object *m, *d; | |
| 489 | |
| 490 m = initmodule("sunaudiodev", sunaudiodev_methods); | |
| 491 d = getmoduledict(m); | |
| 492 SunAudioError = newstringobject("sunaudiodev.error"); | |
| 493 if ( SunAudioError == NULL || dictinsert(d, "error", SunAudioError) ) | |
| 494 fatal("can't define sunaudiodev.error"); | |
| 495 } |
