root/trunk/midgard/apis/python/py_midgard_view.c

Revision 22895, 5.1 kB (checked in by indeyets, 8 months ago)

fix compilation (duplicate symbol was detected). removed the one, which is unused

Line 
1 /*
2  * Copyright (C) 2007 Piotr Pokora <piotrek.pokora@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not-> write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #define NO_IMPORT_PYGOBJECT
24 #include "py_midgard.h"
25
26 PyTypeObject G_GNUC_INTERNAL Pymidgard_view_Type;
27
28 PyTypeObject G_GNUC_INTERNAL Pymidgard_view_Type = {
29     PyObject_HEAD_INIT(NULL)
30     0,                                 /* ob_size */
31     "view",                   /* tp_name */
32     sizeof(PyGObject),          /* tp_basicsize */
33     0,                                 /* tp_itemsize */
34     /* methods */
35     (destructor)0,        /* tp_dealloc */
36     (printfunc)0,                      /* tp_print */
37     (getattrfunc)_py_midgard_get_object_attribute,       /* tp_getattr */
38     (setattrfunc)0,       /* tp_setattr */
39     (cmpfunc)0,           /* tp_compare */
40     (reprfunc)0,             /* tp_repr */
41     (PyNumberMethods*)0,     /* tp_as_number */
42     (PySequenceMethods*)0, /* tp_as_sequence */
43     (PyMappingMethods*)0,   /* tp_as_mapping */
44     (hashfunc)0,             /* tp_hash */
45     (ternaryfunc)0,          /* tp_call */
46     (reprfunc)0,              /* tp_str */
47     (getattrofunc)0,     /* tp_getattro */
48     (setattrofunc)0,     /* tp_setattro */
49     (PyBufferProcs*)0,  /* tp_as_buffer */
50     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                      /* tp_flags */
51     NULL,                        /* Documentation string */
52     (traverseproc)0,     /* tp_traverse */
53     (inquiry)0,             /* tp_clear */
54     (richcmpfunc)0,   /* tp_richcompare */
55     offsetof(PyGObject, weakreflist),             /* tp_weaklistoffset */
56     (getiterfunc)0,          /* tp_iter */
57     (iternextfunc)0,     /* tp_iternext */
58     (struct PyMethodDef*)NULL, /* tp_methods */
59     (struct PyMemberDef*)0,              /* tp_members */
60     (struct PyGetSetDef*)0,  /* tp_getset */
61     NULL,                              /* tp_base */
62     NULL,                              /* tp_dict */
63     (descrgetfunc)0,    /* tp_descr_get */
64     (descrsetfunc)0,    /* tp_descr_set */
65     offsetof(PyGObject, inst_dict),                 /* tp_dictoffset */
66     (initproc)0,             /* tp_init */
67     (allocfunc)0,           /* tp_alloc */
68     (newfunc)0,               /* tp_new */
69     (freefunc)0,             /* tp_free */
70     (inquiry)0              /* tp_is_gc */
71 };
72
73 void py_midgard_base_view_register_class(
74                 PyObject *d, gpointer pygobject_type)
75 {
76         pygobject_register_class(d,
77                         "view",
78                         MIDGARD_TYPE_VIEW,
79                         &Pymidgard_view_Type,
80                         Py_BuildValue("(O)", pygobject_type));
81 }
82
83 PyTypeObject *__new_view_struct(const gchar *typename)
84 {
85         /* initialize object type */
86         PyTypeObject *ot = g_new0(PyTypeObject, 1);
87         ot->ob_refcnt = 1;
88         ot->ob_type = NULL;
89         ot->tp_name = g_strdup(typename);
90         ot->ob_size = 0;
91         ot->tp_basicsize = sizeof(PyGObject);
92         ot->tp_itemsize = 0;
93         ot->tp_dealloc = 0;
94         ot->tp_print = 0;
95         ot->tp_getattr = 0;
96         ot->tp_setattr = 0;
97         ot->tp_compare = 0;
98         ot->tp_repr = 0;
99         ot->tp_as_number = 0;
100         ot->tp_as_sequence = 0;
101         ot->tp_as_mapping = 0;
102         ot->tp_hash = 0;
103         ot->tp_call = 0;
104         ot->tp_str = 0;
105         //ot->tp_getattro = 0;
106         ot->tp_getattro = _py_midgard_get_object_attribute;
107         ot->tp_setattro = _py_midgard_set_object_attribute;
108         ot->tp_as_buffer = 0;
109         ot->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
110         ot->tp_doc = "User defined view class";
111         ot->tp_traverse = 0;
112         ot->tp_clear = 0;
113         ot->tp_richcompare = 0;
114         ot->tp_weaklistoffset = offsetof(PyGObject, weakreflist);
115         ot->tp_iter = 0;
116         ot->tp_iternext = 0;   
117         ot->tp_methods = 0;
118         //ot->tp_methods = NULL;
119         ot->tp_members = 0;
120         ot->tp_getset = 0;
121         ot->tp_base = NULL;
122         ot->tp_dict = NULL;
123         ot->tp_descr_get = 0;
124         ot->tp_descr_set = 0;
125         ot->tp_dictoffset = offsetof(PyGObject, inst_dict);
126         ot->tp_init = 0;               
127         ot->tp_alloc = 0;
128         ot->tp_new = 0;
129         ot->tp_free = 0;
130         ot->tp_is_gc = 0;
131
132         ot->tp_bases = 0;
133         ot->tp_mro = 0; /* method resolution order */
134         ot->tp_cache = 0;
135         ot->tp_subclasses = 0;
136         ot->tp_weaklist = 0;
137         ot->tp_del = 0;
138        
139         return ot;
140 }
141
142 void py_midgard_view_register_class(
143                 PyObject *d, gpointer pygobject_type)
144 {
145         py_midgard_base_view_register_class(d, pygobject_type);
146
147         guint n_types, i;
148         const gchar *typename;
149         GType *all_types = g_type_children(MIDGARD_TYPE_VIEW, &n_types);
150
151         for (i = 0; i < n_types; i++) {
152
153                 typename = g_type_name(all_types[i]);
154
155                 PyTypeObject *ot = __new_view_struct(typename);
156                 pygobject_register_class(d,
157                                 typename, all_types[i], ot, 
158                                 /* FIXME, What is a static bases in this case? */
159                                 Py_BuildValue("(O)", pygobject_type));
160         }
161
162         g_free(all_types);
163 }
Note: See TracBrowser for help on using the browser.