Initial import to Tizen
[profile/ivi/gstreamer-python.git] / gst / gsttaglist.override
1 /* -*- Mode: C; ; c-file-style: "python" -*- */
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-glob
25   gst_tag_list_get_*
26 %%
27 ignore
28   gst_tag_list_add
29   gst_tag_list_add_values
30   gst_tag_list_add_valist_values
31   gst_tag_list_copy_value
32   gst_tag_list_get
33   gst_tag_list_remove_tag
34   gst_tag_list_foreach
35   gst_is_tag_list
36 %%
37 define GstTagList.keys noargs
38 static void
39 tag_foreach_func_list (const GstTagList *list,
40                        const gchar      *tag,
41                        PyObject         *py_list)
42 {
43         int count;
44     
45         count = gst_tag_list_get_tag_size(GST_TAG_LIST(list), tag);
46         if (count == 0)
47                 PyErr_SetString(PyExc_KeyError, tag);
48         else if (count > 0)
49                 PyList_Append(py_list, PyString_FromString(tag));
50 }
51
52 static PyObject*
53 _wrap_gst_tag_list_keys(PyGObject *self)
54 {
55         PyObject *dict;
56
57         dict = PyList_New(0);
58     
59         gst_tag_list_foreach(GST_TAG_LIST(self->obj),
60                              (GstTagForeachFunc)tag_foreach_func_list,
61                              (gpointer)dict);
62         return dict;
63 }
64 %%
65 override-slot GstTagList.tp_as_mapping
66 static Py_ssize_t
67 _wrap_gst_tag_list_length(PyObject *self)
68 {
69         PyGObject *gself = (PyGObject *)self;
70         return gst_structure_n_fields((GstStructure*)gself->obj);
71 }
72
73 static PyObject *
74 _wrap_gst_tag_list_subscript(PyGObject *self, PyObject *py_key)
75 {
76         PyObject *v = NULL;
77         const char *field = PyString_AsString(py_key);
78         
79         if (gst_structure_has_field((GstStructure*)self->obj, field)) {
80                 const GValue *gvalue;
81                 gvalue = gst_structure_get_value((GstStructure*)self->obj, field);
82                 g_assert(gvalue != NULL);
83                 v = pygst_value_as_pyobject(gvalue, TRUE);
84         } else {
85                 PyErr_SetString(PyExc_KeyError, field);
86         }
87                 
88         return v;
89 }
90
91 static int
92 _wrap_gst_tag_list_ass_subscript(PyGObject *self,
93                                   PyObject *py_key,
94                                   PyObject *py_value)
95 {
96         const char *key;
97         GstStructure* structure;
98         GType tagtype;
99
100         structure = (GstStructure*)self->obj;
101         key = PyString_AsString(py_key);
102         if (py_value != NULL) {
103             GValue v = { 0, };
104
105             if (!pygst_value_init_for_pyobject (&v, py_value))
106                 return -1;
107             if (pygst_value_from_pyobject(&v, py_value))
108                 return -1;
109             
110             /* some tags are supposed to be uint, but there is no unsigned
111              * int python type, so convert here if needed */
112             if (gst_tag_exists (key)) {
113                 tagtype = gst_tag_get_type (key);
114
115                 if (tagtype && tagtype != G_VALUE_TYPE (&v)) {
116                     GValue w = { 0, };
117
118                     g_value_init (&w, tagtype);
119                     g_value_transform (&v, &w);
120                     g_value_unset (&v);
121                     g_value_init (&v, tagtype);
122                     g_value_copy (&w, &v);
123                 }
124             }
125             gst_structure_set_value(structure, key, &v);
126             g_value_unset(&v);
127         } else {
128             gst_structure_remove_field(structure, key);
129         }
130         
131         return 0;
132 }
133
134 static PyMappingMethods _wrap_gst_tag_list_tp_as_mapping = {
135         _wrap_gst_tag_list_length,         /* mp_length */
136         (binaryfunc)_wrap_gst_tag_list_subscript,   /* mp_subscript */
137         (objobjargproc)_wrap_gst_tag_list_ass_subscript /* mp_ass_subscript */
138 };
139 %%
140 override-slot GstTagList.tp_as_sequence
141 static int
142 _wrap_gst_tag_list_contains(PyGObject *self, PyObject *py_key)
143 {
144         return gst_structure_has_field((GstStructure*)self->obj,
145                                        PyString_AsString(py_key));
146 }
147
148 static PySequenceMethods _wrap_gst_tag_list_tp_as_sequence = {
149         (lenfunc)NULL,
150         (binaryfunc)NULL,
151         (ssizeargfunc)NULL,
152         (ssizeargfunc)NULL,
153         (ssizessizeargfunc)NULL,
154         (ssizeobjargproc)NULL,
155         (ssizessizeobjargproc)NULL,
156         (objobjproc)_wrap_gst_tag_list_contains,
157         (binaryfunc)NULL,
158         (ssizeargfunc)NULL,
159 };
160