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
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
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) */
47 #if 0 && !defined(DBG_IS_TOO_VERBOSE)
51 #define DEFINE_CHECK(type) \
52 static inline int type##_Check (PyObject *o) \
54 return (PyObject_TypeCheck (o, &type##_Type)); \
56 static inline int type##_CheckExact (PyObject *o) \
58 return ((o)->ob_type == &type##_Type); \
61 PyMODINIT_FUNC init_dbus_bindings(void);
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);
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);
77 extern dbus_bool_t dbus_py_init_bus_types(void);
78 extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module);
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);
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);
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 *,
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);
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);
145 extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
147 extern dbus_bool_t dbus_py_init_pending_call(void);
148 extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module);
151 extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
153 extern dbus_bool_t dbus_py_set_up_server(PyObject *server,
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 *);
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);
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
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); \
185 #define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
186 do { if (!(assertion)) { \
187 _dbus_py_assertion_failed(#assertion); \
192 #define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
193 do { if (!(assertion)) { \
194 _dbus_py_assertion_failed(#assertion); \
199 /* verbose debugging support */
202 # include <sys/types.h>
205 void _dbus_py_dbg_exc(void);
206 void _dbus_py_whereami(void);
207 void _dbus_py_dbg_dump_message(DBusMessage *);
209 # define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
211 self->ob_type->tp_name, \
213 self->ob_refcnt); } while (0)
214 # define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
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()
221 #else /* !defined(USING_DBG) */
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)
229 #endif /* !defined(USING_DBG) */
231 /* General-purpose Python glue */
233 #define DEFERRED_ADDRESS(ADDR) 0
235 #if defined(__GNUC__)
237 # define UNUSED __attribute__((__unused__))
239 # define UNUSED /*nothing*/
242 # define UNUSED /*nothing*/