codegen/codegen.py: let's not forget to wrap the MiniObject :)

Original commit message from CVS:
* codegen/codegen.py: (GstMiniObjectWrapper.constructor_tmpl):
let's not forget to wrap the MiniObject :)
* gst/gst-types.defs:
* gst/gst.defs:
Always keep up to date with the core
* gst/gstelement.override:
override for gst_element_query_position
* gst/pygstminiobject.c:
* gst/pygstminiobject.h:
* gst/gst.override:
PyGstMiniObject now properly wrap GstMiniObject and are referenced in a
global hash table
This commit is contained in:
Edward Hervey 2005-06-28 16:13:53 +00:00
parent 685c434a03
commit 835f29e2bb
8 changed files with 183 additions and 61 deletions

View file

@ -1,3 +1,21 @@
2005-06-28 Edward Hervey <edward@fluendo.com>
* codegen/codegen.py: (GstMiniObjectWrapper.constructor_tmpl):
let's not forget to wrap the MiniObject :)
* gst/gst-types.defs:
* gst/gst.defs:
Always keep up to date with the core
* gst/gstelement.override:
override for gst_element_query_position
* gst/pygstminiobject.c:
* gst/pygstminiobject.h:
* gst/gst.override:
PyGstMiniObject now properly wrap GstMiniObject and are referenced in a
global hash table
2005-06-26 Edward Hervey <edward@fluendo.com>
* codegen/argtypes.py:

View file

@ -832,6 +832,7 @@ class GstMiniObjectWrapper(Wrapper):
' return -1;\n' \
' }\n' \
'%(aftercreate)s' \
' pygstminiobject_register_wrapper((PyObject *)self);\n' \
' return 0;\n' \
'}\n\n'
method_tmpl = \

View file

@ -673,7 +673,7 @@
'("ok" "GST_FLOW_OK")
'("resend" "GST_FLOW_RESEND")
'("error" "GST_FLOW_ERROR")
'("not-connected" "GST_FLOW_NOT_CONNECTED")
'("not-linked" "GST_FLOW_NOT_LINKED")
'("not-negotiated" "GST_FLOW_NOT_NEGOTIATED")
'("wrong-state" "GST_FLOW_WRONG_STATE")
'("unexpected" "GST_FLOW_UNEXPECTED")

View file

@ -1031,6 +1031,18 @@
(return-type "GstIterator*")
)
(define-method iterate_src_pads
(of-object "GstElement")
(c-name "gst_element_iterate_src_pads")
(return-type "GstIterator*")
)
(define-method iterate_sink_pads
(of-object "GstElement")
(c-name "gst_element_iterate_sink_pads")
(return-type "GstIterator*")
)
(define-method send_event
(of-object "GstElement")
(c-name "gst_element_send_event")
@ -2646,22 +2658,28 @@
)
)
(define-method ref
(of-object "GstObject")
(define-function object_ref
(c-name "gst_object_ref")
(return-type "GstObject*")
(return-type "gpointer")
(parameters
'("gpointer" "object")
)
)
(define-method unref
(of-object "GstObject")
(define-function object_unref
(c-name "gst_object_unref")
(return-type "GstObject*")
(return-type "none")
(parameters
'("gpointer" "object")
)
)
(define-method sink
(of-object "GstObject")
(define-function object_sink
(c-name "gst_object_sink")
(return-type "none")
(parameters
'("gpointer" "object")
)
)
(define-function object_replace
@ -2772,16 +2790,7 @@
(c-name "gst_pad_set_active")
(return-type "gboolean")
(parameters
'("GstActivateMode" "mode")
)
)
(define-method peer_set_active
(of-object "GstPad")
(c-name "gst_pad_peer_set_active")
(return-type "gboolean")
(parameters
'("GstActivateMode" "mode")
'("gboolean" "active")
)
)
@ -2791,6 +2800,24 @@
(return-type "gboolean")
)
(define-method activate_pull
(of-object "GstPad")
(c-name "gst_pad_activate_pull")
(return-type "gboolean")
(parameters
'("gboolean" "active")
)
)
(define-method activate_push
(of-object "GstPad")
(c-name "gst_pad_activate_push")
(return-type "gboolean")
(parameters
'("gboolean" "active")
)
)
(define-method set_blocked
(of-object "GstPad")
(c-name "gst_pad_set_blocked")
@ -2868,12 +2895,21 @@
)
)
(define-method set_loop_function
(define-method set_activatepull_function
(of-object "GstPad")
(c-name "gst_pad_set_loop_function")
(c-name "gst_pad_set_activatepull_function")
(return-type "none")
(parameters
'("GstPadLoopFunction" "loop")
'("GstPadActivateModeFunction" "activatepull")
)
)
(define-method set_activatepush_function
(of-object "GstPad")
(c-name "gst_pad_set_activatepush_function")
(return-type "none")
(parameters
'("GstPadActivateModeFunction" "activatepush")
)
)
@ -3322,7 +3358,7 @@
(is-constructor-of "GstPipeline")
(return-type "GstElement*")
(parameters
'("const-gchar*" "name")
'("const-gchar*" "name" (null-ok) (default "NULL"))
)
)
@ -5257,6 +5293,11 @@
(return-type "none")
)
(define-function gst_alloc_trace_print_live
(c-name "gst_alloc_trace_print_live")
(return-type "none")
)
(define-function alloc_trace_set_flags_all
(c-name "gst_alloc_trace_set_flags_all")
(return-type "none")

View file

@ -232,6 +232,7 @@ init
#endif
if (!pygst_value_init())
return;
pygst_miniobject_init();
}
%%
modulename gst

