-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpy_midgard.h
134 lines (113 loc) · 6.04 KB
/
py_midgard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright (C) 2007 Piotr Pokora <piotrek.pokora@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PY_MIDGARD_H
#define PY_MIDGARD_H
#ifndef PY_MIDGARD_H_INT
#define PY_MIDGARD_H_INT
#include <Python.h>
#include <pygobject.h>
#include <midgard/midgard.h>
#endif
#ifdef G_LOG_DOMAIN
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "midgard-core"
#endif
extern guint get_global_log_handler(void);
extern void py_midgard_dbobject_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_object_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_config_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_connection_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_query_builder_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_blob_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_collector_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_reflector_property_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_replicator_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_user_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_dbus_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_transaction_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_storage_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_view_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_key_config_context_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_key_config_file_context_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_reflector_object_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_schema_object_tree_register_class(PyObject *d, gpointer pygobject_type);
extern void py_midgard_schema_object_factory_register_class(PyObject *d, gpointer pygobject_type);
/* PARAMETERS */
extern PyObject *pymidgard_object_get_parameter(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_set_parameter(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_delete_parameters(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_purge_parameters(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_list_parameters(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_find_parameters(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_has_parameters(PyGObject *self, PyObject *args);
/* ATTACHMENTS */
extern PyObject *pymidgard_object_create_attachment(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_delete_attachments(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_purge_attachments(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_list_attachments(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_find_attachments(PyGObject *self, PyObject *args);
extern PyObject *pymidgard_object_has_attachments(PyGObject *self, PyObject *args);
/* GLOBALS */
/* MidgardConnection is defined as global value.
* Singleton pattern should be kept for Apache environment */
extern MidgardConnection *MGDCG;
/* Types' pointers */
PyTypeObject py_midgard_dbobject_get_type_object(void);
PyTypeObject py_midgard_query_builder_get_type_object(void);
PyTypeObject py_midgard_collector_get_type_object(void);
extern void _py_midgard_connection_singleton_set(MidgardConnection *mgd);
extern MidgardConnection *_py_midgard_connection_singleton_get(void);
extern PyTypeObject *py_midgard_lookup_schema_type(const gchar *name);
/* GType routines */
extern GValue gvalue_from_pyobject(PyObject *obj);
extern gchar *_py_midgard_format_string(const gchar *msg , ...);
extern GParameter *_py_midgard_parameters_from_args(PyObject *args, guint *n_params);
void py_midgard_gvalue_from_pyobject(GValue *gvalue, const PyObject *pyvalue);
PyObject *py_midgard_pyobject_from_gvalue(const GValue *gvalue, gboolean copy_boxed);
/* Object routines */
PyObject *_py_midgard_get_object_attribute(PyObject *self, PyObject *attr);
int _py_midgard_set_object_attribute(PyObject *self, PyObject *attr, PyObject *value);
void _py_midgard_gobject_destructor (PyObject *self);
/* ROUTINES */
#define CHECK_MGD \
if(1 < 0) { \
PyTypeObject *tp = self->ob_type; \
PyObject *__class = PyObject_GetAttrString((PyObject *)self, "__class__"); \
PyObject *__name = PyObject_GetAttrString(__class, "__name__"); \
PyObject *__string = PyObject_Str(__name); \
Py_DECREF(__name); \
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s.%s(...)", tp->tp_name, PyString_AS_STRING(__string)); \
}
#define CLASS_METHOD_DEBUG(__classname, __name) \
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s.%s(...)", __classname, __name);
#define OBJECTS2LIST(__gobjects, __rlist) \
guint k = 0; \
while(__gobjects[k] != NULL) { \
PyObject *__pobject = \
Py_BuildValue("O", pygobject_new(G_OBJECT(__gobjects[k]))); \
((PyGObject *)__pobject)->obj = G_OBJECT(__gobjects[k]); \
PyTuple_SetItem(__rlist, k, __pobject); \
k++; \
}
#define FREE_PARAMETERS(_n_params, _params) \
guint _i; \
for(_i = 0; _i < _n_params; _i++) { \
g_value_unset(&_params[_i].value); \
} \
g_free(_params);
#endif /* PY_MIDGARD_H */