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
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
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) */
46 #if 0 && !defined(DBG_IS_TOO_VERBOSE)
50 #define DEFINE_CHECK(type) \
51 static inline int type##_Check (PyObject *o) \
53 return (PyObject_TypeCheck (o, &type##_Type)); \
57 extern PyTypeObject DBusPyConnection_Type
;
58 DEFINE_CHECK(DBusPyConnection
)
59 extern PyObject
*DBusPyConnection_NewConsumingDBusConnection(PyTypeObject
*,
62 extern dbus_bool_t
dbus_py_init_conn_types(void);
63 extern dbus_bool_t
dbus_py_insert_conn_types(PyObject
*this_module
);
66 extern dbus_bool_t
dbus_py_init_bus_types(void);
67 extern dbus_bool_t
dbus_py_insert_bus_types(PyObject
*this_module
);
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
);
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
);
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
*,
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);
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
);
134 extern PyObject
*DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall
*,
136 extern dbus_bool_t
dbus_py_init_pending_call(void);
137 extern dbus_bool_t
dbus_py_insert_pending_call(PyObject
*this_module
);
140 extern dbus_bool_t
dbus_py_set_up_connection(PyObject
*conn
,
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
*);
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); \
165 #define DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(assertion, label) \
166 do { if (!(assertion)) { \
167 _dbus_py_assertion_failed(#assertion); \
172 #define DBUS_PY_RAISE_VIA_RETURN_IF_FAIL(assertion, value) \
173 do { if (!(assertion)) { \
174 _dbus_py_assertion_failed(#assertion); \
179 /* verbose debugging support */
182 # include <sys/types.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, " \
191 self->ob_type->tp_name, \
193 self->ob_refcnt); } while (0)
194 # define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
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__)
217 # define UNUSED __attribute__((__unused__))
219 # define UNUSED /*nothing*/
222 # define UNUSED /*nothing*/