Add TRACE macro and allow debug to be turned off per file
[dbus-python-phuang.git] / _dbus_bindings / dbus_bindings-internal.h
blob82b52ba4cb661dc6a54eaaa74c1be25eaa58c2ae
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 #include <Python.h>
29 #define INSIDE_DBUS_BINDINGS
30 #include "dbus_bindings.h"
32 /* no need for extern "C", this is only for internal use */
34 /* on/off switch for debugging support (see below) */
35 #undef USING_DBG
36 #if 0 && !defined(DBG_IS_TOO_VERBOSE)
37 # define USING_DBG 1
38 #endif
40 #define DEFINE_CHECK(type) \
41 static inline int type##_Check (PyObject *o) \
42 { \
43 return (PyObject_TypeCheck (o, &type##_Type)); \
46 /* conn.c */
47 extern PyTypeObject DBusPyConnection_Type;
48 DEFINE_CHECK(DBusPyConnection)
49 extern PyObject *DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *,
50 DBusConnection *,
51 PyObject *);
52 extern dbus_bool_t dbus_py_init_conn_types(void);
53 extern dbus_bool_t dbus_py_insert_conn_types(PyObject *this_module);
55 /* bus.c */
56 extern dbus_bool_t dbus_py_init_bus_types(void);
57 extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module);
59 /* exceptions.c */
60 extern PyObject *DBusPyException;
61 extern PyObject *DBusPyException_ConsumeError(DBusError *error);
62 extern dbus_bool_t dbus_py_init_exception_types(void);
63 extern dbus_bool_t dbus_py_insert_exception_types(PyObject *this_module);
65 /* types */
66 extern PyTypeObject DBusPyBoolean_Type;
67 DEFINE_CHECK(DBusPyBoolean)
68 extern PyTypeObject DBusPyObjectPath_Type, DBusPySignature_Type;
69 DEFINE_CHECK(DBusPyObjectPath)
70 DEFINE_CHECK(DBusPySignature)
71 extern PyTypeObject DBusPyArray_Type, DBusPyDict_Type, DBusPyStruct_Type;
72 DEFINE_CHECK(DBusPyArray)
73 DEFINE_CHECK(DBusPyDict)
74 DEFINE_CHECK(DBusPyStruct)
75 extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type;
76 DEFINE_CHECK(DBusPyByteArray)
77 DEFINE_CHECK(DBusPyByte)
78 extern PyTypeObject DBusPyUTF8String_Type, DBusPyString_Type;
79 DEFINE_CHECK(DBusPyUTF8String)
80 DEFINE_CHECK(DBusPyString)
81 extern PyTypeObject DBusPyDouble_Type;
82 DEFINE_CHECK(DBusPyDouble)
83 extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type;
84 DEFINE_CHECK(DBusPyInt16)
85 DEFINE_CHECK(DBusPyUInt16)
86 extern PyTypeObject DBusPyInt32_Type, DBusPyUInt32_Type;
87 DEFINE_CHECK(DBusPyInt32)
88 DEFINE_CHECK(DBusPyUInt32)
89 extern PyTypeObject DBusPyInt64_Type, DBusPyUInt64_Type;
90 DEFINE_CHECK(DBusPyInt64)
91 DEFINE_CHECK(DBusPyUInt64)
92 extern dbus_bool_t dbus_py_init_abstract(void);
93 extern dbus_bool_t dbus_py_init_signature(void);
94 extern dbus_bool_t dbus_py_init_int_types(void);
95 extern dbus_bool_t dbus_py_init_string_types(void);
96 extern dbus_bool_t dbus_py_init_float_types(void);
97 extern dbus_bool_t dbus_py_init_container_types(void);
98 extern dbus_bool_t dbus_py_init_byte_types(void);
99 extern dbus_bool_t dbus_py_insert_abstract_types(PyObject *this_module);
100 extern dbus_bool_t dbus_py_insert_signature(PyObject *this_module);
101 extern dbus_bool_t dbus_py_insert_int_types(PyObject *this_module);
102 extern dbus_bool_t dbus_py_insert_string_types(PyObject *this_module);
103 extern dbus_bool_t dbus_py_insert_float_types(PyObject *this_module);
104 extern dbus_bool_t dbus_py_insert_container_types(PyObject *this_module);
105 extern dbus_bool_t dbus_py_insert_byte_types(PyObject *this_module);
107 /* generic */
108 extern void dbus_py_take_gil_and_xdecref(PyObject *);
109 extern int dbus_py_immutable_setattro(PyObject *, PyObject *, PyObject *);
110 extern PyObject *dbus_py_tp_richcompare_by_pointer(PyObject *,
111 PyObject *,
112 int);
113 extern long dbus_py_tp_hash_by_pointer(PyObject *self);
114 extern PyObject *dbus_py_empty_tuple;
115 extern dbus_bool_t dbus_py_init_generic(void);
117 /* message.c */
118 extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg);
119 extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *);
120 extern dbus_bool_t dbus_py_init_message_types(void);
121 extern dbus_bool_t dbus_py_insert_message_types(PyObject *this_module);
123 /* pending-call.c */
124 extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
125 PyObject *);
126 extern dbus_bool_t dbus_py_init_pending_call(void);
127 extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module);
129 /* mainloop.c */
130 extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
131 PyObject *mainloop);
132 extern PyObject *dbus_py_get_default_main_loop(void);
133 extern dbus_bool_t dbus_py_check_mainloop_sanity(PyObject *);
134 extern dbus_bool_t dbus_py_init_mainloop(void);
135 extern dbus_bool_t dbus_py_insert_mainloop_types(PyObject *);
137 /* validation.c */
138 dbus_bool_t dbus_py_validate_bus_name(const char *name,
139 dbus_bool_t may_be_unique,
140 dbus_bool_t may_be_not_unique);
141 dbus_bool_t dbus_py_validate_member_name(const char *name);
142 dbus_bool_t dbus_py_validate_interface_name(const char *name);
143 dbus_bool_t dbus_py_validate_object_path(const char *path);
144 #define dbus_py_validate_error_name dbus_py_validate_interface_name
146 /* debugging support */
147 void _dbus_py_assertion_failed(const char *);
148 #define DBUS_PY_RAISE_VIA_NULL_IF_FAIL(assertion) \
149 do { if (!(assertion)) { \
150 _dbus_py_assertion_failed(#assertion); \
151 return NULL; \
153 } while (0)
155 #define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
156 do { if (!(assertion)) { \
157 _dbus_py_assertion_failed(#assertion); \
158 goto label; \
160 } while (0)
162 #define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
163 do { if (!(assertion)) { \
164 _dbus_py_assertion_failed(#assertion); \
165 return value; \
167 } while (0)
169 /* verbose debugging support */
170 #ifdef USING_DBG
172 # include <sys/types.h>
173 # include <unistd.h>
175 void _dbus_py_dbg_exc(void);
176 void _dbus_py_whereami(void);
177 void _dbus_py_dbg_dump_message(DBusMessage *);
179 # define TRACE(self) do { fprintf(stderr, "TRACE: <%s at %p> in %s, " \
180 "%d refs\n", \
181 self->ob_type->tp_name, \
182 self, __func__, \
183 self->ob_refcnt); } while (0)
184 # define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
185 __VA_ARGS__)
186 # define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
187 _dbus_py_dbg_exc();} while (0)
188 # define DBG_DUMP_MESSAGE(x) _dbus_py_dbg_dump_message(x)
189 # define DBG_WHEREAMI _dbus_py_whereami()
191 #else /* !defined(USING_DBG) */
193 # define TRACE(self) do {} while (0)
194 # define DBG(format, ...) do {} while (0)
195 # define DBG_EXC(format, ...) do {} while (0)
196 # define DBG_DUMP_MESSAGE(x) do {} while (0)
197 # define DBG_WHEREAMI do {} while (0)
199 #endif /* !defined(USING_DBG) */
201 /* General-purpose Python glue */
203 #define DEFERRED_ADDRESS(ADDR) 0
205 #if defined(__GNUC__)
206 # if __GNUC__ >= 3
207 # define UNUSED __attribute__((__unused__))
208 # else
209 # define UNUSED /*nothing*/
210 # endif
211 #else
212 # define UNUSED /*nothing*/
213 #endif
215 #endif