source: trunk/essentials/dev-lang/python/Modules/cdmodule.c@ 3408

Last change on this file since 3408 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 18.8 KB
Line 
1/* CD module -- interface to Mark Callow's and Roger Chickering's */
2 /* CD Audio Library (CD). */
3
4#include <sys/types.h>
5#include <cdaudio.h>
6#include "Python.h"
7
8#define NCALLBACKS 8
9
10typedef struct {
11 PyObject_HEAD
12 CDPLAYER *ob_cdplayer;
13} cdplayerobject;
14
15static PyObject *CdError; /* exception cd.error */
16
17static PyObject *
18CD_allowremoval(cdplayerobject *self, PyObject *args)
19{
20 if (!PyArg_ParseTuple(args, ":allowremoval"))
21 return NULL;
22
23 CDallowremoval(self->ob_cdplayer);
24
25 Py_INCREF(Py_None);
26 return Py_None;
27}
28
29static PyObject *
30CD_preventremoval(cdplayerobject *self, PyObject *args)
31{
32 if (!PyArg_ParseTuple(args, ":preventremoval"))
33 return NULL;
34
35 CDpreventremoval(self->ob_cdplayer);
36
37 Py_INCREF(Py_None);
38 return Py_None;
39}
40
41static PyObject *
42CD_bestreadsize(cdplayerobject *self, PyObject *args)
43{
44 if (!PyArg_ParseTuple(args, ":bestreadsize"))
45 return NULL;
46
47 return PyInt_FromLong((long) CDbestreadsize(self->ob_cdplayer));
48}
49
50static PyObject *
51CD_close(cdplayerobject *self, PyObject *args)
52{
53 if (!PyArg_ParseTuple(args, ":close"))
54 return NULL;
55
56 if (!CDclose(self->ob_cdplayer)) {
57 PyErr_SetFromErrno(CdError); /* XXX - ??? */
58 return NULL;
59 }
60 self->ob_cdplayer = NULL;
61
62 Py_INCREF(Py_None);
63 return Py_None;
64}
65
66static PyObject *
67CD_eject(cdplayerobject *self, PyObject *args)
68{
69 CDSTATUS status;
70
71 if (!PyArg_ParseTuple(args, ":eject"))
72 return NULL;
73
74 if (!CDeject(self->ob_cdplayer)) {
75 if (CDgetstatus(self->ob_cdplayer, &status) &&
76 status.state == CD_NODISC)
77 PyErr_SetString(CdError, "no disc in player");
78 else
79 PyErr_SetString(CdError, "eject failed");
80 return NULL;
81 }
82
83 Py_INCREF(Py_None);
84 return Py_None;
85}
86
87static PyObject *
88CD_getstatus(cdplayerobject *self, PyObject *args)
89{
90 CDSTATUS status;