Initial import to Tizen
[profile/ivi/gstreamer-python.git] / gst / gstobject.override
1 /* -*- Mode: C -*- */
2 /* gst-python
3  * Copyright (C) 2005 Edward Hervey
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  * 
20  * Author: Edward Hervey <edward@fluendo.com>
21  */
22
23 %%
24 ignore
25   gst_object_default_deep_notify
26   gst_object_check_uniqueness
27   gst_object_replace
28
29 %%
30 override-attr GstObject.__gstrefcount__
31
32 /* keep this attribute around even after 2.8 for compatibility reasons */
33 static PyObject *
34 _wrap_gst_object__get___gstrefcount__ (PyGObject * self, void *closure)
35 {
36   return PyInt_FromLong (GST_OBJECT_REFCOUNT_VALUE (self->obj));
37 }
38
39 %%
40 override-slot GstObject.tp_repr
41 static PyObject *
42 _wrap_gst_object_tp_repr (PyObject * self)
43 {
44   gchar *repr;
45   PyObject *ret;
46   GstObject *object = GST_OBJECT (pygobject_get (self));
47
48   repr = g_strdup_printf ("<%s object (%s) at 0x%lx>",
49       self->ob_type->tp_name,
50       object ? (
51         GST_OBJECT_NAME (object) ? GST_OBJECT_NAME (object) : "unnamed"
52       ) : "(null)",
53       (long) self);
54   ret = PyString_FromString (repr);
55   g_free (repr);
56   return ret;
57 }
58
59 %%
60 override-slot GstObject.tp_str
61 static PyObject *
62 _wrap_gst_object_tp_str (PyObject * self)
63 {
64   gchar *repr, *path;
65   PyObject *ret;
66   GstObject *object = GST_OBJECT (pygobject_get (self));
67
68   pyg_begin_allow_threads;
69   path = gst_object_get_path_string (object);
70   pyg_end_allow_threads;
71
72   repr = g_strdup_printf ("%s (%s)", path, self->ob_type->tp_name);
73   ret = PyString_FromString (repr);
74   g_free (repr);
75   g_free (path);
76   return ret;
77 }
78 %%
79 override gst_object_set_property args
80
81 /*
82  * REMOVE THE FOLLOWING CODE, once pygobject has fixed the issue of not
83  * releasing the GIL when calling g_object_set_property.
84  * 
85  * See bug #395048 : set_property() doesn't release the GIL
86  **/
87
88 static gboolean
89 set_property_from_pspec(GObject *obj,
90                         char *attr_name,
91                         GParamSpec *pspec,
92                         PyObject *pvalue)
93 {
94     GValue value = { 0, };
95
96     if (pspec->flags & G_PARAM_CONSTRUCT_ONLY) {
97         PyErr_Format(PyExc_TypeError,
98                      "property '%s' can only be set in constructor",
99                      attr_name);
100         return FALSE;
101     }   
102
103     if (!(pspec->flags & G_PARAM_WRITABLE)) {
104         PyErr_Format(PyExc_TypeError,
105                      "property '%s' is not writable", attr_name);
106         return FALSE;
107     }   
108
109     g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
110 /* FIXME: bug in pygtk 2.8 series; see
111 http://svn.gnome.org/viewcvs/pygobject/trunk/gobject/pygobject.h?rev=566&r1=564&r2=566 */
112
113 #ifndef PYGOBJECT_2_12
114 #undef pyg_param_gvalue_from_pyobject
115 #define pyg_param_gvalue_from_pyobject (_PyGObject_API->gvalue_from_param_pyobject)
116 #endif
117
118     if (pyg_param_gvalue_from_pyobject(&value, pvalue, pspec) < 0) {
119         PyErr_SetString(PyExc_TypeError,
120                         "could not convert argument to correct param type");
121         return FALSE;
122     }
123
124     pyg_begin_allow_threads;
125     g_object_set_property(obj, attr_name, &value);
126     pyg_end_allow_threads;
127
128     g_value_unset(&value);
129     
130     return TRUE;
131 }
132
133 static PyObject *
134 _wrap_gst_object_set_property(PyGObject *self, PyObject *args)
135 {
136     gchar *param_name;
137     GParamSpec *pspec;
138     PyObject *pvalue;
139
140     if (!PyArg_ParseTuple(args, "sO:gst.Object.set_property", &param_name,
141                           &pvalue))
142       return NULL;
143     
144     if (!GST_IS_OBJECT (self->obj)) {
145       PyErr_Format (PyExc_TypeError,
146                     "object at %p of type %s is not initialized",
147                     self, self->ob_type->tp_name);
148       return NULL;
149     }
150     
151     pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(self->obj),
152                                          param_name);
153     if (!pspec) {
154         PyErr_Format(PyExc_TypeError,
155                      "object of type `%s' does not have property `%s'",
156                      g_type_name(G_OBJECT_TYPE(self->obj)), param_name);
157         return NULL;
158     }
159     
160     if (!set_property_from_pspec(self->obj, param_name, pspec, pvalue))
161         return NULL;
162     
163     Py_INCREF(Py_None);
164     return Py_None;
165 }