| 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 |
PyTypeObject G_GNUC_INTERNAL Pymidgard_storage_Type; |
|---|
| 27 |
|
|---|
| 28 |
#define STORAGE_DEBUG(__name) \ |
|---|
| 29 |
CHECK_MGD; \ |
|---|
| 30 |
CLASS_METHOD_DEBUG(Pymidgard_storage_Type.tp_name, __name); |
|---|
| 31 |
|
|---|
| 32 |
#define __STORAGE_FUNC \ |
|---|
| 33 |
gchar *classname; \ |
|---|
| 34 |
if(!PyArg_ParseTuple(args, "s", &classname)) \ |
|---|
| 35 |
return NULL; \ |
|---|
| 36 |
MidgardConnection *mgd = _py_midgard_connection_singleton_get(); \ |
|---|
| 37 |
if (!mgd) { \ |
|---|
| 38 |
g_warning("Underlying midgard connection not found"); \ |
|---|
| 39 |
return NULL; \ |
|---|
| 40 |
} \ |
|---|
| 41 |
MidgardDBObjectClass *dbklass = g_type_class_peek(g_type_from_name(classname)); \ |
|---|
| 42 |
if (!dbklass) { \ |
|---|
| 43 |
g_warning("%s is no tregistered as midgard_dbobject derived class", classname); \ |
|---|
| 44 |
return NULL; \ |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
static PyObject * |
|---|
| 48 |
pymidgard_storage_create_class_storage(PyGObject *self, PyObject *args) |
|---|
| 49 |
{ |
|---|
| 50 |
STORAGE_DEBUG("create_class_storage"); |
|---|
| 51 |
|
|---|
| 52 |
__STORAGE_FUNC |
|---|
| 53 |
|
|---|
| 54 |
if (midgard_storage_create_class_storage(mgd, dbklass)) |
|---|
| 55 |
Py_RETURN_TRUE; |
|---|
| 56 |
|
|---|
| 57 |
Py_RETURN_FALSE; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
static PyObject * |
|---|
| 61 |
pymidgard_storage_update_class_storage(PyGObject *self, PyObject *args) |
|---|
| 62 |
{ |
|---|
| 63 |
STORAGE_DEBUG("update_class_storage"); |
|---|
| 64 |
|
|---|
| 65 |
__STORAGE_FUNC |
|---|
| 66 |
|
|---|
| 67 |
if (midgard_storage_update_class_storage(mgd, dbklass)) |
|---|
| 68 |
Py_RETURN_TRUE; |
|---|
| 69 |
|
|---|
| 70 |
Py_RETURN_FALSE; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
static PyObject * |
|---|
| 74 |
pymidgard_storage_delete_class_storage(PyGObject *self, PyObject *args) |
|---|
| 75 |
{ |
|---|
| 76 |
STORAGE_DEBUG("delete_class_storage"); |
|---|
| 77 |
|
|---|
| 78 |
__STORAGE_FUNC |
|---|
| 79 |
|
|---|
| 80 |
if (midgard_storage_delete_class_storage(mgd, dbklass)) |
|---|
| 81 |
Py_RETURN_TRUE; |
|---|
| 82 |
|
|---|
| 83 |
Py_RETURN_FALSE; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
static PyObject * |
|---|
| 87 |
pymidgard_storage_class_storage_exists(PyGObject *self, PyObject *args) |
|---|
| 88 |
{ |
|---|
| 89 |
STORAGE_DEBUG("class_storage_exists"); |
|---|
| 90 |
|
|---|
| 91 |
__STORAGE_FUNC |
|---|
| 92 |
|
|---|
| 93 |
if (midgard_storage_class_storage_exists(mgd, dbklass)) |
|---|
| 94 |
Py_RETURN_TRUE; |
|---|
| 95 |
|
|---|
| 96 |
Py_RETURN_FALSE; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
static PyObject * |
|---|
| 100 |
pymidgard_storage_create_base_storage(PyGObject *self, PyObject *args) |
|---|
| 101 |
{ |
|---|
| 102 |
STORAGE_DEBUG("create_base_storage"); |
|---|
| 103 |
|
|---|
| 104 |
MidgardConnection *mgd = |
|---|
| 105 |
_py_midgard_connection_singleton_get(); |
|---|
| 106 |
|
|---|
| 107 |
if (midgard_storage_create_base_storage(mgd)) |
|---|
| 108 |
Py_RETURN_TRUE; |
|---|
| 109 |
|
|---|
| 110 |
Py_RETURN_FALSE; |
|---|
| 111 |
|
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
static int __py_midgard_parse_dbobject(PyObject *object) |
|---|
| 115 |
{ |
|---|
| 116 |
PyObject *pclass = NULL, *pcname = NULL; |
|---|
| 117 |
int ret = 0; |
|---|
| 118 |
|
|---|
| 119 |
pclass = PyObject_GetAttrString(object, "__class__"); |
|---|
| 120 |
if (!pclass) { |
|---|
| 121 |
|
|---|
| 122 |
PyErr_SetString(PyExc_TypeError, "Didn't find a class for given argument object."); |
|---|
| 123 |
return ret; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
pcname = PyObject_GetAttrString(pclass, "__name__"); |
|---|
| 127 |
if(!pcname) { |
|---|
| 128 |
|
|---|
| 129 |
PyErr_SetString(PyExc_TypeError, "Didn't find a class name for given argument object."); |
|---|
| 130 |
return ret; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
GType type = g_type_from_name(PyString_AS_STRING(pcname)); |
|---|
| 134 |
|
|---|
| 135 |
if(!type) { |
|---|
| 136 |
|
|---|
| 137 |
PyErr_SetString(PyExc_TypeError, "Expected argument object registered in GType system."); |
|---|
| 138 |
return ret; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
if(g_type_parent(type) != MIDGARD_TYPE_DBOBJECT) { |
|---|
| 142 |
|
|---|
| 143 |
if(g_type_parent(type) != MIDGARD_TYPE_OBJECT) { |
|---|
| 144 |
|
|---|
| 145 |
PyErr_SetString(PyExc_TypeError, "Expected argument of type midgard_dbobject (or derived class)."); |
|---|
| 146 |
ret = 0; |
|---|
| 147 |
|
|---|
| 148 |
} else { |
|---|
| 149 |
|
|---|
| 150 |
ret = 1; |
|---|
| 151 |
} |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
if(ret == 1) { |
|---|
| 155 |
|
|---|
| 156 |
if(G_OBJECT(((PyGObject *)object)->obj) == NULL) { |
|---|
| 157 |
|
|---|
| 158 |
PyErr_SetString(PyExc_TypeError, "Can not find underlying GObject object."); |
|---|
| 159 |
ret = 0; |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
return ret; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
static PyMethodDef pymidgard_storage_methods[] = { |
|---|
| 167 |
{ "create_base_storage", (PyCFunction)pymidgard_storage_create_base_storage, METH_NOARGS | METH_STATIC}, |
|---|
| 168 |
{ "create_class_storage", (PyCFunction)pymidgard_storage_create_class_storage, METH_VARARGS | METH_STATIC}, |
|---|
| 169 |
{ "update_class_storage", (PyCFunction)pymidgard_storage_update_class_storage, METH_VARARGS | METH_STATIC}, |
|---|
| 170 |
{ "delete_class_storage", (PyCFunction)pymidgard_storage_delete_class_storage, METH_VARARGS | METH_STATIC}, |
|---|
| 171 |
{ "class_storage_exists", (PyCFunction)pymidgard_storage_class_storage_exists, METH_VARARGS | METH_STATIC}, |
|---|
| 172 |
{ NULL, NULL, 0 } |
|---|
| 173 |
}; |
|---|
| 174 |
|
|---|
| 175 |
PyTypeObject G_GNUC_INTERNAL Pymidgard_storage_Type = { |
|---|
| 176 |
PyObject_HEAD_INIT(NULL) |
|---|
| 177 |
0, |
|---|
| 178 |
"storage", |
|---|
| 179 |
sizeof(PyGObject), |
|---|
| 180 |
0, |
|---|
| 181 |
|
|---|
| 182 |
(destructor)_py_midgard_gobject_destructor, |
|---|
| 183 |
(printfunc)0, |
|---|
| 184 |
(getattrfunc)0, |
|---|
| 185 |
(setattrfunc)0, |
|---|
| 186 |
(cmpfunc)0, |
|---|
| 187 |
(reprfunc)0, |
|---|
| 188 |
(PyNumberMethods*)0, |
|---|
| 189 |
(PySequenceMethods*)0, |
|---|
| 190 |
(PyMappingMethods*)0, |
|---|
| 191 |
(hashfunc)0, |
|---|
| 192 |
(ternaryfunc)0, |
|---|
| 193 |
(reprfunc)0, |
|---|
| 194 |
(getattrofunc)0, |
|---|
| 195 |
(setattrofunc)0, |
|---|
| 196 |
(PyBufferProcs*)0, |
|---|
| 197 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|---|
| 198 |
NULL, |
|---|
| 199 |
(traverseproc)0, |
|---|
| 200 |
(inquiry)0, |
|---|
| 201 |
(richcmpfunc)0, |
|---|
| 202 |
offsetof(PyGObject, weakreflist), |
|---|
| 203 |
(getiterfunc)0, |
|---|
| 204 |
(iternextfunc)0, |
|---|
| 205 |
pymidgard_storage_methods, |
|---|
| 206 |
(struct PyMemberDef*)0, |
|---|
| 207 |
(struct PyGetSetDef*)0, |
|---|
| 208 |
NULL, |
|---|
| 209 |
NULL, |
|---|
| 210 |
(descrgetfunc)0, |
|---|
| 211 |
(descrsetfunc)0, |
|---|
| 212 |
offsetof(PyGObject, inst_dict), |
|---|
| 213 |
(initproc)0, |
|---|
| 214 |
(allocfunc)0, |
|---|
| 215 |
(newfunc)0, |
|---|
| 216 |
(freefunc)0, |
|---|
| 217 |
(inquiry)0 |
|---|
| 218 |
}; |
|---|
| 219 |
|
|---|
| 220 |
void py_midgard_storage_register_class( |
|---|
| 221 |
PyObject *d, gpointer pygobject_type) |
|---|
| 222 |
{ |
|---|
| 223 |
pygobject_register_class(d, |
|---|
| 224 |
"storage", |
|---|
| 225 |
MIDGARD_TYPE_STORAGE, |
|---|
| 226 |
&Pymidgard_storage_Type, |
|---|
| 227 |
Py_BuildValue("(O)", pygobject_type)); |
|---|
| 228 |
} |
|---|