1
/* -*- Mode: C; c-basic-offset: 4 -*-
2
* vi:si:et:sw=4:sts=4:ts=4
5
* Copyright (C) 2005 Edward Hervey
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
22
* Author: Edward Hervey <edward@fluendo.com>
27
gst_bus_sync_signal_handler
28
gst_bus_async_signal_func
31
static GstBusSyncReply
32
bus_sync_handler (GstBus *bus, GstMessage *message, gpointer user_data)
34
PyGILState_STATE state;
36
PyObject *py_userdata;
38
PyObject *callback, *args;
42
g_return_val_if_fail (user_data != NULL, GST_BUS_PASS);
44
state = pyg_gil_state_ensure ();
46
py_userdata = (PyObject *) user_data;
47
py_msg = pygstminiobject_new (GST_MINI_OBJECT (message));
48
callback = PyTuple_GetItem (py_userdata, 0);
50
/* Using N we give away our references to the args tuple */
51
args = Py_BuildValue ("(NN)",
52
pygstobject_new (G_OBJECT (bus)),
55
/* add all *args to the args tuple object */
56
len = PyTuple_Size (py_userdata);
57
for (i = 1; i < len; ++i) {
58
PyObject *tuple = args;
59
args = PySequence_Concat (tuple, PyTuple_GetItem (py_userdata, i));
62
ret = PyObject_CallObject (callback, args);
69
PyErr_SetString (PyExc_TypeError,
70
"callback should return a BusSyncReply");
73
} else if (pyg_enum_get_value (GST_TYPE_BUS_SYNC_REPLY, ret,
81
pyg_gil_state_release (state);
87
bus_func (GstBus *bus, GstMessage *message, gpointer user_data)
89
PyGILState_STATE state;
91
PyObject *py_userdata;
93
PyObject *callback, *args;
97
g_return_val_if_fail (user_data != NULL, TRUE);
99
GST_DEBUG_OBJECT (bus, "dispatching message %p", message);
101
state = pyg_gil_state_ensure ();
103
py_userdata = (PyObject *) user_data;
104
g_assert (PyTuple_Check (py_userdata));
106
py_msg = pygstminiobject_new (GST_MINI_OBJECT (message));
107
callback = PyTuple_GetItem (py_userdata, 0);
109
/* Using N we give away our references to the args tuple */
110
args = Py_BuildValue ("(NN)",
111
pygstobject_new (G_OBJECT (bus)),
115
/* add all *args to the args tuple object */
116
len = PyTuple_Size (py_userdata);
117
for (i = 1; i < len; ++i) {
119
PyObject *tuple = args;
121
item = PyTuple_GetItem (py_userdata, i);
124
args = PySequence_Concat (tuple, item);
129
ret = PyObject_CallObject(callback, args);
135
if (ret == Py_None) {
136
PyErr_SetString (PyExc_TypeError,
137
"callback should return True or False");
141
res = PyObject_IsTrue (ret);
146
pyg_gil_state_release (state);
148
GST_DEBUG_OBJECT (bus, "dispatched message %p", message);
154
override gst_bus_set_sync_handler args
156
_wrap_gst_bus_set_sync_handler (PyGObject *self, PyObject *args)
158
PyObject *callback, *cbargs = NULL, *data;
161
len = PyTuple_Size(args);
164
PyErr_SetString(PyExc_TypeError, "Bus requires at least 1 arg");
167
callback = PySequence_GetItem(args, 0);
168
if (!PyCallable_Check(callback)) {
169
PyErr_SetString(PyExc_TypeError, "callback is not callable");
172
cbargs = PySequence_GetSlice(args, 1, len);
175
data = Py_BuildValue("(ON)", callback, cbargs);
178
gst_bus_set_sync_handler (GST_BUS (self->obj),
179
(GstBusSyncHandler) bus_sync_handler,
186
override gst_bus_add_watch args
188
_wrap_gst_bus_add_watch (PyGObject *self, PyObject *args)
190
PyObject *callback, *cbargs = NULL, *data;
194
len = PyTuple_Size(args);
197
PyErr_SetString(PyExc_TypeError, "Bus.add_watch requires at least 1 argument");
201
callback = PySequence_GetItem(args, 0);
202
if (!PyCallable_Check(callback)) {
203
PyErr_SetString(PyExc_TypeError, "callback is not callable");
206
cbargs = PySequence_GetSlice(args, 1, len);
209
/* FIXME: thomas: I'm pretty sure the second N needs to be O */
210
data = Py_BuildValue("(ON)", callback, cbargs);
214
sigid = gst_bus_add_watch_full (GST_BUS (self->obj), G_PRIORITY_DEFAULT,
215
(GstBusFunc) bus_func, data, (GDestroyNotify)pyg_destroy_notify);
217
return PyInt_FromLong(sigid);
220
override gst_bus_add_signal_watch kwargs
222
_wrap_gst_bus_add_signal_watch(PyGObject *self, PyObject *args, PyObject *kwargs)
224
static char *kwlist[] = { "priority", NULL };
225
int priority = G_PRIORITY_DEFAULT;
227
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:GstBus.add_signal_watch", kwlist, &priority))
229
pyg_begin_allow_threads;
230
gst_bus_add_signal_watch_full(GST_BUS(self->obj), priority);
231
pyg_end_allow_threads;