View file

@ -92,6 +92,7 @@ _wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs)
GstElementState state;
GstElementStateReturn ret;
/* Only returns the state for the time being */
ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, NULL, NULL);
if (!ret) {
PyErr_SetString(PyExc_RuntimeError, "conversion could not be performed");
@ -409,3 +410,35 @@ _wrap_gst_element_factory_get_pad_templates(PyGObject *self)
return list;
}
%%
override gst_element_query_position args
static PyObject *
_wrap_gst_element_query_position (PyGObject *self, PyObject *args)
{
gint64 cur, end;
gint format;
PyObject *pformat;
PyObject *ret;
int i;
pformat = (PyObject*)PyTuple_GetItem(args, 0);
if (pyg_enum_get_value (GST_TYPE_FORMAT, pformat, &format)) {
PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat");
return NULL;
}
ret = PyList_New(0);
if ((gst_element_query_position(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur, &end))) {
PyList_Append(ret, PyLong_FromLong(cur));
PyList_Append(ret, PyLong_FromLong(end));
PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format ));
} else {
for (i = 0; i < 2; i++) {
Py_INCREF(Py_None);
PyList_Append(ret, Py_None);
}
PyList_Append(ret, pformat);
}
return ret;
}

View file

@ -31,6 +31,13 @@ static void pygstminiobject_dealloc(PyGstMiniObject *self);
static int pygstminiobject_traverse(PyGstMiniObject *self, visitproc visit, void *arg);
static int pygstminiobject_clear(PyGstMiniObject *self);
static GHashTable *miniobjs;
void
pygst_miniobject_init()
{
miniobjs = g_hash_table_new (NULL, NULL);
}
/**
* pygstminiobject_lookup_class:
@ -111,6 +118,31 @@ pygstminiobject_register_class(PyObject *dict, const gchar *type_name,
PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
}
/**
* pygstminiobject_register_wrapper:
* @self: the wrapper instance
*
* In the constructor of PyGTK wrappers, this function should be
* called after setting the obj member. It will tie the wrapper
* instance to the Gstminiobject so that the same wrapper instance will
* always be used for this Gstminiobject instance. It will also sink any
* floating references on the Gstminiobject.
*/
void
pygstminiobject_register_wrapper(PyObject *self)
{
GstMiniObject *obj = ((PyGstMiniObject *)self)->obj;
if (!pygstminiobject_wrapper_key)
pygstminiobject_wrapper_key=g_quark_from_static_string(pygstminiobject_wrapper_id);
Py_INCREF(self);
g_hash_table_insert (miniobjs, (gpointer) obj, (gpointer) self);
/* gst_mini_object_set_qdata_full(obj, pygstminiobject_wrapper_key, self, */
/* pyg_destroy_notify); */
}
/**
* pygstminiobject_new:
* @obj: a GstMiniObject instance.
@ -135,25 +167,33 @@ pygstminiobject_new(GstMiniObject *obj)
return Py_None;
}
/* create wrapper */
PyTypeObject *tp = pygstminiobject_lookup_class(G_OBJECT_TYPE(obj));
/* need to bump type refcount if created with
pygstminiobject_new_with_interfaces(). fixes bug #141042 */
if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_INCREF(tp);
self = PyObject_GC_New(PyGstMiniObject, tp);
if (self == NULL)
return NULL;
self->obj = gst_mini_object_ref(obj);
self->inst_dict = NULL;
self->weakreflist = NULL;
/* save wrapper pointer so we can access it later */
Py_INCREF(self);
/* g_object_set_qdata_full(obj, pygstminiobject_wrapper_key, self, */
/* pyg_destroy_notify); */
PyObject_GC_Track((PyObject *)self);
/* we already have a wrapper for this object -- return it. */
self = (PyGstMiniObject *)g_hash_table_lookup (miniobjs, (gpointer) obj);
/* self = (PyGstMiniObject *)gst_mini_object_get_qdata(obj, pygstminiobject_wrapper_key); */
if (self != NULL) {
Py_INCREF(self);
} else {
/* create wrapper */
PyTypeObject *tp = pygstminiobject_lookup_class(G_OBJECT_TYPE(obj));
/* need to bump type refcount if created with
pygstminiobject_new_with_interfaces(). fixes bug #141042 */
if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_INCREF(tp);
self = PyObject_GC_New(PyGstMiniObject, tp);
if (self == NULL)
return NULL;
self->obj = gst_mini_object_make_writable(obj);
self->inst_dict = NULL;
self->weakreflist = NULL;
/* save wrapper pointer so we can access it later */
Py_INCREF(self);
g_hash_table_insert (miniobjs, (gpointer) obj, (gpointer) self);
/* gst_mini_object_set_qdata_full(obj, pygstminiobject_wrapper_key, self, */
/* pyg_destroy_notify); */
PyObject_GC_Track((PyObject *)self);
}
return (PyObject *)self;
}
@ -177,6 +217,7 @@ pygstminiobject_dealloc(PyGstMiniObject *self)
/* the following causes problems with subclassed types */
/* self->ob_type->tp_free((PyObject *)self); */
g_hash_table_remove (miniobjs, (gpointer) self);
PyObject_GC_Del(self);
}
@ -242,6 +283,7 @@ pygstminiobject_clear(PyGstMiniObject *self)
static void
pygstminiobject_free(PyObject *op)
{
g_hash_table_remove (miniobjs, (gpointer) op);
PyObject_GC_Del(op);
}

View file

@ -36,6 +36,11 @@ void
pygstminiobject_register_class(PyObject *dict, const gchar *type_name,
GType gtype, PyTypeObject *type,
PyObject *bases);
void
pygstminiobject_register_wrapper(PyObject *self);
void
pygst_miniobject_init();
#ifndef _INSIDE_PYGSTMINIOBJECT_
@ -43,25 +48,6 @@ struct _PyGObject_Functions *_PyGObject_API;
extern PyTypeObject PyGstMiniObject_Type;
#define init_pygstminiobject() { \
PyObject *gstminiobject = PyImport_ImportModule("gstminiobject"); \
if (gstminiobject != NULL) { \
PyObject *mdict = PyModule_GetDict(gstminiobject); \
PyObject *cobject = PyDict_GetItemString(mdict, "_PyGstMiniObject_API"); \
if (PyCObject_Check(cobject)) \
_PyGstMiniObject_API = (struct _PyGstMiniObject_Functions *)PyCObject_AsVoidPtr(cobject); \
else { \
PyErr_SetString(PyExc_RuntimeError, \
"could not find _PyGstMiniObject_API object"); \
return; \
} \
} else { \
PyErr_SetString(PyExc_ImportError, \
"could not import gst"); \
return; \
} \
}
#endif /* !_INSIDE_PYGSTMINIOBJECT_ */
G_END_DECLS