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

Revision 23617, 5.9 kB (checked in by indeyets, 5 months ago)

fix build-warnings

  • 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 guint get_global_log_handler(void);
37 extern void py_midgard_dbobject_register_class(PyObject *d, gpointer pygobject_type);
38 extern void py_midgard_object_register_class(PyObject *d, gpointer pygobject_type);
39 extern void py_midgard_config_register_class(PyObject *d, gpointer pygobject_type);
40 extern void py_midgard_connection_register_class(PyObject *d, gpointer pygobject_type);
41 extern void py_midgard_query_builder_register_class(PyObject *d, gpointer pygobject_type);
42 extern void py_midgard_blob_register_class(PyObject *d, gpointer pygobject_type);
43 extern void py_midgard_collector_register_class(PyObject *d, gpointer pygobject_type);
44 extern void py_midgard_reflection_property_register_class(PyObject *d, gpointer pygobject_type);
45 extern void py_midgard_object_class_register_class(PyObject *d, gpointer pygobject_type);
46 extern void py_midgard_replicator_register_class(PyObject *d, gpointer pygobject_type);
47 extern void py_midgard_user_register_class(PyObject *d, gpointer pygobject_type);
48 extern void py_midgard_dbus_register_class(PyObject *d, gpointer pygobject_type);
49 extern void py_midgard_transaction_register_class(PyObject *d, gpointer pygobject_type);
50 extern void py_midgard_storage_register_class(PyObject *d, gpointer pygobject_type);
51 extern void py_midgard_view_register_class(PyObject *d, gpointer pygobject_type);
52 extern void py_midgard_key_config_context_register_class(PyObject *d, gpointer pygobject_type);
53 extern void py_midgard_key_config_file_context_register_class(PyObject *d, gpointer pygobject_type);
54
55 /* PARAMETERS */
56 extern PyObject *pymidgard_object_get_parameter(PyGObject *self, PyObject *args);
57 extern PyObject *pymidgard_object_set_parameter(PyGObject *self, PyObject *args);
58 extern PyObject *pymidgard_object_delete_parameters(PyGObject *self, PyObject *args);
59 extern PyObject *pymidgard_object_purge_parameters(PyGObject *self, PyObject *args);
60 extern PyObject *pymidgard_object_list_parameters(PyGObject *self, PyObject *args);
61 extern PyObject *pymidgard_object_find_parameters(PyGObject *self, PyObject *args);
62 extern PyObject *pymidgard_object_has_parameters(PyGObject *self, PyObject *args);
63
64 /* ATTACHMENTS */
65 extern PyObject *pymidgard_object_create_attachment(PyGObject *self, PyObject *args);
66 extern PyObject *pymidgard_object_delete_attachments(PyGObject *self, PyObject *args);
67 extern PyObject *pymidgard_object_purge_attachments(PyGObject *self, PyObject *args);
68 extern PyObject *pymidgard_object_list_attachments(PyGObject *self, PyObject *args);
69 extern PyObject *pymidgard_object_find_attachments(PyGObject *self, PyObject *args);
70 extern PyObject *pymidgard_object_has_attachments(PyGObject *self, PyObject *args);
71
72 /* GLOBALS */
73
74 /* MidgardConnection is defined as global value.
75  * Singleton pattern should be kept for Apache environment */
76 extern MidgardConnection *MGDCG;
77
78 /* Types' pointers */
79 PyTypeObject py_midgard_dbobject_get_type_object(void);
80 PyTypeObject py_midgard_query_builder_get_type_object(void);
81 PyTypeObject py_midgard_collector_get_type_object(void);
82
83 extern void _py_midgard_connection_singleton_set(MidgardConnection *mgd);
84 extern MidgardConnection *_py_midgard_connection_singleton_get(void);
85 extern PyTypeObject *py_midgard_lookup_schema_type(const gchar *name);
86
87 /* GType routines */
88 extern GValue gvalue_from_pyobject(PyObject *obj);
89 extern gchar *_py_midgard_format_string(const gchar *msg , ...);
90 extern GParameter *_py_midgard_parameters_from_args(PyObject *args, guint *n_params);
91
92 void py_midgard_gvalue_from_pyobject(GValue *gvalue, const PyObject *pyvalue);
93 PyObject *py_midgard_pyobject_from_gvalue(const GValue *gvalue, gboolean copy_boxed);
94
95 /* Object routines */
96 PyObject *_py_midgard_get_object_attribute(PyObject *self, PyObject *attr);
97 int _py_midgard_set_object_attribute(PyObject *self, PyObject *attr, PyObject *value);
98 void _py_midgard_gobject_destructor (PyObject *self);
99
100 /* ROUTINES */
101 #define CHECK_MGD \
102         if(1 < 0) { \
103                 PyTypeObject *tp = self->ob_type; \
104                 PyObject *__class = PyObject_GetAttrString((PyObject *)self, "__class__"); \
105                 PyObject *__name = PyObject_GetAttrString(__class, "__name__"); \
106                 PyObject *__string = PyObject_Str(__name); \
107                 Py_DECREF(__name); \
108                 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s.%s(...)", tp->tp_name, PyString_AS_STRING(__string)); \
109         }
110
111 #define CLASS_METHOD_DEBUG(__classname, __name) \
112         g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s.%s(...)", __classname, __name);
113        
114 #define OBJECTS2LIST(__gobjects, __rlist)               \
115         guint k = 0;                                    \
116         while(__gobjects[k] != NULL) {                  \
117                 PyObject *__pobject =                   \
118                         Py_BuildValue("O", pygobject_new(G_OBJECT(__gobjects[k]))); \
119                 ((PyGObject *)__pobject)->obj = G_OBJECT(__gobjects[k]); \
120                 PyTuple_SetItem(__rlist, k, __pobject); \
121                 k++;                                    \
122         }
123
124 #define FREE_PARAMETERS(_n_params, _params) \
125         guint _i; \
126         for(_i = 0; _i < _n_params; _i++) { \
127                 g_value_unset(&_params[_i].value); \
128         } \
129         g_free(_params);
130
131 #endif  /* PY_MIDGARD_H */
Note: See TracBrowser for help on using the browser.