NEWS: update
[dbus-python-phuang.git] / _dbus_bindings / dbus_bindings-internal.h
blob2e7f6ffcb6c3e43c27d216eb0cc4f68e1c2fe161
1 /* _dbus_bindings internal API. For use within _dbus_bindings only.
3 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
5 * Licensed under the Academic Free License version 2.1
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef DBUS_BINDINGS_INTERNAL_H
24 #define DBUS_BINDINGS_INTERNAL_H
26 #define PY_SSIZE_T_CLEAN 1
28 #include <Python.h>
30 /* Python < 2.5 compat */
31 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
32 typedef int Py_ssize_t;
33 #define PY_SSIZE_T_MAX INT_MAX
34 #define PY_SSIZE_T_MIN INT_MIN
35 #endif
37 #define INSIDE_DBUS_PYTHON_BINDINGS
38 #include "dbus-python.h"
40 /* no need for extern "C", this is only for internal use */
42 /* on/off switch for debugging support (see below) */
43 #undef USING_DBG
44 #if 0 && !defined(DBG_IS_TOO_VERBOSE)
45 # define USING_DBG 1
46 #endif
48 #define DEFINE_CHECK(type) \
49 static inline int type##_Check (PyObject *o) \
50 { \
51 return (PyObject_TypeCheck (o, &type##_Type)); \
54 /* conn.c */
55 extern PyTypeObject DBusPyConnection_Type;
56 DEFINE_CHECK(DBusPyConnection)
57 extern PyObject *DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *,
58 DBusConnection *,
59 PyObject *);
60 extern dbus_bool_t dbus_py_init_conn_types(void);
61 extern dbus_bool_t dbus_py_insert_conn_types(PyObject *this_module);
63 /* bus.c */
64 extern dbus_bool_t dbus_py_init_bus_types(void);
65 extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module);
67 /* exceptions.c */
68 extern PyObject *DBusPyException_SetString(const char *msg);
69 extern PyObject *DBusPyException_ConsumeError(DBusError *error);
70 extern dbus_bool_t dbus_py_init_exception_types(void);
71 extern dbus_bool_t dbus_py_insert_exception_types(PyObject *this_module);
73 /* types */
74 extern PyTypeObject DBusPyBoolean_Type;
75 DEFINE_CHECK(DBusPyBoolean)
76 extern PyTypeObject DBusPyObjectPath_Type, DBusPySignature_Type;
77 DEFINE_CHECK(DBusPyObjectPath)
78 DEFINE_CHECK(DBusPySignature)
79 extern PyTypeObject DBusPyArray_Type, DBusPyDict_Type, DBusPyStruct_Type;
80 DEFINE_CHECK(DBusPyArray)
81 DEFINE_CHECK(DBusPyDict)
82 DEFINE_CHECK(DBusPyStruct)
83 extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type;
84 DEFINE_CHECK(DBusPyByteArray)
85 DEFINE_CHECK(DBusPyByte)
86 extern PyTypeObject DBusPyUTF8String_Type, DBusPyString_Type;
87 DEFINE_CHECK(DBusPyUTF8String)
88 DEFINE_CHECK(DBusPyString)
89 extern PyTypeObject DBusPyDouble_Type;
90 DEFINE_CHECK(DBusPyDouble)
91 extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
92 DEFINE_CHECK(DBusPyInt16)
93 DEFINE_CHECK(DBusPyUInt16)
94 extern PyTypeObject DBusPyInt32_Type, DBusPyUInt32_Type;
95 DEFINE_CHECK(DBusPyInt32)
96 DEFINE_CHECK(DBusPyUInt32)
97 extern PyTypeObject DBusPyInt64_Type, DBusPyUInt64_Type;
98 DEFINE_CHECK(DBusPyInt64)
99 DEFINE_CHECK(DBusPyUInt64)
100 extern dbus_bool_t dbus_py_init_abstract(void);
101 extern dbus_bool_t dbus_py_init_signature(void);
102 extern dbus_bool_t dbus_py_init_int_types(void);
103 extern dbus_bool_t dbus_py_init_string_types(void);
104 extern dbus_bool_t dbus_py_init_float_types(void);
105 extern dbus_bool_t dbus_py_init_container_types(void);
106 extern dbus_bool_t dbus_py_init_byte_types(void);
107 extern dbus_bool_t dbus_py_insert_abstract_types(PyObject *this_module);
108 extern dbus_bool_t dbus_py_insert_signature(PyObject *this_module);
109 extern dbus_bool_t dbus_py_insert_int_types(PyObject *this_module);
110 extern dbus_bool_t dbus_py_insert_string_types(PyObject *this_module);
111 extern dbus_bool_t dbus_py_insert_float_types(PyObject *this_module);
112 extern dbus_bool_t dbus_py_insert_container_types(PyObject *this_module);
113 extern dbus_bool_t dbus_py_insert_byte_types(PyObject *this_module);
115 /* generic */
116 extern void dbus_py_take_gil_and_xdecref(PyObject *);
117 extern int dbus_py_immutable_setattro(PyObject *, PyObject *, PyObject *);
118 extern PyObject *dbus_py_tp_richcompare_by_pointer(PyObject *,
119 PyObject *,
120 int);
121 extern long dbus_py_tp_hash_by_pointer(PyObject *self);
122 extern PyObject *dbus_py_empty_tuple;
123 extern dbus_bool_t dbus_py_init_generic(void);
125 /* message.c */
126 extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg);
127 extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *);
128 extern dbus_bool_t dbus_py_init_message_types(void);
129 extern dbus_bool_t dbus_py_insert_message_types(PyObject *this_module);
131 /* pending-call.c */
132 extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
133 PyObject *);
134 extern dbus_bool_t dbus_py_init_pending_call(void);
135 extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module);
137 /* mainloop.c */
138 extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
139 PyObject *mainloop);
140 extern PyObject *dbus_py_get_default_main_loop(void);
141 extern dbus_bool_t dbus_py_check_mainloop_sanity(PyObject *);
142 extern dbus_bool_t dbus_py_init_mainloop(void);
143 extern dbus_bool_t dbus_py_insert_mainloop_types(PyObject *);
145 /* validation.c */
146 dbus_bool_t dbus_py_validate_bus_name(const char *name,
147 dbus_bool_t may_be_unique,
148 dbus_bool_t may_be_not_unique);
149 dbus_bool_t dbus_py_validate_member_name(const char *name);
150 dbus_bool_t dbus_py_validate_interface_name(const char *name);
151 dbus_bool_t dbus_py_validate_object_path(const char *path);
152 #define dbus_py_validate_error_name dbus_py_validate_interface_name
154 /* debugging support */
155 void _dbus_py_assertion_failed(const char *);
156 #define DBUS_PY_RAISE_VIA_NULL_IF_FAIL(assertion) \
157 do { if (!(assertion)) { \
158 _dbus_py_assertion_failed(#assertion); \
159 return NULL; \
161 } while (0)
163 #define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
164 do { if (!(assertion)) { \
165 _dbus_py_assertion_failed(#assertion); \
166 goto label; \
168 } while (0)
170 #define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
171 do { if (!(assertion)) { \
172 _dbus_py_assertion_failed(#assertion); \
173 return value; \
175 } while (0)
177 /* verbose debugging support */
178 #ifdef USING_DBG
180 # include <sys/types.h>
181 # include <unistd.h>
183 void _dbus_py_dbg_exc(void);
184 void _dbus_py_whereami(void);
185 void _dbus_py_dbg_dump_message(DBusMessage *);
187 # define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
188 "%d refs\n", \
189 self->ob_type->tp_name, \
190 self, __func__, \
191 self->ob_refcnt); } while (0)
192 # define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
193 __VA_ARGS__)
194 # define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
195 _dbus_py_dbg_exc();} while (0)
196 # define DBG_DUMP_MESSAGE(x) _dbus_py_dbg_dump_message(x)
197 # define DBG_WHEREAMI _dbus_py_whereami()
199 #else /* !defined(USING_DBG) */
201 # define TRACE(self) do {} while (0)
202 # define DBG(format, ...) do {} while (0)
203 # define DBG_EXC(format, ...) do {} while (0)
204 # define DBG_DUMP_MESSAGE(x) do {} while (0)
205 # define DBG_WHEREAMI do {} while (0)
207 #endif /* !defined(USING_DBG) */
209 /* General-purpose Python glue */
211 #define DEFERRED_ADDRESS(ADDR) 0
213 #if defined(__GNUC__)
214 # if __GNUC__ >= 3
215 # define UNUSED __attribute__((__unused__))
216 # else
217 # define UNUSED /*nothing*/
218 # endif
219 #else
220 # define UNUSED /*nothing*/
221 #endif
223 #endif