Revert "Make sure extensions are built before docs; get rid of strange inter-director...
[dbus-python-phuang.git] / _dbus_bindings / dbus_bindings-internal.h
blob1dfd6b2925ead6c77268a8b5fbcfa78ba4040b11
1 /* _dbus_bindings internal API. For use within _dbus_bindings only.
3 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
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:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
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.
26 #ifndef DBUS_BINDINGS_INTERNAL_H
27 #define DBUS_BINDINGS_INTERNAL_H
29 #define PY_SSIZE_T_CLEAN 1
31 #include <Python.h>
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
40 #define INSIDE_DBUS_PYTHON_BINDINGS
41 #include "dbus-python.h"
43 /* no need for extern "C", this is only for internal use */
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
51 #define DEFINE_CHECK(type) \
52 static inline int type##_Check (PyObject *o) \
53 { \
54 return (PyObject_TypeCheck (o, &type##_Type)); \
57 /* conn.c */
58 extern PyTypeObject DBusPyConnection_Type;
59 DEFINE_CHECK(DBusPyConnection)
60 extern PyObject *DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *,
61 DBusConnection *,
62 PyObject *);
63 extern dbus_bool_t dbus_py_init_conn_types(void);
64 extern dbus_bool_t dbus_py_insert_conn_types(PyObject *this_module);
66 /* bus.c */
67 extern dbus_bool_t dbus_py_init_bus_types(void);
68 extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module);
70 /* exceptions.c */
71 extern PyObject *DBusPyException_SetString(const char *msg);
72 extern PyObject *DBusPyException_ConsumeError(DBusError *error);
73 extern dbus_bool_t dbus_py_init_exception_types(void);
74 extern dbus_bool_t dbus_py_insert_exception_types(PyObject *this_module);
76 /* types */
77 extern PyTypeObject DBusPyBoolean_Type;
78 DEFINE_CHECK(DBusPyBoolean)
79 extern PyTypeObject DBusPyObjectPath_Type, DBusPySignature_Type;
80 DEFINE_CHECK(DBusPyObjectPath)
81 DEFINE_CHECK(DBusPySignature)
82 extern PyTypeObject DBusPyArray_Type, DBusPyDict_Type, DBusPyStruct_Type;
83 DEFINE_CHECK(DBusPyArray)
84 DEFINE_CHECK(DBusPyDict)
85 DEFINE_CHECK(DBusPyStruct)
86 extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type;
87 DEFINE_CHECK(DBusPyByteArray)
88 DEFINE_CHECK(DBusPyByte)
89 extern PyTypeObject DBusPyUTF8String_Type, DBusPyString_Type;
90 DEFINE_CHECK(DBusPyUTF8String)
91 DEFINE_CHECK(DBusPyString)
92 extern PyTypeObject DBusPyDouble_Type;
93 DEFINE_CHECK(DBusPyDouble)
94 extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
95 DEFINE_CHECK(DBusPyInt16)
96 DEFINE_CHECK(DBusPyUInt16)
97 extern PyTypeObject DBusPyInt32_Type, DBusPyUInt32_Type;
98 DEFINE_CHECK(DBusPyInt32)
99 DEFINE_CHECK(DBusPyUInt32)
100 extern PyTypeObject DBusPyInt64_Type, DBusPyUInt64_Type;
101 DEFINE_CHECK(DBusPyInt64)
102 DEFINE_CHECK(DBusPyUInt64)
103 extern dbus_bool_t dbus_py_init_abstract(void);
104 extern dbus_bool_t dbus_py_init_signature(void);
105 extern dbus_bool_t dbus_py_init_int_types(void);
106 extern dbus_bool_t dbus_py_init_string_types(void);
107 extern dbus_bool_t dbus_py_init_float_types(void);
108 extern dbus_bool_t dbus_py_init_container_types(void);
109 extern dbus_bool_t dbus_py_init_byte_types(void);
110 extern dbus_bool_t dbus_py_insert_abstract_types(PyObject *this_module);
111 extern dbus_bool_t dbus_py_insert_signature(PyObject *this_module);
112 extern dbus_bool_t dbus_py_insert_int_types(PyObject *this_module);
113 extern dbus_bool_t dbus_py_insert_string_types(PyObject *this_module);
114 extern dbus_bool_t dbus_py_insert_float_types(PyObject *this_module);
115 extern dbus_bool_t dbus_py_insert_container_types(PyObject *this_module);
116 extern dbus_bool_t dbus_py_insert_byte_types(PyObject *this_module);
118 /* generic */
119 extern void dbus_py_take_gil_and_xdecref(PyObject *);
120 extern int dbus_py_immutable_setattro(PyObject *, PyObject *, PyObject *);
121 extern PyObject *dbus_py_tp_richcompare_by_pointer(PyObject *,
122 PyObject *,
123 int);
124 extern long dbus_py_tp_hash_by_pointer(PyObject *self);
125 extern PyObject *dbus_py_empty_tuple;
126 extern dbus_bool_t dbus_py_init_generic(void);
128 /* message.c */
129 extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg);
130 extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *);
131 extern dbus_bool_t dbus_py_init_message_types(void);
132 extern dbus_bool_t dbus_py_insert_message_types(PyObject *this_module);
134 /* pending-call.c */
135 extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
136 PyObject *);
137 extern dbus_bool_t dbus_py_init_pending_call(void);
138 extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module);
140 /* mainloop.c */
141 extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
142 PyObject *mainloop);
143 extern PyObject *dbus_py_get_default_main_loop(void);
144 extern dbus_bool_t dbus_py_check_mainloop_sanity(PyObject *);
145 extern dbus_bool_t dbus_py_init_mainloop(void);
146 extern dbus_bool_t dbus_py_insert_mainloop_types(PyObject *);
148 /* validation.c */
149 dbus_bool_t dbus_py_validate_bus_name(const char *name,
150 dbus_bool_t may_be_unique,
151 dbus_bool_t may_be_not_unique);
152 dbus_bool_t dbus_py_validate_member_name(const char *name);
153 dbus_bool_t dbus_py_validate_interface_name(const char *name);
154 dbus_bool_t dbus_py_validate_object_path(const char *path);
155 #define dbus_py_validate_error_name dbus_py_validate_interface_name
157 /* debugging support */
158 void _dbus_py_assertion_failed(const char *);
159 #define DBUS_PY_RAISE_VIA_NULL_IF_FAIL(assertion) \
160 do { if (!(assertion)) { \
161 _dbus_py_assertion_failed(#assertion); \
162 return NULL; \
164 } while (0)
166 #define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
167 do { if (!(assertion)) { \
168 _dbus_py_assertion_failed(#assertion); \
169 goto label; \
171 } while (0)
173 #define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
174 do { if (!(assertion)) { \
175 _dbus_py_assertion_failed(#assertion); \
176 return value; \
178 } while (0)
180 /* verbose debugging support */
181 #ifdef USING_DBG
183 # include <sys/types.h>
184 # include <unistd.h>
186 void _dbus_py_dbg_exc(void);
187 void _dbus_py_whereami(void);
188 void _dbus_py_dbg_dump_message(DBusMessage *);
190 # define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
191 "%d refs\n", \
192 self->ob_type->tp_name, \
193 self, __func__, \
194 self->ob_refcnt); } while (0)
195 # define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
196 __VA_ARGS__)
197 # define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
198 _dbus_py_dbg_exc();} while (0)
199 # define DBG_DUMP_MESSAGE(x) _dbus_py_dbg_dump_message(x)
200 # define DBG_WHEREAMI _dbus_py_whereami()
202 #else /* !defined(USING_DBG) */
204 # define TRACE(self) do {} while (0)
205 # define DBG(format, ...) do {} while (0)
206 # define DBG_EXC(format, ...) do {} while (0)
207 # define DBG_DUMP_MESSAGE(x) do {} while (0)
208 # define DBG_WHEREAMI do {} while (0)
210 #endif /* !defined(USING_DBG) */
212 /* General-purpose Python glue */
214 #define DEFERRED_ADDRESS(ADDR) 0
216 #if defined(__GNUC__)
217 # if __GNUC__ >= 3
218 # define UNUSED __attribute__((__unused__))
219 # else
220 # define UNUSED /*nothing*/
221 # endif
222 #else
223 # define UNUSED /*nothing*/
224 #endif
226 #endif