Skip to contentSkip to conversation

alsa-python: add register_poll to alsaseq

PATCH Applied Hector Martin 2 participants 2 messages May 12, 2010 – May 27, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alsa-python: add register_poll to alsaseq

Attached patch adds register_poll to the sequencer bindings to support nonblocking sequencer access with the select module.

I sent this last month but it looks like it was overlooked. Resending.

Signature · 2 lines
Hector Martin ([email protected])
Public Key: http://www.marcansoft.com/marcan.asc
Quoted 1 line

From f801ff2f940b24c3ee3f27271ec4b249a2c67fb8 Mon Sep 17 00:00:00 2001

From: Hector Martin <[email protected]>
Date: Wed, 21 Apr 2010 05:54:49 +0200
Subject: [PATCH] Add register_poll for alsaseq

---
 pyalsa/alsaseq.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
pyalsa/alsaseq.c +51 -0
index de131a4..bbf6b2e 100644
@@ -3236,6 +3236,53 @@ Sequencer_stop_queue(SequencerObject *self,
   Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(Sequencer_registerpoll__doc__,
+"register_poll(pollObj, input=False, output=False) -- Register poll file descriptors.");
+
+static PyObject *
+Sequencer_registerpoll(SequencerObject *self, PyObject *args, PyObject *kwds)
+{
+    PyObject *pollObj, *reg, *t;
+    struct pollfd *pfd;
+    int i, count;
+    int input = 0;
+    int output = 0;
+    int mode = POLLIN|POLLOUT;
+
+    static char * kwlist[] = { "pollObj", "input", "output", NULL };
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ii", kwlist, &pollObj, &input, &output))
+        return NULL;
+
+    if (input && !output)
+        mode = POLLIN;
+    else if (!input && output)
+        mode = POLLOUT;
+
+    count = snd_seq_poll_descriptors_count(self->handle, mode);
+    if (count <= 0)
+        Py_RETURN_NONE;
+    pfd = alloca(sizeof(struct pollfd) * count);
+    count = snd_seq_poll_descriptors(self->handle, pfd, count, mode);
+    if (count <= 0)
+        Py_RETURN_NONE;
+
+    reg = PyObject_GetAttr(pollObj, PyString_InternFromString("register"));
+
+    for (i = 0; i < count; i++) {
+        t = PyTuple_New(2);
+        if (t) {
+            PyTuple_SET_ITEM(t, 0, PyInt_FromLong(pfd[i].fd));
+            PyTuple_SET_ITEM(t, 1, PyInt_FromLong(pfd[i].events));
+            Py_XDECREF(PyObject_CallObject(reg, t));
+            Py_DECREF(t);
+        }
+    }
+
+    Py_XDECREF(reg);
+
+    Py_RETURN_NONE;
+}
 
 
 
@@ -3309,6 +3356,10 @@ static PyMethodDef Sequencer_methods[] = {
    (PyCFunction) Sequencer_stop_queue,
    METH_VARARGS | METH_KEYWORDS,
    Sequencer_stop_queue__doc__},
+  {"register_poll",
+   (PyCFunction) Sequencer_registerpoll,
+   METH_VARARGS | METH_KEYWORDS,
+   Sequencer_registerpoll__doc__},
   {NULL}
 };
 
Signature · 1 line
1.6.4.4

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Applied
#1 lore raw

At Wed, 12 May 2010 03:51:34 +0200,

Quoted 5 lines · Hector Martin

Attached patch adds register_poll to the sequencer bindings to support nonblocking sequencer access with the select module.

I sent this last month but it looks like it was overlooked. Resending.

Thanks, applied now.

Takashi

Quoted 94 lines
Signature · 6 lines
-- 
Hector Martin ([email protected])
Public Key: http://www.marcansoft.com/marcan.asc


[2 0001-Add-register_poll-for-alsaseq.patch <text/plain (7bit)>]
Quoted 1 line

From f801ff2f940b24c3ee3f27271ec4b249a2c67fb8 Mon Sep 17 00:00:00 2001

From: Hector Martin <[email protected]>
Date: Wed, 21 Apr 2010 05:54:49 +0200
Subject: [PATCH] Add register_poll for alsaseq

---
 pyalsa/alsaseq.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
pyalsa/alsaseq.c +51 -0
index de131a4..bbf6b2e 100644
@@ -3236,6 +3236,53 @@ Sequencer_stop_queue(SequencerObject *self,
   Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(Sequencer_registerpoll__doc__,
+"register_poll(pollObj, input=False, output=False) -- Register poll file descriptors.");
+
+static PyObject *
+Sequencer_registerpoll(SequencerObject *self, PyObject *args, PyObject *kwds)
+{
+    PyObject *pollObj, *reg, *t;
+    struct pollfd *pfd;
+    int i, count;
+    int input = 0;
+    int output = 0;
+    int mode = POLLIN|POLLOUT;
+
+    static char * kwlist[] = { "pollObj", "input", "output", NULL };
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ii", kwlist, &pollObj, &input, &output))
+        return NULL;
+
+    if (input && !output)
+        mode = POLLIN;
+    else if (!input && output)
+        mode = POLLOUT;
+
+    count = snd_seq_poll_descriptors_count(self->handle, mode);
+    if (count <= 0)
+        Py_RETURN_NONE;
+    pfd = alloca(sizeof(struct pollfd) * count);
+    count = snd_seq_poll_descriptors(self->handle, pfd, count, mode);
+    if (count <= 0)
+        Py_RETURN_NONE;
+
+    reg = PyObject_GetAttr(pollObj, PyString_InternFromString("register"));
+
+    for (i = 0; i < count; i++) {
+        t = PyTuple_New(2);
+        if (t) {
+            PyTuple_SET_ITEM(t, 0, PyInt_FromLong(pfd[i].fd));
+            PyTuple_SET_ITEM(t, 1, PyInt_FromLong(pfd[i].events));
+            Py_XDECREF(PyObject_CallObject(reg, t));
+            Py_DECREF(t);
+        }
+    }
+
+    Py_XDECREF(reg);
+
+    Py_RETURN_NONE;
+}
 
 
 
@@ -3309,6 +3356,10 @@ static PyMethodDef Sequencer_methods[] = {
    (PyCFunction) Sequencer_stop_queue,
    METH_VARARGS | METH_KEYWORDS,
    Sequencer_stop_queue__doc__},
+  {"register_poll",
+   (PyCFunction) Sequencer_registerpoll,
+   METH_VARARGS | METH_KEYWORDS,
+   Sequencer_registerpoll__doc__},
   {NULL}
 };
 
Signature · 7 lines
1.6.4.4

[3  <text/plain; us-ascii (7bit)>]
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel