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