Renamed, however there is no test case. I did test some of the module
out manually, and it does compile, but I'm not sure how to write a useful portable test case. Maybe later...
This commit is contained in:
parent
0caa7ec206
commit
8496d39478
|
@ -31,8 +31,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* Sad objects */
|
||||
|
||||
#include "allobjects.h"
|
||||
#include "modsupport.h"
|
||||
#include "Python.h"
|
||||
#include "structmember.h"
|
||||
|
||||
#ifdef HAVE_SYS_AUDIOIO_H
|
||||
|
@ -58,7 +57,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
|||
/* #define offsetof(str,mem) ((int)(((str *)0)->mem)) */
|
||||
|
||||
typedef struct {
|
||||
OB_HEAD
|
||||
PyObject_HEAD
|
||||
int x_fd; /* The open file */
|
||||
int x_icount; /* # samples read */
|
||||
int x_ocount; /* # samples written */
|
||||
|
@ -67,22 +66,22 @@ typedef struct {
|
|||
} sadobject;
|
||||
|
||||
typedef struct {
|
||||
OB_HEAD
|
||||
PyObject_HEAD
|
||||
audio_info_t ai;
|
||||
} sadstatusobject;
|
||||
|
||||
staticforward typeobject Sadtype;
|
||||
staticforward typeobject Sadstatustype;
|
||||
staticforward PyTypeObject Sadtype;
|
||||
staticforward PyTypeObject Sadstatustype;
|
||||
static sadstatusobject *sads_alloc(); /* Forward */
|
||||
|
||||
static object *SunAudioError;
|
||||
static PyObject *SunAudioError;
|
||||
|
||||
#define is_sadobject(v) ((v)->ob_type == &Sadtype)
|
||||
#define is_sadstatusobject(v) ((v)->ob_type == &Sadstatustype)
|
||||
|
||||
static sadobject *
|
||||
newsadobject(arg)
|
||||
object *arg;
|
||||
PyObject *arg;
|
||||
{
|
||||
sadobject *xp;
|
||||
int fd;
|
||||
|
@ -90,34 +89,35 @@ newsadobject(arg)
|
|||
int imode;
|
||||
|
||||
/* Check arg for r/w/rw */
|
||||
if ( !getargs(arg, "s", &mode) )
|
||||
return 0;
|
||||
if ( strcmp(mode, "r") == 0 )
|
||||
imode = 0;
|
||||
else if ( strcmp(mode, "w") == 0 )
|
||||
imode = 1;
|
||||
else if ( strcmp(mode, "rw") == 0 )
|
||||
imode = 2;
|
||||
else if ( strcmp(mode, "control") == 0 )
|
||||
imode = -1;
|
||||
if (!PyArg_Parse(arg, "s", &mode))
|
||||
return NULL;
|
||||
if (strcmp(mode, "r") == 0)
|
||||
imode = 0;
|
||||
else if (strcmp(mode, "w") == 0)
|
||||
imode = 1;
|
||||
else if (strcmp(mode, "rw") == 0)
|
||||
imode = 2;
|
||||
else if (strcmp(mode, "control") == 0)
|
||||
imode = -1;
|
||||
else {
|
||||
err_setstr(SunAudioError,
|
||||
"Mode should be one of 'r', 'w', 'rw' or 'control'");
|
||||
return 0;
|
||||
PyErr_SetString(SunAudioError,
|
||||
"Mode should be one of 'r', 'w', 'rw' or 'control'");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Open the correct device */
|
||||
if ( imode < 0 )
|
||||
fd = open("/dev/audioctl", 2); /* XXXX Chaeck that this works */
|
||||
if (imode < 0)
|
||||
/* XXXX Check that this works */
|
||||
fd = open("/dev/audioctl", 2);
|
||||
else
|
||||
fd = open("/dev/audio", imode);
|
||||
if ( fd < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
fd = open("/dev/audio", imode);
|
||||
if (fd < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create and initialize the object */
|
||||
xp = NEWOBJ(sadobject, &Sadtype);
|
||||
xp = PyObject_NEW(sadobject, &Sadtype);
|
||||
if (xp == NULL)
|
||||
return NULL;
|
||||
xp->x_fd = fd;
|
||||
|
@ -134,242 +134,249 @@ sad_dealloc(xp)
|
|||
sadobject *xp;
|
||||
{
|
||||
close(xp->x_fd);
|
||||
DEL(xp);
|
||||
PyMem_DEL(xp);
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_read(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
PyObject *args;
|
||||
{
|
||||
int size, count;
|
||||
char *cp;
|
||||
object *rv;
|
||||
PyObject *rv;
|
||||
|
||||
if ( !getargs(args, "i", &size) )
|
||||
return 0;
|
||||
rv = newsizedstringobject(NULL, size);
|
||||
if ( rv == NULL )
|
||||
return 0;
|
||||
if (!PyArg_Parse(args, "i", &size))
|
||||
return NULL;
|
||||
rv = PyString_FromStringAndSize(NULL, size);
|
||||
if (rv == NULL)
|
||||
return NULL;
|
||||
|
||||
cp = getstringvalue(rv);
|
||||
if (!(cp = PyString_AsString(rv)))
|
||||
goto finally;
|
||||
|
||||
count = read(self->x_fd, cp, size);
|
||||
if ( count < 0 ) {
|
||||
DECREF(rv);
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
if (count < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
goto finally;
|
||||
}
|
||||
if ( count != size )
|
||||
printf("sunaudio: funny read rv %d wtd %d\n", count, size);
|
||||
#if 0
|
||||
/* TBD: why print this message if you can handle the condition?
|
||||
assume it's debugging info which we can just as well get rid
|
||||
of. in any case this message should *not* be using printf!
|
||||
*/
|
||||
if (count != size)
|
||||
printf("sunaudio: funny read rv %d wtd %d\n", count, size);
|
||||
#endif
|
||||
self->x_icount += count;
|
||||
return rv;
|
||||
|
||||
finally:
|
||||
Py_DECREF(rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_write(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
PyObject *args;
|
||||
{
|
||||
char *cp;
|
||||
int count, size;
|
||||
|
||||
if ( !getargs(args, "s#", &cp, &size) )
|
||||
return 0;
|
||||
if (!PyArg_Parse(args, "s#", &cp, &size))
|
||||
return NULL;
|
||||
|
||||
count = write(self->x_fd, cp, size);
|
||||
if ( count < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
if (count < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
if ( count != size )
|
||||
printf("sunaudio: funny write rv %d wanted %d\n", count, size);
|
||||
#if 0
|
||||
if (count != size)
|
||||
printf("sunaudio: funny write rv %d wanted %d\n", count, size);
|
||||
#endif
|
||||
self->x_ocount += count;
|
||||
|
||||
INCREF(None);
|
||||
return None;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_getinfo(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
sadstatusobject *rv;
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return NULL;
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
rv = sads_alloc();
|
||||
if ( ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
DECREF(rv);
|
||||
if (ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
Py_DECREF(rv);
|
||||
return NULL;
|
||||
}
|
||||
return (object *)rv;
|
||||
return (PyObject *)rv;
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_setinfo(self, arg)
|
||||
sadobject *self;
|
||||
sadstatusobject *arg;
|
||||
sadobject *self;
|
||||
sadstatusobject *arg;
|
||||
{
|
||||
if ( !is_sadstatusobject(arg) ) {
|
||||
err_setstr(TypeError, "Must be sun audio status object");
|
||||
if (!is_sadstatusobject(arg)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Must be sun audio status object");
|
||||
return NULL;
|
||||
}
|
||||
if ( ioctl(self->x_fd, AUDIO_SETINFO, &arg->ai) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
if (ioctl(self->x_fd, AUDIO_SETINFO, &arg->ai) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
INCREF(None);
|
||||
return None;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_ibufcount(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
audio_info_t ai;
|
||||
object *rv;
|
||||
audio_info_t ai;
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return 0;
|
||||
if ( ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
rv = newintobject(ai.record.samples - self->x_icount);
|
||||
return rv;
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
return PyInt_FromLong(ai.record.samples - self->x_icount);
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_obufcount(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
audio_info_t ai;
|
||||
object *rv;
|
||||
audio_info_t ai;
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return 0;
|
||||
if ( ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
rv = newintobject(self->x_ocount - ai.play.samples);
|
||||
return rv;
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
return PyInt_FromLong(self->x_ocount - ai.play.samples);
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_drain(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return 0;
|
||||
if ( ioctl(self->x_fd, AUDIO_DRAIN, 0) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
INCREF(None);
|
||||
return None;
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
if (ioctl(self->x_fd, AUDIO_DRAIN, 0) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
#ifdef SOLARIS
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_getdev(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
struct audio_device ad;
|
||||
struct audio_device ad;
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return 0;
|
||||
if ( ioctl(self->x_fd, AUDIO_GETDEV, &ad) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
return mkvalue("(sss)", ad.name, ad.version, ad.config);
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
if (ioctl(self->x_fd, AUDIO_GETDEV, &ad) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("(sss)", ad.name, ad.version, ad.config);
|
||||
}
|
||||
#endif
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_flush(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return 0;
|
||||
if ( ioctl(self->x_fd, I_FLUSH, FLUSHW) < 0 ) {
|
||||
err_errno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
INCREF(None);
|
||||
return None;
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
if (ioctl(self->x_fd, I_FLUSH, FLUSHW) < 0) {
|
||||
PyErr_SetFromErrno(SunAudioError);
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_close(self, args)
|
||||
sadobject *self;
|
||||
object *args;
|
||||
sadobject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
|
||||
if ( !getargs(args, "") )
|
||||
return 0;
|
||||
if ( self->x_fd >= 0 ) {
|
||||
close(self->x_fd);
|
||||
self->x_fd = -1;
|
||||
}
|
||||
INCREF(None);
|
||||
return None;
|
||||
if (!PyArg_Parse(args, ""))
|
||||
return NULL;
|
||||
if (self->x_fd >= 0) {
|
||||
close(self->x_fd);
|
||||
self->x_fd = -1;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static struct methodlist sad_methods[] = {
|
||||
{ "read", (method)sad_read },
|
||||
{ "write", (method)sad_write },
|
||||
{ "ibufcount", (method)sad_ibufcount },
|
||||
{ "obufcount", (method)sad_obufcount },
|
||||
static PyMethodDef sad_methods[] = {
|
||||
{ "read", (PyCFunction)sad_read },
|
||||
{ "write", (PyCFunction)sad_write },
|
||||
{ "ibufcount", (PyCFunction)sad_ibufcount },
|
||||
{ "obufcount", (PyCFunction)sad_obufcount },
|
||||
#define CTL_METHODS 4
|
||||
{ "getinfo", (method)sad_getinfo },
|
||||
{ "setinfo", (method)sad_setinfo },
|
||||
{ "drain", (method)sad_drain },
|
||||
{ "flush", (method)sad_flush },
|
||||
{ "getinfo", (PyCFunction)sad_getinfo },
|
||||
{ "setinfo", (PyCFunction)sad_setinfo },
|
||||
{ "drain", (PyCFunction)sad_drain },
|
||||
{ "flush", (PyCFunction)sad_flush },
|
||||
#ifdef SOLARIS
|
||||
{ "getdev", (method)sad_getdev },
|
||||
{ "getdev", (PyCFunction)sad_getdev },
|
||||
#endif
|
||||
{ "close", (method)sad_close },
|
||||
{ "close", (PyCFunction)sad_close },
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sad_getattr(xp, name)
|
||||
sadobject *xp;
|
||||
char *name;
|
||||
{
|
||||
if ( xp->x_isctl )
|
||||
return findmethod(sad_methods+CTL_METHODS, (object *)xp, name);
|
||||
if (xp->x_isctl)
|
||||
return Py_FindMethod(sad_methods+CTL_METHODS,
|
||||
(PyObject *)xp, name);
|
||||
else
|
||||
return findmethod(sad_methods, (object *)xp, name);
|
||||
return Py_FindMethod(sad_methods, (PyObject *)xp, name);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
static sadstatusobject *
|
||||
sads_alloc() {
|
||||
sadstatusobject *rv;
|
||||
|
||||
rv = NEWOBJ(sadstatusobject, &Sadstatustype);
|
||||
return rv;
|
||||
return PyObject_NEW(sadstatusobject, &Sadstatustype);
|
||||
}
|
||||
|
||||
static void
|
||||
sads_dealloc(xp)
|
||||
sadstatusobject *xp;
|
||||
sadstatusobject *xp;
|
||||
{
|
||||
DEL(xp);
|
||||
PyMem_DEL(xp);
|
||||
}
|
||||
|
||||
#define OFF(x) offsetof(audio_info_t,x)
|
||||
|
@ -416,34 +423,34 @@ static struct memberlist sads_ml[] = {
|
|||
{ NULL, 0, 0},
|
||||
};
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sads_getattr(xp, name)
|
||||
sadstatusobject *xp;
|
||||
char *name;
|
||||
sadstatusobject *xp;
|
||||
char *name;
|
||||
{
|
||||
return getmember((char *)&xp->ai, sads_ml, name);
|
||||
return PyMember_Get((char *)&xp->ai, sads_ml, name);
|
||||
}
|
||||
|
||||
static int
|
||||
sads_setattr(xp, name, v)
|
||||
sadstatusobject *xp;
|
||||
char *name;
|
||||
object *v;
|
||||
sadstatusobject *xp;
|
||||
char *name;
|
||||
PyObject *v;
|
||||
{
|
||||
|
||||
if (v == NULL) {
|
||||
err_setstr(TypeError,
|
||||
"can't delete sun audio status attributes");
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"can't delete sun audio status attributes");
|
||||
return -1;
|
||||
}
|
||||
return setmember((char *)&xp->ai, sads_ml, name, v);
|
||||
return PyMember_Set((char *)&xp->ai, sads_ml, name, v);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static typeobject Sadtype = {
|
||||
OB_HEAD_INIT(&Typetype)
|
||||
static PyTypeObject Sadtype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"sun_audio_device", /*tp_name*/
|
||||
sizeof(sadobject), /*tp_size*/
|
||||
|
@ -457,8 +464,8 @@ static typeobject Sadtype = {
|
|||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
static typeobject Sadstatustype = {
|
||||
OB_HEAD_INIT(&Typetype)
|
||||
static PyTypeObject Sadstatustype = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"sun_audio_device_status", /*tp_name*/
|
||||
sizeof(sadstatusobject), /*tp_size*/
|
||||
|
@ -473,29 +480,28 @@ static typeobject Sadstatustype = {
|
|||
};
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
static object *
|
||||
static PyObject *
|
||||
sadopen(self, args)
|
||||
object *self;
|
||||
object *args;
|
||||
PyObject *self;
|
||||
PyObject *args;
|
||||
{
|
||||
object *rv;
|
||||
|
||||
rv = (object *)newsadobject(args);
|
||||
return rv;
|
||||
return (PyObject *)newsadobject(args);
|
||||
}
|
||||
|
||||
static struct methodlist sunaudiodev_methods[] = {
|
||||
static PyMethodDef sunaudiodev_methods[] = {
|
||||
{ "open", sadopen },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
void
|
||||
initsunaudiodev() {
|
||||
object *m, *d;
|
||||
initsunaudiodev()
|
||||
{
|
||||
PyObject *m, *d;
|
||||
|
||||
m = initmodule("sunaudiodev", sunaudiodev_methods);
|
||||
d = getmoduledict(m);
|
||||
SunAudioError = newstringobject("sunaudiodev.error");
|
||||
if ( SunAudioError == NULL || dictinsert(d, "error", SunAudioError) )
|
||||
fatal("can't define sunaudiodev.error");
|
||||
m = Py_InitModule("sunaudiodev", sunaudiodev_methods);
|
||||
d = PyModule_GetDict(m);
|
||||
SunAudioError = PyString_FromString("sunaudiodev.error");
|
||||
if ( SunAudioError == NULL ||
|
||||
PyDict_SetItemString(d, "error", SunAudioError) )
|
||||
Py_FatalError("can't define sunaudiodev.error");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue