| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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 |
static PyObject * |
|---|
| 27 |
pymidgard_object_class_factory(PyGObject *self, PyObject *args) |
|---|
| 28 |
{ |
|---|
| 29 |
PyObject *pvalue = NULL; |
|---|
| 30 |
const gchar *classname; |
|---|
| 31 |
const gchar *guid; |
|---|
| 32 |
guint id; |
|---|
| 33 |
MgdObject *mobject = NULL; |
|---|
| 34 |
|
|---|
| 35 |
if(!PyArg_ParseTuple(args, "s|O", &classname, &pvalue)) |
|---|
| 36 |
return NULL; |
|---|
| 37 |
|
|---|
| 38 |
MidgardConnection *mgd = |
|---|
| 39 |
_py_midgard_connection_singleton_get(); |
|---|
| 40 |
|
|---|
| 41 |
if(pvalue == NULL) { |
|---|
| 42 |
|
|---|
| 43 |
mobject = midgard_object_new(mgd, classname, NULL); |
|---|
| 44 |
|
|---|
| 45 |
} else { |
|---|
| 46 |
|
|---|
| 47 |
GValue gval = gvalue_from_pyobject(pvalue); |
|---|
| 48 |
pyg_value_from_pyobject(&gval, pvalue); |
|---|
| 49 |
|
|---|
| 50 |
if(G_IS_VALUE(&gval)) |
|---|
| 51 |
mobject = midgard_object_new(mgd, classname, &gval); |
|---|
| 52 |
|
|---|
| 53 |
g_value_unset(&gval); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
if(mobject == NULL) |
|---|
| 57 |
PyErr_SetString(PyExc_SystemError, "Failed to initialize new object"); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
GValue gval = {0, }; |
|---|
| 61 |
g_value_init(&gval, G_TYPE_OBJECT); |
|---|
| 62 |
g_value_set_object(&gval, G_OBJECT(mobject)); |
|---|
| 63 |
PyObject *pval = pyg_value_as_pyobject((const GValue *)&gval, FALSE); |
|---|
| 64 |
|
|---|
| 65 |
return pval; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
static PyObject * |
|---|
| 69 |
pymidgard_object_class_get_primary_property(PyGObject *self, PyObject *args) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
const gchar *classname; |
|---|
| 73 |
|
|---|
| 74 |
if(!PyArg_ParseTuple(args, "s", &classname)) |
|---|
| 75 |
return NULL; |
|---|
| 76 |
|
|---|
| 77 |
GObjectClass *klass = g_type_class_peek(g_type_from_name(classname)); |
|---|
| 78 |
if(klass == NULL) |
|---|
| 79 |
return NULL; |
|---|
| 80 |
|
|---|
| 81 |
const gchar *pname = |
|---|
| 82 |
midgard_object_class_get_primary_property(MIDGARD_OBJECT_CLASS(klass)); |
|---|
| 83 |
|
|---|
| 84 |
if(pname == NULL) |
|---|
| 85 |
Py_RETURN_NONE; |
|---|
| 86 |
|
|---|
| 87 |
return Py_BuildValue("s", pname); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
static PyObject * |
|---|
| 91 |
pymidgard_object_class_get_property_parent(PyGObject *self, PyObject *args) |
|---|
| 92 |
{ |
|---|
| 93 |
|
|---|
| 94 |
const gchar *classname; |
|---|
| 95 |
|
|---|
| 96 |
if(!PyArg_ParseTuple(args, "s", &classname)) |
|---|
| 97 |
return NULL; |
|---|
| 98 |
|
|---|
| 99 |
GObjectClass *klass = g_type_class_peek(g_type_from_name(classname)); |
|---|
| 100 |
if(klass == NULL) |
|---|
| 101 |
return NULL; |
|---|
| 102 |
|
|---|
| 103 |
const gchar *pname = |
|---|
| 104 |
midgard_object_class_get_property_parent(MIDGARD_OBJECT_CLASS(klass)); |
|---|
| 105 |
|
|---|
| 106 |
if(pname == NULL) |
|---|
| 107 |
Py_RETURN_NONE; |
|---|
| 108 |
|
|---|
| 109 |
return Py_BuildValue("s", pname); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
static PyObject * |
|---|
| 113 |
pymidgard_object_class_get_property_up(PyGObject *self, PyObject *args) |
|---|
| 114 |
{ |
|---|
| 115 |
|
|---|
| 116 |
const gchar *classname; |
|---|
| 117 |
|
|---|
| 118 |
if(!PyArg_ParseTuple(args, "s", &classname)) |
|---|
| 119 |
return NULL; |
|---|
| 120 |
|
|---|
| 121 |
GObjectClass *klass = g_type_class_peek(g_type_from_name(classname)); |
|---|
| 122 |
if(klass == NULL) |
|---|
| 123 |
return NULL; |
|---|
| 124 |
|
|---|
| 125 |
const gchar *pname = |
|---|
| 126 |
midgard_object_class_get_property_up(MIDGARD_OBJECT_CLASS(klass)); |
|---|
| 127 |
|
|---|
| 128 |
if(pname == NULL) |
|---|
| 129 |
Py_RETURN_NONE; |
|---|
| 130 |
|
|---|
| 131 |
return Py_BuildValue("s", pname); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
static PyObject * |
|---|
| 135 |
pymidgard_object_class_list_children(PyGObject *self, PyObject *args) |
|---|
| 136 |
{ |
|---|
| 137 |
|
|---|
| 138 |
const gchar *classname; |
|---|
| 139 |
|
|---|
| 140 |
if(!PyArg_ParseTuple(args, "s", &classname)) |
|---|
| 141 |
return NULL; |
|---|
| 142 |
|
|---|
| 143 |
GObjectClass *klass = g_type_class_peek(g_type_from_name(classname)); |
|---|
| 144 |
if(klass == NULL) |
|---|
| 145 |
return NULL; |
|---|
| 146 |
|
|---|
| 147 |
MidgardObjectClass **klases = |
|---|
| 148 |
midgard_object_class_list_children(MIDGARD_OBJECT_CLASS(klass)); |
|---|
| 149 |
|
|---|
| 150 |
guint i = 0; |
|---|
| 151 |
if(klases == NULL) { |
|---|
| 152 |
|
|---|
| 153 |
PyObject *list = PyTuple_New(i); |
|---|
| 154 |
return list; |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
while(klases[i] != NULL) |
|---|
| 158 |
i++; |
|---|
| 159 |
|
|---|
| 160 |
PyObject *list = PyTuple_New(i); |
|---|
| 161 |
i = 0; |
|---|
| 162 |
while(klases[i] != NULL) { |
|---|
| 163 |
|
|---|
| 164 |
const gchar *cname = G_OBJECT_CLASS_NAME(klases[i]); |
|---|
| 165 |
PyObject *strname = PyString_FromString(cname); |
|---|
| 166 |
PyTuple_SetItem(list, i, strname); |
|---|
| 167 |
i++; |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
return list; |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
static PyObject * |
|---|
| 174 |
pymidgard_object_class_get_object_by_guid(PyGObject *self, PyObject *args) |
|---|
| 175 |
{ |
|---|
| 176 |
const gchar *guid; |
|---|
| 177 |
|
|---|
| 178 |
if(!PyArg_ParseTuple(args, "s", &guid)) |
|---|
| 179 |
return NULL; |
|---|
| 180 |
|
|---|
| 181 |
MidgardConnection *mgd = |
|---|
| 182 |
_py_midgard_connection_singleton_get(); |
|---|
| 183 |
|
|---|
| 184 |
MgdObject *mobject = midgard_object_class_get_object_by_guid(mgd, guid); |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
GValue gval = {0, }; |
|---|
| 188 |
g_value_init(&gval, G_TYPE_OBJECT); |
|---|
| 189 |
g_value_set_object(&gval, G_OBJECT(mobject)); |
|---|
| 190 |
PyObject *pvalue = pyg_value_as_pyobject((const GValue *)&gval, FALSE); |
|---|
| 191 |
|
|---|
| 192 |
return pvalue; |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
static PyObject * |
|---|
| 196 |
pymidgard_object_class_get_object_by_path(PyGObject *self, PyObject *args) |
|---|
| 197 |
{ |
|---|
| 198 |
const gchar *path; |
|---|
| 199 |
const gchar *classname; |
|---|
| 200 |
|
|---|
| 201 |
if(!PyArg_ParseTuple(args, "ss", &classname, &path)) |
|---|
| 202 |
return NULL; |
|---|
| 203 |
|
|---|
| 204 |
MidgardConnection *mgd = |
|---|
| 205 |
_py_midgard_connection_singleton_get(); |
|---|
| 206 |
|
|---|
| 207 |
MgdObject *mobject = |
|---|
| 208 |
midgard_object_class_get_object_by_path(mgd, classname, path); |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
GValue gval = {0, }; |
|---|
| 212 |
g_value_init(&gval, G_TYPE_OBJECT); |
|---|
| 213 |
g_value_set_object(&gval, G_OBJECT(mobject)); |
|---|
| 214 |
PyObject *pvalue = pyg_value_as_pyobject((const GValue *)&gval, FALSE); |
|---|
| 215 |
|
|---|
| 216 |
return pvalue; |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
static PyObject * |
|---|
| 220 |
pymidgard_object_class_is_multilang(PyGObject *self, PyObject *args) |
|---|
| 221 |
{ |
|---|
| 222 |
const gchar *classname; |
|---|
| 223 |
|
|---|
| 224 |
if(!PyArg_ParseTuple(args, "s", &classname)) |
|---|
| 225 |
return NULL; |
|---|
| 226 |
|
|---|
| 227 |
MidgardConnection *mgd = |
|---|
| 228 |
_py_midgard_connection_singleton_get(); |
|---|
| 229 |
|
|---|
| 230 |
MidgardObjectClass *klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME(classname); |
|---|
| 231 |
|
|---|
| 232 |
if(!klass) |
|---|
| 233 |
Py_RETURN_NONE; |
|---|
| 234 |
|
|---|
| 235 |
if(midgard_object_class_is_multilang(klass)) |
|---|
| 236 |
Py_RETURN_TRUE; |
|---|
| 237 |
|
|---|
| 238 |
Py_RETURN_FALSE; |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
static PyObject * |
|---|
| 242 |
pymidgard_object_class_undelete(PyGObject *self, PyObject *args) |
|---|
| 243 |
{ |
|---|
| 244 |
const gchar *guid; |
|---|
| 245 |
|
|---|
| 246 |
if(!PyArg_ParseTuple(args, "s", &guid)) |
|---|
| 247 |
return NULL; |
|---|
| 248 |
|
|---|
| 249 |
MidgardConnection *mgd = |
|---|
| 250 |
_py_midgard_connection_singleton_get(); |
|---|
| 251 |
|
|---|
| 252 |
if(midgard_object_class_undelete(mgd, guid)) |
|---|
| 253 |
Py_RETURN_TRUE; |
|---|
| 254 |
|
|---|
| 255 |
Py_RETURN_FALSE; |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
static PyMethodDef pymidgard_object_class_methods[] = { |
|---|
| 259 |
{ "factory", |
|---|
| 260 |
(PyCFunction)pymidgard_object_class_factory, METH_VARARGS | METH_STATIC}, |
|---|
| 261 |
{ "get_primary_property", |
|---|
| 262 |
(PyCFunction)pymidgard_object_class_get_primary_property, METH_VARARGS | METH_STATIC}, |
|---|
| 263 |
{ "get_property_parent", |
|---|
| 264 |
(PyCFunction)pymidgard_object_class_get_property_parent, METH_VARARGS | METH_STATIC}, |
|---|
| 265 |
{ "get_property_up", |
|---|
| 266 |
(PyCFunction)pymidgard_object_class_get_property_up, METH_VARARGS | METH_STATIC}, |
|---|
| 267 |
{ "list_children", |
|---|
| 268 |
(PyCFunction)pymidgard_object_class_list_children, METH_VARARGS | METH_STATIC}, |
|---|
| 269 |
{ "get_object_by_guid", |
|---|
| 270 |
(PyCFunction)pymidgard_object_class_get_object_by_guid, METH_VARARGS | METH_STATIC}, |
|---|
| 271 |
{ "is_multilang", |
|---|
| 272 |
(PyCFunction)pymidgard_object_class_is_multilang, METH_VARARGS | METH_STATIC}, |
|---|
| 273 |
{ "get_object_by_path", |
|---|
| 274 |
(PyCFunction)pymidgard_object_class_get_object_by_path, METH_VARARGS | METH_STATIC}, |
|---|
| 275 |
{ "undelete", |
|---|
| 276 |
(PyCFunction)pymidgard_object_class_undelete, METH_VARARGS | METH_STATIC}, |
|---|
| 277 |
|
|---|
| 278 |
{ NULL, NULL, 0 } |
|---|
| 279 |
}; |
|---|
| 280 |
|
|---|
| 281 |
PyTypeObject G_GNUC_INTERNAL Pymidgard_object_class_Type = { |
|---|
| 282 |
PyObject_HEAD_INIT(NULL) |
|---|
| 283 |
0, |
|---|
| 284 |
"object_class", |
|---|
| 285 |
sizeof(PyGObject), |
|---|
| 286 |
0, |
|---|
| 287 |
|
|---|
| 288 |
(destructor)0, |
|---|
| 289 |
(printfunc)0, |
|---|
| 290 |
(getattrfunc)0, |
|---|
| 291 |
(setattrfunc)0, |
|---|
| 292 |
(cmpfunc)0, |
|---|
| 293 |
(reprfunc)0, |
|---|
| 294 |
(PyNumberMethods*)0, |
|---|
| 295 |
(PySequenceMethods*)0, |
|---|
| 296 |
(PyMappingMethods*)0, |
|---|
| 297 |
(hashfunc)0, |
|---|
| 298 |
(ternaryfunc)0, |
|---|
| 299 |
(reprfunc)0, |
|---|
| 300 |
(getattrofunc)0, |
|---|
| 301 |
(setattrofunc)0, |
|---|
| 302 |
(PyBufferProcs*)0, |
|---|
| 303 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|---|
| 304 |
NULL, |
|---|
| 305 |
(traverseproc)0, |
|---|
| 306 |
(inquiry)0, |
|---|
| 307 |
(richcmpfunc)0, |
|---|
| 308 |
offsetof(PyGObject, weakreflist), |
|---|
| 309 |
(getiterfunc)0, |
|---|
| 310 |
(iternextfunc)0, |
|---|
| 311 |
pymidgard_object_class_methods, |
|---|
| 312 |
(struct PyMemberDef*)0, |
|---|
| 313 |
(struct PyGetSetDef*)0, |
|---|
| 314 |
NULL, |
|---|
| 315 |
NULL, |
|---|
| 316 |
(descrgetfunc)0, |
|---|
| 317 |
(descrsetfunc)0, |
|---|
| 318 |
offsetof(PyGObject, inst_dict), |
|---|
| 319 |
(initproc)0, |
|---|
| 320 |
(allocfunc)0, |
|---|
| 321 |
(newfunc)0, |
|---|
| 322 |
(freefunc)0, |
|---|
| 323 |
(inquiry)0 |
|---|
| 324 |
}; |
|---|
| 325 |
|
|---|
| 326 |
void py_midgard_object_class_register_class( |
|---|
| 327 |
PyObject *d, gpointer pygobject_type) |
|---|
| 328 |
{ |
|---|
| 329 |
pygobject_register_class(d, |
|---|
| 330 |
"object_class", |
|---|
| 331 |
MIDGARD_TYPE_OBJECT, |
|---|
| 332 |
&Pymidgard_object_class_Type, |
|---|
| 333 |
Py_BuildValue("(O)", pygobject_type)); |
|---|
| 334 |
} |
|---|