| 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 |
|
|---|
| 10 | typedef struct {
|
|---|
| 11 | PyObject_HEAD
|
|---|
| 12 | CDPLAYER *ob_cdplayer;
|
|---|
| 13 | } cdplayerobject;
|
|---|
| 14 |
|
|---|
| 15 | static PyObject *CdError; /* exception cd.error */
|
|---|
| 16 |
|
|---|
| 17 | static PyObject *
|
|---|
| 18 | CD_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 |
|
|---|
| 29 | static PyObject *
|
|---|
| 30 | CD_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 |
|
|---|
| 41 | static PyObject *
|
|---|
| 42 | CD_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 |
|
|---|
| 50 | static PyObject *
|
|---|
| 51 | CD_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 |
|
|---|
| 66 | static PyObject *
|
|---|
| 67 | CD_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 |
|
|---|
| 87 | static PyObject *
|
|---|
| 88 | CD_getstatus(cdplayerobject *self, PyObject *args)
|
|---|
| 89 | {
|
|---|
| 90 | CDSTATUS status;
|
|---|
|
|---|