TIVI-320: Add dbus-python to repos to support connman-test
[profile/ivi/dbus-python.git] / _dbus_bindings / dbus_bindings-internal.h
1 /* _dbus_bindings internal API. For use within _dbus_bindings only.
2  *
3  * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  */
25
26 #ifndef DBUS_BINDINGS_INTERNAL_H
27 #define DBUS_BINDINGS_INTERNAL_H
28
29 #define PY_SSIZE_T_CLEAN 1
30
31 #include <Python.h>
32
33 /* Python < 2.5 compat */
34 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
35 typedef int Py_ssize_t;
36 #define PY_SSIZE_T_MAX INT_MAX
37 #define PY_SSIZE_T_MIN INT_MIN
38 #endif
39
40 #define INSIDE_DBUS_PYTHON_BINDINGS
41 #include "dbus-python.h"
42
43 /* no need for extern "C", this is only for internal use */
44
45 /* on/off switch for debugging support (see below) */
46 #undef USING_DBG
47 #if 0 && !defined(DBG_IS_TOO_VERBOSE)
48 #   define USING_DBG 1
49 #endif
50
51 #define DEFINE_CHECK(type) \
52 static inline int type##_Check (PyObject *o) \
53 { \
54     return (PyObject_TypeCheck (o, &type##_Type)); \
55 } \
56 static inline int type##_CheckExact (PyObject *o) \
57 { \
58     return ((o)->ob_type == &type##_Type); \
59 }
60
61 PyMODINIT_FUNC init_dbus_bindings(void);
62
63 /* conn.c */
64 extern PyTypeObject DBusPyConnection_Type;
65 DEFINE_CHECK(DBusPyConnection)
66 extern dbus_bool_t dbus_py_init_conn_types(void);
67 extern dbus_bool_t dbus_py_insert_conn_types(PyObject *this_module);
68
69 /* libdbusconn.c */
70 extern PyTypeObject DBusPyLibDBusConnection_Type;
71 DEFINE_CHECK(DBusPyLibDBusConnection)
72 PyObject *DBusPyLibDBusConnection_New(DBusConnection *conn);
73 extern dbus_bool_t dbus_py_init_libdbus_conn_types(void);
74 extern dbus_bool_t dbus_py_insert_libdbus_conn_types(PyObject *this_module);
75
76 /* bus.c */
77 extern dbus_bool_t dbus_py_init_bus_types(void);
78 extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module);
79
80 /* exceptions.c */
81 extern PyObject *DBusPyException_SetString(const char *msg);
82 extern PyObject *DBusPyException_ConsumeError(DBusError *error);
83 extern dbus_bool_t dbus_py_init_exception_types(void);
84 extern dbus_bool_t dbus_py_insert_exception_types(PyObject *this_module);
85
86 /* types */
87 extern PyTypeObject DBusPyBoolean_Type;
88 DEFINE_CHECK(DBusPyBoolean)
89 extern PyTypeObject DBusPyObjectPath_Type, DBusPySignature_Type;
90 DEFINE_CHECK(DBusPyObjectPath)
91 DEFINE_CHECK(DBusPySignature)
92 extern PyTypeObject DBusPyArray_Type, DBusPyDict_Type, DBusPyStruct_Type;
93 DEFINE_CHECK(DBusPyArray)
94 DEFINE_CHECK(DBusPyDict)
95 DEFINE_CHECK(DBusPyStruct)
96 extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type;
97 DEFINE_CHECK(DBusPyByteArray)
98 DEFINE_CHECK(DBusPyByte)
99 extern PyTypeObject DBusPyUTF8String_Type, DBusPyString_Type;
100 DEFINE_CHECK(DBusPyUTF8String)
101 DEFINE_CHECK(DBusPyString)
102 extern PyTypeObject DBusPyDouble_Type;
103 DEFINE_CHECK(DBusPyDouble)
104 extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
105 DEFINE_CHECK(DBusPyInt16)
106 DEFINE_CHECK(DBusPyUInt16)
107 extern PyTypeObject DBusPyInt32_Type, DBusPyUInt32_Type;
108 DEFINE_CHECK(DBusPyInt32)
109 DEFINE_CHECK(DBusPyUInt32)
110 extern PyTypeObject DBusPyInt64_Type, DBusPyUInt64_Type;
111 DEFINE_CHECK(DBusPyInt64)
112 DEFINE_CHECK(DBusPyUInt64)
113 extern dbus_bool_t dbus_py_init_abstract(void);
114 extern dbus_bool_t dbus_py_init_signature(void);
115 extern dbus_bool_t dbus_py_init_int_types(void);
116 extern dbus_bool_t dbus_py_init_string_types(void);
117 extern dbus_bool_t dbus_py_init_float_types(void);
118 extern dbus_bool_t dbus_py_init_container_types(void);
119 extern dbus_bool_t dbus_py_init_byte_types(void);
120 extern dbus_bool_t dbus_py_insert_abstract_types(PyObject *this_module);
121 extern dbus_bool_t dbus_py_insert_signature(PyObject *this_module);
122 extern dbus_bool_t dbus_py_insert_int_types(PyObject *this_module);
123 extern dbus_bool_t dbus_py_insert_string_types(PyObject *this_module);
124 extern dbus_bool_t dbus_py_insert_float_types(PyObject *this_module);
125 extern dbus_bool_t dbus_py_insert_container_types(PyObject *this_module);
126 extern dbus_bool_t dbus_py_insert_byte_types(PyObject *this_module);
127
128 /* generic */
129 extern void dbus_py_take_gil_and_xdecref(PyObject *);
130 extern int dbus_py_immutable_setattro(PyObject *, PyObject *, PyObject *);
131 extern PyObject *dbus_py_tp_richcompare_by_pointer(PyObject *,
132                                                    PyObject *,
133                                                    int);
134 extern long dbus_py_tp_hash_by_pointer(PyObject *self);
135 extern PyObject *dbus_py_empty_tuple;
136 extern dbus_bool_t dbus_py_init_generic(void);
137
138 /* message.c */
139 extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg);
140 extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *);
141 extern dbus_bool_t dbus_py_init_message_types(void);
142 extern dbus_bool_t dbus_py_insert_message_types(PyObject *this_module);
143
144 /* pending-call.c */
145 extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
146                                                           PyObject *);
147 extern dbus_bool_t dbus_py_init_pending_call(void);
148 extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module);
149
150 /* mainloop.c */
151 extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
152                                              PyObject *mainloop);
153 extern dbus_bool_t dbus_py_set_up_server(PyObject *server,
154                                          PyObject *mainloop);
155 extern PyObject *dbus_py_get_default_main_loop(void);
156 extern dbus_bool_t dbus_py_check_mainloop_sanity(PyObject *);
157 extern dbus_bool_t dbus_py_init_mainloop(void);
158 extern dbus_bool_t dbus_py_insert_mainloop_types(PyObject *);
159
160 /* server.c */
161 extern PyTypeObject DBusPyServer_Type;
162 DEFINE_CHECK(DBusPyServer)
163 extern dbus_bool_t dbus_py_init_server_types(void);
164 extern dbus_bool_t dbus_py_insert_server_types(PyObject *this_module);
165 extern DBusServer *DBusPyServer_BorrowDBusServer(PyObject *self);
166
167 /* validation.c */
168 dbus_bool_t dbus_py_validate_bus_name(const char *name,
169                                       dbus_bool_t may_be_unique,
170                                       dbus_bool_t may_be_not_unique);
171 dbus_bool_t dbus_py_validate_member_name(const char *name);
172 dbus_bool_t dbus_py_validate_interface_name(const char *name);
173 dbus_bool_t dbus_py_validate_object_path(const char *path);
174 #define dbus_py_validate_error_name dbus_py_validate_interface_name
175
176 /* debugging support */
177 void _dbus_py_assertion_failed(const char *);
178 #define DBUS_PY_RAISE_VIA_NULL_IF_FAIL(assertion) \
179     do { if (!(assertion)) { \
180             _dbus_py_assertion_failed(#assertion); \
181             return NULL; \
182         } \
183     } while (0)
184
185 #define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
186     do { if (!(assertion)) { \
187             _dbus_py_assertion_failed(#assertion); \
188             goto label; \
189         } \
190     } while (0)
191
192 #define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
193     do { if (!(assertion)) { \
194             _dbus_py_assertion_failed(#assertion); \
195             return value; \
196         } \
197     } while (0)
198
199 /* verbose debugging support */
200 #ifdef USING_DBG
201
202 #   include <sys/types.h>
203 #   include <unistd.h>
204
205 void _dbus_py_dbg_exc(void);
206 void _dbus_py_whereami(void);
207 void _dbus_py_dbg_dump_message(DBusMessage *);
208
209 #   define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
210                                     "%d refs\n", \
211                                     self->ob_type->tp_name, \
212                                     self, __func__, \
213                                     self->ob_refcnt); } while (0)
214 #   define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
215                                     __VA_ARGS__)
216 #   define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
217                                     _dbus_py_dbg_exc();} while (0)
218 #   define DBG_DUMP_MESSAGE(x) _dbus_py_dbg_dump_message(x)
219 #   define DBG_WHEREAMI _dbus_py_whereami()
220
221 #else /* !defined(USING_DBG) */
222
223 #   define TRACE(self) do {} while (0)
224 #   define DBG(format, ...) do {} while (0)
225 #   define DBG_EXC(format, ...) do {} while (0)
226 #   define DBG_DUMP_MESSAGE(x) do {} while (0)
227 #   define DBG_WHEREAMI do {} while (0)
228
229 #endif /* !defined(USING_DBG) */
230
231 /* General-purpose Python glue */
232
233 #define DEFERRED_ADDRESS(ADDR) 0
234
235 #if defined(__GNUC__)
236 #   if __GNUC__ >= 3
237 #       define UNUSED __attribute__((__unused__))
238 #   else
239 #       define UNUSED /*nothing*/
240 #   endif
241 #else
242 #   define UNUSED /*nothing*/
243 #endif
244
245 #endif