blob: d731eff16e48aa734126c56c04fd1d30a1e779bc [file] [log] [blame]
Guido van Rossume3db8621991-09-09 23:33:34 +00001/**********************************************************
Guido van Rossume5372401993-03-16 12:15:04 +00002Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3Amsterdam, The Netherlands.
Guido van Rossume3db8621991-09-09 23:33:34 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum57737981992-05-15 11:06:29 +000025/* AL module -- interface to Mark Callow's Audio Library (AL). */
Guido van Rossume3db8621991-09-09 23:33:34 +000026
27#include "audio.h"
28
Jack Jansene8a3c281993-02-10 14:10:56 +000029/* Check which version audio library we have: */
30#ifdef AL_ERROR_NUMBER
31#define AL_405
32/* XXXX 4.0.5 libaudio also allows us to provide better error
33** handling (with ALseterrorhandler). We should implement that
34** sometime.
35*/
36
37#endif
38
Guido van Rossume3db8621991-09-09 23:33:34 +000039#include "allobjects.h"
40#include "import.h"
41#include "modsupport.h"
42#include "structmember.h"
Jack Jansen743db361992-08-13 14:13:11 +000043#include "ceval.h"
Guido van Rossume3db8621991-09-09 23:33:34 +000044
45
46/* Config objects */
47
48typedef struct {
49 OB_HEAD
50 ALconfig ob_config;
51} configobject;
52
53extern typeobject Configtype; /* Forward */
54
55#define is_configobject(v) ((v)->ob_type == &Configtype)
56
Guido van Rossumfc58e581992-01-27 16:45:55 +000057/* Forward */
58static int getconfigarg PROTO((object *, ALconfig *));
59static int getstrstrconfigarg PROTO((object *, char **, char **, ALconfig *));
60
Guido van Rossume3db8621991-09-09 23:33:34 +000061static object *
62setConfig (self, args, func)
63 configobject *self;
64 object *args;
65 void (*func)(ALconfig, long);
66{
67 long par;
68
Guido van Rossumfc58e581992-01-27 16:45:55 +000069 if (!getlongarg (args, &par)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +000070
71 (*func) (self-> ob_config, par);
72
73 INCREF (None);
74 return None;
75}
76
77static object *
78getConfig (self, args, func)
79 configobject *self;
80 object *args;
81 long (*func)(ALconfig);
82{
83 long par;
84
Guido van Rossumfc58e581992-01-27 16:45:55 +000085 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +000086
87 par = (*func) (self-> ob_config);
88
89 return newintobject (par);
90}
91
92static object *
93al_setqueuesize (self, args)
94 configobject *self;
95 object *args;
96{
97 return (setConfig (self, args, ALsetqueuesize));
98}
99
100static object *
101al_getqueuesize (self, args)
102 configobject *self;
103 object *args;
104{
105 return (getConfig (self, args, ALgetqueuesize));
106}
107
108static object *
109al_setwidth (self, args)
110 configobject *self;
111 object *args;
112{
113 return (setConfig (self, args, ALsetwidth));
114}
115
116static object *
117al_getwidth (self, args)
118 configobject *self;
119 object *args;
120{
121 return (getConfig (self, args, ALgetwidth));
122}
123
124static object *
125al_getchannels (self, args)
126 configobject *self;
127 object *args;
128{
129 return (getConfig (self, args, ALgetchannels));
130}
131
132static object *
133al_setchannels (self, args)
134 configobject *self;
135 object *args;
136{
137 return (setConfig (self, args, ALsetchannels));
138}
139
Jack Jansene8a3c281993-02-10 14:10:56 +0000140#ifdef AL_405
141
142static object *
143al_getsampfmt (self, args)
144 configobject *self;
145 object *args;
146{
147 return (getConfig (self, args, ALgetsampfmt));
148}
149
150static object *
151al_setsampfmt (self, args)
152 configobject *self;
153 object *args;
154{
155 return (setConfig (self, args, ALsetsampfmt));
156}
157
158static object *
159al_getfloatmax(self, args)
160 configobject *self;
161 object *args;
162{
163 double arg;
164
165 if ( !getnoarg(args) )
166 return 0;
167 arg = ALgetfloatmax(self->ob_config);
168 return newfloatobject(arg);
169}
170
171static object *
172al_setfloatmax(self, args)
173 configobject *self;
174 object *args;
175{
176 double arg;
177
178 if ( !getargs(args, "d", &arg) )
179 return 0;
180 ALsetfloatmax(self->ob_config, arg);
181 INCREF(None);
182 return None;
183}
184#endif /* AL_405 */
185
Guido van Rossume3db8621991-09-09 23:33:34 +0000186static struct methodlist config_methods[] = {
187 {"getqueuesize", al_getqueuesize},
188 {"setqueuesize", al_setqueuesize},
189 {"getwidth", al_getwidth},
190 {"setwidth", al_setwidth},
191 {"getchannels", al_getchannels},
192 {"setchannels", al_setchannels},
Jack Jansene8a3c281993-02-10 14:10:56 +0000193#ifdef AL_405
194 {"getsampfmt", al_getsampfmt},
195 {"setsampfmt", al_setsampfmt},
196 {"getfloatmax", al_getfloatmax},
197 {"setfloatmax", al_setfloatmax},
198#endif /* AL_405 */
Guido van Rossume3db8621991-09-09 23:33:34 +0000199 {NULL, NULL} /* sentinel */
200};
201
202static void
203config_dealloc(self)
204 configobject *self;
205{
206 ALfreeconfig(self->ob_config);
207 DEL(self);
208}
209
210static object *
211config_getattr(self, name)
212 configobject *self;
213 char *name;
214{
215 return findmethod(config_methods, (object *)self, name);
216}
217
218typeobject Configtype = {
219 OB_HEAD_INIT(&Typetype)
220 0, /*ob_size*/
221 "config", /*tp_name*/
222 sizeof(configobject), /*tp_size*/
223 0, /*tp_itemsize*/
224 /* methods */
225 config_dealloc, /*tp_dealloc*/
226 0, /*tp_print*/
227 config_getattr, /*tp_getattr*/
228 0, /*tp_setattr*/
229 0, /*tp_compare*/
230 0, /*tp_repr*/
231};
232
233static object *
234newconfigobject(config)
235 ALconfig config;
236{
237 configobject *p;
238
239 p = NEWOBJ(configobject, &Configtype);
240 if (p == NULL)
241 return NULL;
242 p->ob_config = config;
243 return (object *)p;
244}
245
246/* Port objects */
247
248typedef struct {
249 OB_HEAD
250 ALport ob_port;
251} portobject;
252
253extern typeobject Porttype; /* Forward */
254
255#define is_portobject(v) ((v)->ob_type == &Porttype)
256
257static object *
258al_closeport (self, args)
259 portobject *self;
260 object *args;
261{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000262 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000263
264 if (self->ob_port != NULL) {
265 ALcloseport (self-> ob_port);
266 self->ob_port = NULL;
267 /* XXX Using a closed port may dump core! */
268 }
269
270 INCREF (None);
271 return None;
272}
273
274static object *
275al_getfd (self, args)
276 portobject *self;
277 object *args;
278{
279 int fd;
280
Guido van Rossumfc58e581992-01-27 16:45:55 +0000281 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000282
283 fd = ALgetfd (self-> ob_port);
284
285 return newintobject (fd);
286}
287
288static object *
289al_getfilled (self, args)
290 portobject *self;
291 object *args;
292{
293 long count;
294
Guido van Rossumfc58e581992-01-27 16:45:55 +0000295 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000296
297 count = ALgetfilled (self-> ob_port);
298
299 return newintobject (count);
300}
301
302static object *
303al_getfillable (self, args)
304 portobject *self;
305 object *args;
306{
307 long count;
308
Guido van Rossumfc58e581992-01-27 16:45:55 +0000309 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000310
311 count = ALgetfillable (self-> ob_port);
312
313 return newintobject (count);
314}
315
316static object *
317al_readsamps (self, args)
318 portobject *self;
319 object *args;
320{
321 long count;
322 object *v;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000323 ALconfig c;
Guido van Rossume3db8621991-09-09 23:33:34 +0000324 int width;
325
326 if (!getlongarg (args, &count)) return NULL;
327
328 if (count <= 0)
329 {
330 err_setstr (RuntimeError, "al.readsamps : arg <= 0");
331 return NULL;
332 }
333
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000334 c = ALgetconfig(self->ob_port);
Jack Jansene8a3c281993-02-10 14:10:56 +0000335#ifdef AL_405
336 width = ALgetsampfmt(c);
337 if ( width == AL_SAMPFMT_FLOAT )
338 width = sizeof(float);
339 else if ( width == AL_SAMPFMT_DOUBLE )
340 width = sizeof(double);
341 else
342 width = ALgetwidth(c);
343#else
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000344 width = ALgetwidth(c);
Jack Jansene8a3c281993-02-10 14:10:56 +0000345#endif /* AL_405 */
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000346 ALfreeconfig(c);
Guido van Rossume3db8621991-09-09 23:33:34 +0000347 v = newsizedstringobject ((char *)NULL, width * count);
348 if (v == NULL) return NULL;
349
Jack Jansen743db361992-08-13 14:13:11 +0000350 BGN_SAVE
Guido van Rossume3db8621991-09-09 23:33:34 +0000351 ALreadsamps (self-> ob_port, (void *) getstringvalue(v), count);
Jack Jansen743db361992-08-13 14:13:11 +0000352 END_SAVE
Guido van Rossume3db8621991-09-09 23:33:34 +0000353
354 return (v);
355}
356
357static object *
358al_writesamps (self, args)
359 portobject *self;
360 object *args;
361{
362 long count;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000363 char *buf;
364 int size, width;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000365 ALconfig c;
Guido van Rossume3db8621991-09-09 23:33:34 +0000366
Guido van Rossumfc58e581992-01-27 16:45:55 +0000367 if (!getargs (args, "s#", &buf, &size)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000368
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000369 c = ALgetconfig(self->ob_port);
Jack Jansene8a3c281993-02-10 14:10:56 +0000370#ifdef AL_405
371 width = ALgetsampfmt(c);
372 if ( width == AL_SAMPFMT_FLOAT )
373 width = sizeof(float);
374 else if ( width == AL_SAMPFMT_DOUBLE )
375 width = sizeof(double);
376 else
377 width = ALgetwidth(c);
378#else
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000379 width = ALgetwidth(c);
Jack Jansene8a3c281993-02-10 14:10:56 +0000380#endif /* AL_405 */
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000381 ALfreeconfig(c);
Jack Jansen743db361992-08-13 14:13:11 +0000382 BGN_SAVE
Guido van Rossumfc58e581992-01-27 16:45:55 +0000383 ALwritesamps (self-> ob_port, (void *) buf, (long) size / width);
Jack Jansen743db361992-08-13 14:13:11 +0000384 END_SAVE
Guido van Rossume3db8621991-09-09 23:33:34 +0000385
386 INCREF (None);
387 return None;
388}
389
390static object *
391al_getfillpoint (self, args)
392 portobject *self;
393 object *args;
394{
395 long count;
396
Guido van Rossumfc58e581992-01-27 16:45:55 +0000397 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000398
399 count = ALgetfillpoint (self-> ob_port);
400
401 return newintobject (count);
402}
403
404static object *
405al_setfillpoint (self, args)
406 portobject *self;
407 object *args;
408{
409 long count;
410
Guido van Rossumfc58e581992-01-27 16:45:55 +0000411 if (!getlongarg (args, &count)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000412
413 ALsetfillpoint (self-> ob_port, count);
414
415 INCREF (None);
416 return (None);
417}
418
419static object *
420al_setconfig (self, args)
421 portobject *self;
422 object *args;
423{
424 ALconfig config;
425
Guido van Rossumfc58e581992-01-27 16:45:55 +0000426 if (!getconfigarg (args, &config)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000427
428 ALsetconfig (self-> ob_port, config);
429
430 INCREF (None);
431 return (None);
432}
433
434static object *
435al_getconfig (self, args)
436 portobject *self;
437 object *args;
438{
439 ALconfig config;
440
Guido van Rossumfc58e581992-01-27 16:45:55 +0000441 if (!getnoarg (args)) return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000442
443 config = ALgetconfig (self-> ob_port);
444
445 return newconfigobject (config);
446}
447
Jack Jansene8a3c281993-02-10 14:10:56 +0000448#ifdef AL_405
449static object *
450al_getstatus (self, args)
451 portobject *self;
452 object *args;
453{
454 object *list, *v;
455 long *PVbuffer;
456 long length;
457 int i;
458
459 if (!getargs(args, "O", &list))
460 return NULL;
461 if (!is_listobject(list)) {
462 err_badarg();
463 return NULL;
464 }
465 length = getlistsize(list);
466 PVbuffer = NEW(long, length);
467 if (PVbuffer == NULL)
468 return err_nomem();
469 for (i = 0; i < length; i++) {
470 v = getlistitem(list, i);
471 if (!is_intobject(v)) {
472 DEL(PVbuffer);
473 err_badarg();
474 return NULL;
475 }
476 PVbuffer[i] = getintvalue(v);
477 }
478
479 ALgetstatus(self->ob_port, PVbuffer, length);
480
481 for (i = 0; i < length; i++)
482 setlistitem(list, i, newintobject(PVbuffer[i]));
483
484 DEL(PVbuffer);
485
486 INCREF(None);
487 return None;
488}
489#endif /* AL_405 */
490
Guido van Rossume3db8621991-09-09 23:33:34 +0000491static struct methodlist port_methods[] = {
492 {"closeport", al_closeport},
Sjoerd Mullender7030b1f1993-12-20 17:26:34 +0000493 {"close", al_closeport},
Guido van Rossume3db8621991-09-09 23:33:34 +0000494 {"getfd", al_getfd},
Jack Jansen743db361992-08-13 14:13:11 +0000495 {"fileno", al_getfd},
Guido van Rossume3db8621991-09-09 23:33:34 +0000496 {"getfilled", al_getfilled},
497 {"getfillable", al_getfillable},
498 {"readsamps", al_readsamps},
499 {"writesamps", al_writesamps},
500 {"setfillpoint", al_setfillpoint},
501 {"getfillpoint", al_getfillpoint},
502 {"setconfig", al_setconfig},
503 {"getconfig", al_getconfig},
Jack Jansene8a3c281993-02-10 14:10:56 +0000504#ifdef AL_405
505 {"getstatus", al_getstatus},
506#endif /* AL_405 */
Guido van Rossume3db8621991-09-09 23:33:34 +0000507 {NULL, NULL} /* sentinel */
508};
509
510static void
511port_dealloc(p)
512 portobject *p;
513{
514 if (p->ob_port != NULL)
515 ALcloseport(p->ob_port);
516 DEL(p);
517}
518
519static object *
520port_getattr(p, name)
521 portobject *p;
522 char *name;
523{
524 return findmethod(port_methods, (object *)p, name);
525}
526
527typeobject Porttype = {
528 OB_HEAD_INIT(&Typetype)
529 0, /*ob_size*/
530 "port", /*tp_name*/
531 sizeof(portobject), /*tp_size*/
532 0, /*tp_itemsize*/
533 /* methods */
534 port_dealloc, /*tp_dealloc*/
535 0, /*tp_print*/
536 port_getattr, /*tp_getattr*/
537 0, /*tp_setattr*/
538 0, /*tp_compare*/
539 0, /*tp_repr*/
540};
541
542static object *
543newportobject(port)
544 ALport port;
545{
546 portobject *p;
547
548 p = NEWOBJ(portobject, &Porttype);
549 if (p == NULL)
550 return NULL;
551 p->ob_port = port;
552 return (object *)p;
553}
554
555/* the module al */
556
557static object *
558al_openport (self, args)
559 object *self, *args;
560{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000561 char *name, *dir;
Guido van Rossume3db8621991-09-09 23:33:34 +0000562 ALport port;
563 ALconfig config = NULL;
Guido van Rossumc0aab891991-10-20 20:10:46 +0000564 int size;
Guido van Rossume3db8621991-09-09 23:33:34 +0000565
Guido van Rossumc0aab891991-10-20 20:10:46 +0000566 if (args == NULL || !is_tupleobject(args)) {
Guido van Rossumfc58e581992-01-27 16:45:55 +0000567 err_badarg ();
Guido van Rossumc0aab891991-10-20 20:10:46 +0000568 return NULL;
569 }
570 size = gettuplesize(args);
Guido van Rossume3db8621991-09-09 23:33:34 +0000571 if (size == 2) {
Guido van Rossum234f9421993-06-17 12:35:49 +0000572 if (!getargs (args, "(ss)", &name, &dir))
Guido van Rossume3db8621991-09-09 23:33:34 +0000573 return NULL;
574 }
575 else if (size == 3) {
576 if (!getstrstrconfigarg (args, &name, &dir, &config))
577 return NULL;
578 }
579 else {
Guido van Rossumfc58e581992-01-27 16:45:55 +0000580 err_badarg ();
Guido van Rossume3db8621991-09-09 23:33:34 +0000581 return NULL;
582 }
583
Guido van Rossumfc58e581992-01-27 16:45:55 +0000584 port = ALopenport(name, dir, config);
Guido van Rossume3db8621991-09-09 23:33:34 +0000585
Guido van Rossumc0aab891991-10-20 20:10:46 +0000586 if (port == NULL) {
587 err_errno(RuntimeError);
588 return NULL;
589 }
590
Guido van Rossume3db8621991-09-09 23:33:34 +0000591 return newportobject (port);
592}
593
594static object *
595al_newconfig (self, args)
596 object *self, *args;
597{
598 ALconfig config;
599
600 if (!getnoarg (args)) return NULL;
601
602 config = ALnewconfig ();
Guido van Rossumc0aab891991-10-20 20:10:46 +0000603 if (config == NULL) {
604 err_errno(RuntimeError);
605 return NULL;
606 }
Guido van Rossume3db8621991-09-09 23:33:34 +0000607
608 return newconfigobject (config);
609}
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000610
611static object *
612al_queryparams(self, args)
613 object *self, *args;
614{
615 long device;
616 long length;
617 long *PVbuffer;
618 long PVdummy[2];
619 object *v;
620 object *w;
621
Guido van Rossumfc58e581992-01-27 16:45:55 +0000622 if (!getlongarg (args, &device))
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000623 return NULL;
624 length = ALqueryparams(device, PVdummy, 2L);
625 PVbuffer = NEW(long, length);
626 if (PVbuffer == NULL)
627 return err_nomem();
628 (void) ALqueryparams(device, PVbuffer, length);
629 v = newlistobject((int)length);
630 if (v != NULL) {
631 int i;
632 for (i = 0; i < length; i++)
633 setlistitem(v, i, newintobject(PVbuffer[i]));
634 }
635 DEL(PVbuffer);
636 return v;
637}
638
639static object *
640doParams(args, func, modified)
641 object *args;
642 void (*func)(long, long *, long);
643 int modified;
644{
645 long device;
646 object *list, *v;
647 long *PVbuffer;
648 long length;
649 int i;
Guido van Rossume3db8621991-09-09 23:33:34 +0000650
Guido van Rossumfc58e581992-01-27 16:45:55 +0000651 if (!getargs(args, "(lO)", &device, &list))
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000652 return NULL;
653 if (!is_listobject(list)) {
654 err_badarg();
655 return NULL;
656 }
657 length = getlistsize(list);
658 PVbuffer = NEW(long, length);
659 if (PVbuffer == NULL)
660 return err_nomem();
661 for (i = 0; i < length; i++) {
662 v = getlistitem(list, i);
663 if (!is_intobject(v)) {
664 DEL(PVbuffer);
665 err_badarg();
666 return NULL;
667 }
668 PVbuffer[i] = getintvalue(v);
669 }
670
Guido van Rossum8db03071991-09-13 15:31:47 +0000671 (*func)(device, PVbuffer, length);
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000672
673 if (modified) {
674 for (i = 0; i < length; i++)
675 setlistitem(list, i, newintobject(PVbuffer[i]));
676 }
677
Guido van Rossumc0aab891991-10-20 20:10:46 +0000678 DEL(PVbuffer);
679
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000680 INCREF(None);
681 return None;
682}
683
684static object *
685al_getparams(self, args)
686 object *self, *args;
687{
688 return doParams(args, ALgetparams, 1);
689}
690
691static object *
692al_setparams(self, args)
693 object *self, *args;
694{
695 return doParams(args, ALsetparams, 0);
696}
697
Guido van Rossum448f4bf1992-08-19 16:41:15 +0000698static object *
699al_getname(self, args)
700 object *self, *args;
701{
702 long device, descriptor;
703 char *name;
704 if (!getargs(args, "(ll)", &device, &descriptor))
705 return NULL;
706 name = ALgetname(device, descriptor);
707 if (name == NULL) {
708 err_setstr(ValueError, "al.getname: bad descriptor");
709 return NULL;
710 }
711 return newstringobject(name);
712}
713
714static object *
715al_getdefault(self, args)
716 object *self, *args;
717{
718 long device, descriptor, value;
719 if (!getargs(args, "(ll)", &device, &descriptor))
720 return NULL;
721 value = ALgetdefault(device, descriptor);
722 return newlongobject(value);
723}
724
725static object *
726al_getminmax(self, args)
727 object *self, *args;
728{
729 long device, descriptor, min, max;
730 if (!getargs(args, "(ll)", &device, &descriptor))
731 return NULL;
732 min = -1;
733 max = -1;
734 ALgetminmax(device, descriptor, &min, &max);
735 return mkvalue("ll", min, max);
736}
737
Guido van Rossume3db8621991-09-09 23:33:34 +0000738static struct methodlist al_methods[] = {
739 {"openport", al_openport},
740 {"newconfig", al_newconfig},
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +0000741 {"queryparams", al_queryparams},
742 {"getparams", al_getparams},
743 {"setparams", al_setparams},
Guido van Rossum448f4bf1992-08-19 16:41:15 +0000744 {"getname", al_getname},
745 {"getdefault", al_getdefault},
746 {"getminmax", al_getminmax},
Guido van Rossume3db8621991-09-09 23:33:34 +0000747 {NULL, NULL} /* sentinel */
748};
749
750void
751inital()
752{
753 initmodule("al", al_methods);
754}
755
Guido van Rossumfc58e581992-01-27 16:45:55 +0000756static int
757getconfigarg(o, conf)
758 object *o;
Guido van Rossume3db8621991-09-09 23:33:34 +0000759 ALconfig *conf;
760{
761 if (o == NULL || !is_configobject(o))
762 return err_badarg ();
763
Guido van Rossumfc58e581992-01-27 16:45:55 +0000764 *conf = ((configobject *) o) -> ob_config;
Guido van Rossume3db8621991-09-09 23:33:34 +0000765
766 return 1;
767}
768
Guido van Rossumfc58e581992-01-27 16:45:55 +0000769static int
Guido van Rossume3db8621991-09-09 23:33:34 +0000770getstrstrconfigarg(v, a, b, c)
771 object *v;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000772 char **a;
773 char **b;
Guido van Rossume3db8621991-09-09 23:33:34 +0000774 ALconfig *c;
775{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000776 object *o;
777 return getargs(v, "(ssO)", a, b, &o) && getconfigarg(o, c);
Guido van Rossume3db8621991-09-09 23:33:34 +0000778}