Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 1 | /********************************************************** |
Guido van Rossum | bab9d03 | 1992-04-05 14:26:55 +0000 | [diff] [blame] | 2 | Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 3 | Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 5773798 | 1992-05-15 11:06:29 +0000 | [diff] [blame] | 25 | /* AL module -- interface to Mark Callow's Audio Library (AL). */ |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 26 | |
| 27 | #include "audio.h" |
| 28 | |
| 29 | #include "allobjects.h" |
| 30 | #include "import.h" |
| 31 | #include "modsupport.h" |
| 32 | #include "structmember.h" |
Jack Jansen | 743db36 | 1992-08-13 14:13:11 +0000 | [diff] [blame^] | 33 | #include "ceval.h" |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | /* Config objects */ |
| 37 | |
| 38 | typedef struct { |
| 39 | OB_HEAD |
| 40 | ALconfig ob_config; |
| 41 | } configobject; |
| 42 | |
| 43 | extern typeobject Configtype; /* Forward */ |
| 44 | |
| 45 | #define is_configobject(v) ((v)->ob_type == &Configtype) |
| 46 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 47 | /* Forward */ |
| 48 | static int getconfigarg PROTO((object *, ALconfig *)); |
| 49 | static int getstrstrconfigarg PROTO((object *, char **, char **, ALconfig *)); |
| 50 | |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 51 | static object * |
| 52 | setConfig (self, args, func) |
| 53 | configobject *self; |
| 54 | object *args; |
| 55 | void (*func)(ALconfig, long); |
| 56 | { |
| 57 | long par; |
| 58 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 59 | if (!getlongarg (args, &par)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 60 | |
| 61 | (*func) (self-> ob_config, par); |
| 62 | |
| 63 | INCREF (None); |
| 64 | return None; |
| 65 | } |
| 66 | |
| 67 | static object * |
| 68 | getConfig (self, args, func) |
| 69 | configobject *self; |
| 70 | object *args; |
| 71 | long (*func)(ALconfig); |
| 72 | { |
| 73 | long par; |
| 74 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 75 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 76 | |
| 77 | par = (*func) (self-> ob_config); |
| 78 | |
| 79 | return newintobject (par); |
| 80 | } |
| 81 | |
| 82 | static object * |
| 83 | al_setqueuesize (self, args) |
| 84 | configobject *self; |
| 85 | object *args; |
| 86 | { |
| 87 | return (setConfig (self, args, ALsetqueuesize)); |
| 88 | } |
| 89 | |
| 90 | static object * |
| 91 | al_getqueuesize (self, args) |
| 92 | configobject *self; |
| 93 | object *args; |
| 94 | { |
| 95 | return (getConfig (self, args, ALgetqueuesize)); |
| 96 | } |
| 97 | |
| 98 | static object * |
| 99 | al_setwidth (self, args) |
| 100 | configobject *self; |
| 101 | object *args; |
| 102 | { |
| 103 | return (setConfig (self, args, ALsetwidth)); |
| 104 | } |
| 105 | |
| 106 | static object * |
| 107 | al_getwidth (self, args) |
| 108 | configobject *self; |
| 109 | object *args; |
| 110 | { |
| 111 | return (getConfig (self, args, ALgetwidth)); |
| 112 | } |
| 113 | |
| 114 | static object * |
| 115 | al_getchannels (self, args) |
| 116 | configobject *self; |
| 117 | object *args; |
| 118 | { |
| 119 | return (getConfig (self, args, ALgetchannels)); |
| 120 | } |
| 121 | |
| 122 | static object * |
| 123 | al_setchannels (self, args) |
| 124 | configobject *self; |
| 125 | object *args; |
| 126 | { |
| 127 | return (setConfig (self, args, ALsetchannels)); |
| 128 | } |
| 129 | |
| 130 | static struct methodlist config_methods[] = { |
| 131 | {"getqueuesize", al_getqueuesize}, |
| 132 | {"setqueuesize", al_setqueuesize}, |
| 133 | {"getwidth", al_getwidth}, |
| 134 | {"setwidth", al_setwidth}, |
| 135 | {"getchannels", al_getchannels}, |
| 136 | {"setchannels", al_setchannels}, |
| 137 | {NULL, NULL} /* sentinel */ |
| 138 | }; |
| 139 | |
| 140 | static void |
| 141 | config_dealloc(self) |
| 142 | configobject *self; |
| 143 | { |
| 144 | ALfreeconfig(self->ob_config); |
| 145 | DEL(self); |
| 146 | } |
| 147 | |
| 148 | static object * |
| 149 | config_getattr(self, name) |
| 150 | configobject *self; |
| 151 | char *name; |
| 152 | { |
| 153 | return findmethod(config_methods, (object *)self, name); |
| 154 | } |
| 155 | |
| 156 | typeobject Configtype = { |
| 157 | OB_HEAD_INIT(&Typetype) |
| 158 | 0, /*ob_size*/ |
| 159 | "config", /*tp_name*/ |
| 160 | sizeof(configobject), /*tp_size*/ |
| 161 | 0, /*tp_itemsize*/ |
| 162 | /* methods */ |
| 163 | config_dealloc, /*tp_dealloc*/ |
| 164 | 0, /*tp_print*/ |
| 165 | config_getattr, /*tp_getattr*/ |
| 166 | 0, /*tp_setattr*/ |
| 167 | 0, /*tp_compare*/ |
| 168 | 0, /*tp_repr*/ |
| 169 | }; |
| 170 | |
| 171 | static object * |
| 172 | newconfigobject(config) |
| 173 | ALconfig config; |
| 174 | { |
| 175 | configobject *p; |
| 176 | |
| 177 | p = NEWOBJ(configobject, &Configtype); |
| 178 | if (p == NULL) |
| 179 | return NULL; |
| 180 | p->ob_config = config; |
| 181 | return (object *)p; |
| 182 | } |
| 183 | |
| 184 | /* Port objects */ |
| 185 | |
| 186 | typedef struct { |
| 187 | OB_HEAD |
| 188 | ALport ob_port; |
| 189 | } portobject; |
| 190 | |
| 191 | extern typeobject Porttype; /* Forward */ |
| 192 | |
| 193 | #define is_portobject(v) ((v)->ob_type == &Porttype) |
| 194 | |
| 195 | static object * |
| 196 | al_closeport (self, args) |
| 197 | portobject *self; |
| 198 | object *args; |
| 199 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 200 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 201 | |
| 202 | if (self->ob_port != NULL) { |
| 203 | ALcloseport (self-> ob_port); |
| 204 | self->ob_port = NULL; |
| 205 | /* XXX Using a closed port may dump core! */ |
| 206 | } |
| 207 | |
| 208 | INCREF (None); |
| 209 | return None; |
| 210 | } |
| 211 | |
| 212 | static object * |
| 213 | al_getfd (self, args) |
| 214 | portobject *self; |
| 215 | object *args; |
| 216 | { |
| 217 | int fd; |
| 218 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 219 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 220 | |
| 221 | fd = ALgetfd (self-> ob_port); |
| 222 | |
| 223 | return newintobject (fd); |
| 224 | } |
| 225 | |
| 226 | static object * |
| 227 | al_getfilled (self, args) |
| 228 | portobject *self; |
| 229 | object *args; |
| 230 | { |
| 231 | long count; |
| 232 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 233 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 234 | |
| 235 | count = ALgetfilled (self-> ob_port); |
| 236 | |
| 237 | return newintobject (count); |
| 238 | } |
| 239 | |
| 240 | static object * |
| 241 | al_getfillable (self, args) |
| 242 | portobject *self; |
| 243 | object *args; |
| 244 | { |
| 245 | long count; |
| 246 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 247 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 248 | |
| 249 | count = ALgetfillable (self-> ob_port); |
| 250 | |
| 251 | return newintobject (count); |
| 252 | } |
| 253 | |
| 254 | static object * |
| 255 | al_readsamps (self, args) |
| 256 | portobject *self; |
| 257 | object *args; |
| 258 | { |
| 259 | long count; |
| 260 | object *v; |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 261 | ALconfig c; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 262 | int width; |
| 263 | |
| 264 | if (!getlongarg (args, &count)) return NULL; |
| 265 | |
| 266 | if (count <= 0) |
| 267 | { |
| 268 | err_setstr (RuntimeError, "al.readsamps : arg <= 0"); |
| 269 | return NULL; |
| 270 | } |
| 271 | |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 272 | c = ALgetconfig(self->ob_port); |
| 273 | width = ALgetwidth(c); |
| 274 | ALfreeconfig(c); |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 275 | v = newsizedstringobject ((char *)NULL, width * count); |
| 276 | if (v == NULL) return NULL; |
| 277 | |
Jack Jansen | 743db36 | 1992-08-13 14:13:11 +0000 | [diff] [blame^] | 278 | BGN_SAVE |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 279 | ALreadsamps (self-> ob_port, (void *) getstringvalue(v), count); |
Jack Jansen | 743db36 | 1992-08-13 14:13:11 +0000 | [diff] [blame^] | 280 | END_SAVE |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 281 | |
| 282 | return (v); |
| 283 | } |
| 284 | |
| 285 | static object * |
| 286 | al_writesamps (self, args) |
| 287 | portobject *self; |
| 288 | object *args; |
| 289 | { |
| 290 | long count; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 291 | char *buf; |
| 292 | int size, width; |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 293 | ALconfig c; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 294 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 295 | if (!getargs (args, "s#", &buf, &size)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 296 | |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 297 | c = ALgetconfig(self->ob_port); |
| 298 | width = ALgetwidth(c); |
| 299 | ALfreeconfig(c); |
Jack Jansen | 743db36 | 1992-08-13 14:13:11 +0000 | [diff] [blame^] | 300 | BGN_SAVE |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 301 | ALwritesamps (self-> ob_port, (void *) buf, (long) size / width); |
Jack Jansen | 743db36 | 1992-08-13 14:13:11 +0000 | [diff] [blame^] | 302 | END_SAVE |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 303 | |
| 304 | INCREF (None); |
| 305 | return None; |
| 306 | } |
| 307 | |
| 308 | static object * |
| 309 | al_getfillpoint (self, args) |
| 310 | portobject *self; |
| 311 | object *args; |
| 312 | { |
| 313 | long count; |
| 314 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 315 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 316 | |
| 317 | count = ALgetfillpoint (self-> ob_port); |
| 318 | |
| 319 | return newintobject (count); |
| 320 | } |
| 321 | |
| 322 | static object * |
| 323 | al_setfillpoint (self, args) |
| 324 | portobject *self; |
| 325 | object *args; |
| 326 | { |
| 327 | long count; |
| 328 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 329 | if (!getlongarg (args, &count)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 330 | |
| 331 | ALsetfillpoint (self-> ob_port, count); |
| 332 | |
| 333 | INCREF (None); |
| 334 | return (None); |
| 335 | } |
| 336 | |
| 337 | static object * |
| 338 | al_setconfig (self, args) |
| 339 | portobject *self; |
| 340 | object *args; |
| 341 | { |
| 342 | ALconfig config; |
| 343 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 344 | if (!getconfigarg (args, &config)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 345 | |
| 346 | ALsetconfig (self-> ob_port, config); |
| 347 | |
| 348 | INCREF (None); |
| 349 | return (None); |
| 350 | } |
| 351 | |
| 352 | static object * |
| 353 | al_getconfig (self, args) |
| 354 | portobject *self; |
| 355 | object *args; |
| 356 | { |
| 357 | ALconfig config; |
| 358 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 359 | if (!getnoarg (args)) return NULL; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 360 | |
| 361 | config = ALgetconfig (self-> ob_port); |
| 362 | |
| 363 | return newconfigobject (config); |
| 364 | } |
| 365 | |
| 366 | static struct methodlist port_methods[] = { |
| 367 | {"closeport", al_closeport}, |
| 368 | {"getfd", al_getfd}, |
Jack Jansen | 743db36 | 1992-08-13 14:13:11 +0000 | [diff] [blame^] | 369 | {"fileno", al_getfd}, |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 370 | {"getfilled", al_getfilled}, |
| 371 | {"getfillable", al_getfillable}, |
| 372 | {"readsamps", al_readsamps}, |
| 373 | {"writesamps", al_writesamps}, |
| 374 | {"setfillpoint", al_setfillpoint}, |
| 375 | {"getfillpoint", al_getfillpoint}, |
| 376 | {"setconfig", al_setconfig}, |
| 377 | {"getconfig", al_getconfig}, |
| 378 | {NULL, NULL} /* sentinel */ |
| 379 | }; |
| 380 | |
| 381 | static void |
| 382 | port_dealloc(p) |
| 383 | portobject *p; |
| 384 | { |
| 385 | if (p->ob_port != NULL) |
| 386 | ALcloseport(p->ob_port); |
| 387 | DEL(p); |
| 388 | } |
| 389 | |
| 390 | static object * |
| 391 | port_getattr(p, name) |
| 392 | portobject *p; |
| 393 | char *name; |
| 394 | { |
| 395 | return findmethod(port_methods, (object *)p, name); |
| 396 | } |
| 397 | |
| 398 | typeobject Porttype = { |
| 399 | OB_HEAD_INIT(&Typetype) |
| 400 | 0, /*ob_size*/ |
| 401 | "port", /*tp_name*/ |
| 402 | sizeof(portobject), /*tp_size*/ |
| 403 | 0, /*tp_itemsize*/ |
| 404 | /* methods */ |
| 405 | port_dealloc, /*tp_dealloc*/ |
| 406 | 0, /*tp_print*/ |
| 407 | port_getattr, /*tp_getattr*/ |
| 408 | 0, /*tp_setattr*/ |
| 409 | 0, /*tp_compare*/ |
| 410 | 0, /*tp_repr*/ |
| 411 | }; |
| 412 | |
| 413 | static object * |
| 414 | newportobject(port) |
| 415 | ALport port; |
| 416 | { |
| 417 | portobject *p; |
| 418 | |
| 419 | p = NEWOBJ(portobject, &Porttype); |
| 420 | if (p == NULL) |
| 421 | return NULL; |
| 422 | p->ob_port = port; |
| 423 | return (object *)p; |
| 424 | } |
| 425 | |
| 426 | /* the module al */ |
| 427 | |
| 428 | static object * |
| 429 | al_openport (self, args) |
| 430 | object *self, *args; |
| 431 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 432 | char *name, *dir; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 433 | ALport port; |
| 434 | ALconfig config = NULL; |
Guido van Rossum | c0aab89 | 1991-10-20 20:10:46 +0000 | [diff] [blame] | 435 | int size; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 436 | |
Guido van Rossum | c0aab89 | 1991-10-20 20:10:46 +0000 | [diff] [blame] | 437 | if (args == NULL || !is_tupleobject(args)) { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 438 | err_badarg (); |
Guido van Rossum | c0aab89 | 1991-10-20 20:10:46 +0000 | [diff] [blame] | 439 | return NULL; |
| 440 | } |
| 441 | size = gettuplesize(args); |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 442 | if (size == 2) { |
| 443 | if (!getstrstrarg (args, &name, &dir)) |
| 444 | return NULL; |
| 445 | } |
| 446 | else if (size == 3) { |
| 447 | if (!getstrstrconfigarg (args, &name, &dir, &config)) |
| 448 | return NULL; |
| 449 | } |
| 450 | else { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 451 | err_badarg (); |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 452 | return NULL; |
| 453 | } |
| 454 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 455 | port = ALopenport(name, dir, config); |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 456 | |
Guido van Rossum | c0aab89 | 1991-10-20 20:10:46 +0000 | [diff] [blame] | 457 | if (port == NULL) { |
| 458 | err_errno(RuntimeError); |
| 459 | return NULL; |
| 460 | } |
| 461 | |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 462 | return newportobject (port); |
| 463 | } |
| 464 | |
| 465 | static object * |
| 466 | al_newconfig (self, args) |
| 467 | object *self, *args; |
| 468 | { |
| 469 | ALconfig config; |
| 470 | |
| 471 | if (!getnoarg (args)) return NULL; |
| 472 | |
| 473 | config = ALnewconfig (); |
Guido van Rossum | c0aab89 | 1991-10-20 20:10:46 +0000 | [diff] [blame] | 474 | if (config == NULL) { |
| 475 | err_errno(RuntimeError); |
| 476 | return NULL; |
| 477 | } |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 478 | |
| 479 | return newconfigobject (config); |
| 480 | } |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 481 | |
| 482 | static object * |
| 483 | al_queryparams(self, args) |
| 484 | object *self, *args; |
| 485 | { |
| 486 | long device; |
| 487 | long length; |
| 488 | long *PVbuffer; |
| 489 | long PVdummy[2]; |
| 490 | object *v; |
| 491 | object *w; |
| 492 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 493 | if (!getlongarg (args, &device)) |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 494 | return NULL; |
| 495 | length = ALqueryparams(device, PVdummy, 2L); |
| 496 | PVbuffer = NEW(long, length); |
| 497 | if (PVbuffer == NULL) |
| 498 | return err_nomem(); |
| 499 | (void) ALqueryparams(device, PVbuffer, length); |
| 500 | v = newlistobject((int)length); |
| 501 | if (v != NULL) { |
| 502 | int i; |
| 503 | for (i = 0; i < length; i++) |
| 504 | setlistitem(v, i, newintobject(PVbuffer[i])); |
| 505 | } |
| 506 | DEL(PVbuffer); |
| 507 | return v; |
| 508 | } |
| 509 | |
| 510 | static object * |
| 511 | doParams(args, func, modified) |
| 512 | object *args; |
| 513 | void (*func)(long, long *, long); |
| 514 | int modified; |
| 515 | { |
| 516 | long device; |
| 517 | object *list, *v; |
| 518 | long *PVbuffer; |
| 519 | long length; |
| 520 | int i; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 521 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 522 | if (!getargs(args, "(lO)", &device, &list)) |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 523 | return NULL; |
| 524 | if (!is_listobject(list)) { |
| 525 | err_badarg(); |
| 526 | return NULL; |
| 527 | } |
| 528 | length = getlistsize(list); |
| 529 | PVbuffer = NEW(long, length); |
| 530 | if (PVbuffer == NULL) |
| 531 | return err_nomem(); |
| 532 | for (i = 0; i < length; i++) { |
| 533 | v = getlistitem(list, i); |
| 534 | if (!is_intobject(v)) { |
| 535 | DEL(PVbuffer); |
| 536 | err_badarg(); |
| 537 | return NULL; |
| 538 | } |
| 539 | PVbuffer[i] = getintvalue(v); |
| 540 | } |
| 541 | |
Guido van Rossum | 8db0307 | 1991-09-13 15:31:47 +0000 | [diff] [blame] | 542 | (*func)(device, PVbuffer, length); |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 543 | |
| 544 | if (modified) { |
| 545 | for (i = 0; i < length; i++) |
| 546 | setlistitem(list, i, newintobject(PVbuffer[i])); |
| 547 | } |
| 548 | |
Guido van Rossum | c0aab89 | 1991-10-20 20:10:46 +0000 | [diff] [blame] | 549 | DEL(PVbuffer); |
| 550 | |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 551 | INCREF(None); |
| 552 | return None; |
| 553 | } |
| 554 | |
| 555 | static object * |
| 556 | al_getparams(self, args) |
| 557 | object *self, *args; |
| 558 | { |
| 559 | return doParams(args, ALgetparams, 1); |
| 560 | } |
| 561 | |
| 562 | static object * |
| 563 | al_setparams(self, args) |
| 564 | object *self, *args; |
| 565 | { |
| 566 | return doParams(args, ALsetparams, 0); |
| 567 | } |
| 568 | |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 569 | static struct methodlist al_methods[] = { |
| 570 | {"openport", al_openport}, |
| 571 | {"newconfig", al_newconfig}, |
Guido van Rossum | b3a5b9b | 1991-09-10 14:54:05 +0000 | [diff] [blame] | 572 | {"queryparams", al_queryparams}, |
| 573 | {"getparams", al_getparams}, |
| 574 | {"setparams", al_setparams}, |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 575 | {NULL, NULL} /* sentinel */ |
| 576 | }; |
| 577 | |
| 578 | void |
| 579 | inital() |
| 580 | { |
| 581 | initmodule("al", al_methods); |
| 582 | } |
| 583 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 584 | static int |
| 585 | getconfigarg(o, conf) |
| 586 | object *o; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 587 | ALconfig *conf; |
| 588 | { |
| 589 | if (o == NULL || !is_configobject(o)) |
| 590 | return err_badarg (); |
| 591 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 592 | *conf = ((configobject *) o) -> ob_config; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 593 | |
| 594 | return 1; |
| 595 | } |
| 596 | |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 597 | static int |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 598 | getstrstrconfigarg(v, a, b, c) |
| 599 | object *v; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 600 | char **a; |
| 601 | char **b; |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 602 | ALconfig *c; |
| 603 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 604 | object *o; |
| 605 | return getargs(v, "(ssO)", a, b, &o) && getconfigarg(o, c); |
Guido van Rossum | e3db862 | 1991-09-09 23:33:34 +0000 | [diff] [blame] | 606 | } |