root/trunk/midgard/apis/python/py_midgard.h

Revision 18861, 4.8 kB (checked in by piotras, 2 weeks ago)

Added dbobject type get declaration

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 #ifndef PY_MIDGARD_H
20 #define PY_MIDGARD_H
21
22 #ifndef PY_MIDGARD_H_INT
23 #define PY_MIDGARD_H_INT
24
25 #include <Python.h>
26 #include <pygobject.h>
27 #include <midgard/midgard.h>
28
29 #endif
30
31 #ifdef G_LOG_DOMAIN
32 #undef G_LOG_DOMAIN
33 #define G_LOG_DOMAIN "midgard-core"
34 #endif
35
36 extern void py_midgard_dbobject_register_class(PyObject *d, gpointer pygobject_type);
37 extern void py_midgard_object_register_class(PyObject *d, gpointer pygobject_type);
38 extern void py_midgard_config_register_class(PyObject *d, gpointer pygobject_type);
39 extern void py_midgard_connection_register_class(PyObject *d, gpointer pygobject_type);
40 extern void py_midgard_query_builder_register_class(PyObject *d, gpointer pygobject_type);
41 extern void py_midgard_blob_register_class(PyObject *d, gpointer pygobject_type);
42 extern void py_midgard_collector_register_class(PyObject *d, gpointer pygobject_type);
43 extern void py_midgard_reflection_property_register_class(PyObject *d, gpointer pygobject_type);
44 extern void py_midgard_object_class_register_class(PyObject *d, gpointer pygobject_type);
45 extern void py_midgard_replicator_register_class(PyObject *d, gpointer pygobject_type);
46 extern void py_midgard_user_register_class(PyObject *d, gpointer pygobject_type);
47 extern void py_midgard_dbus_register_class(PyObject *d, gpointer pygobject_type);
48
49 /* PARAMETERS */
50 extern PyObject *pymidgard_object_get_parameter(PyGObject *self, PyObject *args);
51 extern PyObject *pymidgard_object_set_parameter(PyGObject *self, PyObject *args);
52 extern PyObject *pymidgard_object_delete_parameters(PyGObject *self, PyObject *args);
53 extern PyObject *pymidgard_object_purge_parameters(PyGObject *self, PyObject *args);
54 extern PyObject *pymidgard_object_list_parameters(PyGObject *self, PyObject *args);
55 extern PyObject *pymidgard_object_find_parameters(PyGObject *self, PyObject *args);
56
57 /* ATTACHMENTS */
58 extern PyObject *pymidgard_object_create_attachment(PyGObject *self, PyObject *args);
59 extern PyObject *pymidgard_object_delete_attachments(PyGObject *self, PyObject *args);
60 extern PyObject *pymidgard_object_purge_attachments(PyGObject *self, PyObject *args);
61 extern PyObject *pymidgard_object_list_attachments(PyGObject *self, PyObject *args);
62 extern PyObject *pymidgard_object_find_attachments(PyGObject *self, PyObject *args);
63
64 /* GLOBALS */
65
66 /* MidgardConnection is defined as global value.
67  * Singleton pattern should be kept for Apache environment */
68 extern MidgardConnection *MGDCG;
69
70 /* Types' pointers */
71 PyTypeObject py_midgard_dbobject_get_type_object(void);
72 PyTypeObject py_midgard_query_builder_get_type_object(void);
73 PyTypeObject py_midgard_collector_get_type_object(void);
74
75 extern void _py_midgard_connection_singleton_set(MidgardConnection *mgd);
76 extern MidgardConnection *_py_midgard_connection_singleton_get(void);
77 extern PyTypeObject *py_midgard_lookup_schema_type(const gchar *name);
78
79 /* GType routines */
80 extern GValue gvalue_from_pyobject(PyObject *obj);
81 extern gchar *_py_midgard_format_string(const gchar *msg , ...);
82 extern GParameter *_py_midgard_parameters_from_args(PyObject *args, guint *n_params);
83
84 /* Object routines */
85 PyObject *_py_midgard_get_object_attribute(PyObject *self, PyObject *attr);
86 int _py_midgard_set_object_attribute(PyObject *self, PyObject *attr, PyObject *value);
87
88 /* ROUTINES */
89 #define CHECK_MGD \
90         if(1 < 0) { \
91                 PyTypeObject *tp = self->ob_type; \
92                 PyObject *__class = PyObject_GetAttrString((PyObject *)self, "__class__"); \
93                 PyObject *__name = PyObject_GetAttrString(__class, "__name__"); \
94                 PyObject *__string = PyObject_Str(__name); \
95                 Py_DECREF(__name); \
96                 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s.%s(...)", tp->tp_name, PyString_AS_STRING(__string)); \
97         }
98
99 #define CLASS_METHOD_DEBUG(__classname, __name) \
100         g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s.%s(...)", __classname, __name);
101        
102 #define OBJECTS2LIST(__gobjects, __rlist)               \
103         guint k = 0;                                    \
104         while(__gobjects[k] != NULL) {                  \
105                 PyObject *__pobject =                   \
106                         Py_BuildValue("O", pygobject_new(G_OBJECT(__gobjects[k]))); \
107                 ((PyGObject *)__pobject)->obj = G_OBJECT(__gobjects[k]); \
108                 PyTuple_SetItem(__rlist, k, __pobject); \
109                 k++;                                    \
110         }
111
112 #endif  /* PY_MIDGARD_H */
Note: See TracBrowser for help on using the browser.