summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2006-12-08 17:50:25 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2006-12-08 17:50:25 +0000
commitf50c6643bf9fe153a7add75ca150a1470b7eb63a (patch)
tree5642aaab556c4fea023cfb0781b0272035235bf3
parent380b44d38d333092bc9fe2eae8b7a836cb2791c7 (diff)
downloaddbus-python-f50c6643bf9fe153a7add75ca150a1470b7eb63a.tar.gz
_dbus_bindings: split out conn, conn-methods into separate translation units
-rw-r--r--_dbus_bindings/bus-impl.h35
-rw-r--r--_dbus_bindings/conn-internal.h52
-rw-r--r--_dbus_bindings/conn-methods.c (renamed from _dbus_bindings/conn-methods-impl.h)191
-rw-r--r--_dbus_bindings/conn.c (renamed from _dbus_bindings/conn-impl.h)260
-rw-r--r--_dbus_bindings/dbus_bindings-internal.h113
-rw-r--r--_dbus_bindings/debug-impl.h39
-rw-r--r--_dbus_bindings/exceptions-impl.h28
-rw-r--r--_dbus_bindings/generic-impl.h16
-rw-r--r--_dbus_bindings/mainloop-impl.h47
-rw-r--r--_dbus_bindings/message-impl.h57
-rw-r--r--_dbus_bindings/module.c8
-rw-r--r--_dbus_bindings/pending-call-impl.h7
-rw-r--r--_dbus_bindings/types-impl.h2
-rw-r--r--_dbus_bindings/validation-impl.h28
-rw-r--r--include/dbus_bindings.h7
-rw-r--r--setup.py6
16 files changed, 513 insertions, 383 deletions
diff --git a/_dbus_bindings/bus-impl.h b/_dbus_bindings/bus-impl.h
index c5614a7..2fa5d79 100644
--- a/_dbus_bindings/bus-impl.h
+++ b/_dbus_bindings/bus-impl.h
@@ -22,6 +22,9 @@
*
*/
+#include "dbus_bindings-internal.h"
+#include "conn-internal.h"
+
PyDoc_STRVAR(Bus_tp_doc,
"BusImplementation([address: str or int])\n\n"
"If the address is an int it must be one of the constants BUS_SESSION,\n"
@@ -57,19 +60,19 @@ Bus_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs)
if (first && PyString_Check(first)) {
/* It's a custom address. First connect to it, then register. */
- self = (Connection *)Connection_tp_new(cls, args, kwargs);
+ self = (Connection *)(DBusPyConnectionType.tp_new)(cls, args, kwargs);
if (!self) return NULL;
Py_BEGIN_ALLOW_THREADS
ret = dbus_bus_register(self->conn, &error);
Py_END_ALLOW_THREADS
if (!ret) {
- DBusException_ConsumeError(&error);
+ DBusPyException_ConsumeError(&error);
Py_DECREF(self);
return NULL;
}
- return self;
+ return (PyObject *)self;
}
/* If the first argument isn't a string, it must be an integer
@@ -98,10 +101,10 @@ Bus_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Py_END_ALLOW_THREADS
if (!conn) {
- DBusException_ConsumeError (&error);
+ DBusPyException_ConsumeError (&error);
return NULL;
}
- return Connection_NewConsumingDBusConnection(cls, conn, mainloop);
+ return DBusPyConnection_NewConsumingDBusConnection(cls, conn, mainloop);
}
PyDoc_STRVAR(Bus_get_unique_name__doc__,
@@ -117,7 +120,7 @@ Bus_get_unique_name (Connection *self, PyObject *args UNUSED)
Py_END_ALLOW_THREADS
if (!name) {
/* shouldn't happen, but C subtypes could have done something stupid */
- PyErr_SetString (DBusException, "Unable to retrieve unique name");
+ PyErr_SetString(DBusPyException, "Unable to retrieve unique name");
return NULL;
}
return PyString_FromString (name);
@@ -148,7 +151,7 @@ Bus_get_unix_user (Connection *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
uid = dbus_bus_get_unix_user (self->conn, bus_name, &error);
Py_END_ALLOW_THREADS
- if (uid == (unsigned long)(-1)) return DBusException_ConsumeError (&error);
+ if (uid == (unsigned long)(-1)) return DBusPyException_ConsumeError(&error);
return PyLong_FromUnsignedLong (uid);
}
@@ -186,7 +189,7 @@ Bus_start_service_by_name (Connection *self, PyObject *args)
0 /* flags */, &ret, &error);
Py_END_ALLOW_THREADS
if (!success) {
- return DBusException_ConsumeError (&error);
+ return DBusPyException_ConsumeError(&error);
}
return Py_BuildValue ("(Ol)", Py_True, (long)ret);
}
@@ -204,13 +207,13 @@ Bus_request_name (Connection *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s|I:request_name", &bus_name, &flags)) {
return NULL;
}
- if (!_validate_bus_name(bus_name, 0, 1)) return NULL;
+ if (!dbus_py_validate_bus_name(bus_name, 0, 1)) return NULL;
dbus_error_init (&error);
Py_BEGIN_ALLOW_THREADS
ret = dbus_bus_request_name(self->conn, bus_name, flags, &error);
Py_END_ALLOW_THREADS
- if (ret == -1) return DBusException_ConsumeError (&error);
+ if (ret == -1) return DBusPyException_ConsumeError(&error);
return PyInt_FromLong(ret);
}
@@ -229,7 +232,7 @@ Bus_release_name (Connection *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
ret = dbus_bus_release_name(self->conn, bus_name, &error);
Py_END_ALLOW_THREADS
- if (ret == -1) return DBusException_ConsumeError (&error);
+ if (ret == -1) return DBusPyException_ConsumeError(&error);
return PyInt_FromLong(ret);
}
@@ -250,7 +253,7 @@ Bus_name_has_owner (Connection *self, PyObject *args)
ret = dbus_bus_name_has_owner(self->conn, bus_name, &error);
Py_END_ALLOW_THREADS
if (dbus_error_is_set (&error)) {
- return DBusException_ConsumeError (&error);
+ return DBusPyException_ConsumeError(&error);
}
return PyBool_FromLong(ret);
}
@@ -271,7 +274,7 @@ Bus_add_match_string (Connection *self, PyObject *args)
dbus_bus_add_match (self->conn, rule, &error);
Py_END_ALLOW_THREADS
if (dbus_error_is_set (&error)) {
- return DBusException_ConsumeError (&error);
+ return DBusPyException_ConsumeError(&error);
}
Py_RETURN_NONE;
}
@@ -310,7 +313,7 @@ Bus_remove_match_string (Connection *self, PyObject *args)
dbus_bus_remove_match (self->conn, rule, &error);
Py_END_ALLOW_THREADS
if (dbus_error_is_set (&error)) {
- return DBusException_ConsumeError (&error);
+ return DBusPyException_ConsumeError(&error);
}
Py_RETURN_NONE;
}
@@ -357,7 +360,7 @@ static PyTypeObject BusType = {
0, /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
- (destructor)Connection_tp_dealloc, /*tp_dealloc*/
+ 0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
@@ -398,7 +401,7 @@ static PyTypeObject BusType = {
static inline int
init_bus_types (void)
{
- BusType.tp_base = &ConnectionType;
+ BusType.tp_base = &DBusPyConnectionType;
if (PyType_Ready (&BusType) < 0) return 0;
return 1;
}
diff --git a/_dbus_bindings/conn-internal.h b/_dbus_bindings/conn-internal.h
new file mode 100644
index 0000000..668e136
--- /dev/null
+++ b/_dbus_bindings/conn-internal.h
@@ -0,0 +1,52 @@
+/* _dbus_bindings internal API. For use within _dbus_bindings only.
+ *
+ * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef DBUS_BINDINGS_CONN_H
+#define DBUS_BINDINGS_CONN_H
+
+#include "dbus_bindings.h"
+
+typedef struct {
+ PyObject_HEAD
+ DBusConnection *conn;
+ /* A list of filter callbacks. */
+ PyObject *filters;
+ /* A dict mapping object paths to one of:
+ * - tuples (unregister_callback or None, message_callback)
+ * - None (meaning unregistration from libdbus is in progress and nobody
+ * should touch this entry til we're finished)
+ */
+ PyObject *object_paths;
+
+ PyObject *weaklist;
+} Connection;
+
+extern struct PyMethodDef DBusPyConnection_tp_methods[];
+extern DBusHandlerResult DBusPyConnection_HandleMessage(Connection *,
+ PyObject *,
+ PyObject *);
+extern PyObject *DBusPyConnection_ExistingFromDBusConnection(DBusConnection *);
+extern PyObject *DBusPyConnection_GetObjectPathHandlers(PyObject *self,
+ PyObject *path);
+
+#endif
diff --git a/_dbus_bindings/conn-methods-impl.h b/_dbus_bindings/conn-methods.c
index 8d02601..47f2ae0 100644
--- a/_dbus_bindings/conn-methods-impl.h
+++ b/_dbus_bindings/conn-methods.c
@@ -23,6 +23,181 @@
*
*/
+#include "dbus_bindings-internal.h"
+#include "conn-internal.h"
+
+static void
+_object_path_unregister(DBusConnection *conn, void *user_data)
+{
+ PyGILState_STATE gil = PyGILState_Ensure();
+ PyObject *tuple = NULL;
+ Connection *conn_obj = NULL;
+ PyObject *callable;
+
+ conn_obj = (Connection *)DBusPyConnection_ExistingFromDBusConnection(conn);
+ if (!conn_obj) goto out;
+
+ DBG("Connection at %p unregistering object path %s",
+ conn_obj, PyString_AS_STRING((PyObject *)user_data));
+ tuple = DBusPyConnection_GetObjectPathHandlers((PyObject *)conn_obj, (PyObject *)user_data);
+ if (!tuple) goto out;
+ if (tuple == Py_None) goto out;
+
+ DBG("%s", "... yes we have handlers for that object path");
+
+ /* 0'th item is the unregisterer (if that's a word) */
+ callable = PyTuple_GetItem(tuple, 0);
+ if (callable && callable != Py_None) {
+ DBG("%s", "... and we even have an unregisterer");
+ /* any return from the unregisterer is ignored */
+ Py_XDECREF(PyObject_CallFunctionObjArgs(callable, conn_obj, NULL));
+ }
+out:
+ Py_XDECREF(conn_obj);
+ Py_XDECREF(tuple);
+ /* the user_data (a Python str) is no longer ref'd by the DBusConnection */
+ Py_XDECREF((PyObject *)user_data);
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ }
+ PyGILState_Release(gil);
+}
+
+static DBusHandlerResult
+_object_path_message(DBusConnection *conn, DBusMessage *message,
+ void *user_data)
+{
+ DBusHandlerResult ret;
+ PyGILState_STATE gil = PyGILState_Ensure();
+ Connection *conn_obj = NULL;
+ PyObject *tuple = NULL;
+ PyObject *msg_obj;
+ PyObject *callable; /* borrowed */
+
+ dbus_message_ref(message);
+ msg_obj = DBusPyMessage_ConsumeDBusMessage(message);
+ if (!msg_obj) {
+ ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto out;
+ }
+
+ conn_obj = (Connection *)DBusPyConnection_ExistingFromDBusConnection(conn);
+ if (!conn_obj) {
+ ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto out;
+ }
+
+ DBG("Connection at %p messaging object path %s",
+ conn_obj, PyString_AS_STRING((PyObject *)user_data));
+ DBG_DUMP_MESSAGE(message);
+ tuple = DBusPyConnection_GetObjectPathHandlers((PyObject *)conn_obj, (PyObject *)user_data);
+ if (!tuple || tuple == Py_None) {
+ ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto out;
+ }
+
+ DBG("%s", "... yes we have handlers for that object path");
+
+ /* 1st item (0-based) is the message callback */
+ callable = PyTuple_GetItem(tuple, 1);
+ if (!callable) {
+ DBG("%s", "... error getting message handler from tuple");
+ ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ else if (callable == Py_None) {
+ /* there was actually no handler after all */
+ DBG("%s", "... but those handlers don't do messages");
+ ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ else {
+ DBG("%s", "... and we have a message handler for that object path");
+ ret = DBusPyConnection_HandleMessage(conn_obj, msg_obj, callable);
+ }
+
+out:
+ Py_XDECREF(msg_obj);
+ Py_XDECREF(conn_obj);
+ Py_XDECREF(tuple);
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ }
+ PyGILState_Release(gil);
+ return ret;
+}
+
+static const DBusObjectPathVTable _object_path_vtable = {
+ _object_path_unregister,
+ _object_path_message,
+};
+
+static DBusHandlerResult
+_filter_message(DBusConnection *conn, DBusMessage *message, void *user_data)
+{
+ DBusHandlerResult ret;
+ PyGILState_STATE gil = PyGILState_Ensure();
+ Connection *conn_obj = NULL;
+ PyObject *callable = NULL;
+ PyObject *msg_obj;
+#ifndef DBUS_PYTHON_DISABLE_CHECKS
+ int i, size;
+#endif
+
+ dbus_message_ref(message);
+ msg_obj = DBusPyMessage_ConsumeDBusMessage(message);
+ if (!msg_obj) {
+ DBG("%s", "OOM while trying to construct Message");
+ ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
+ goto out;
+ }
+
+ conn_obj = (Connection *)DBusPyConnection_ExistingFromDBusConnection(conn);
+ if (!conn_obj) {
+ DBG("%s", "failed to traverse DBusConnection -> Connection weakref");
+ ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto out;
+ }
+
+ /* The user_data is a pointer to a Python object. To avoid
+ * cross-library reference cycles, the DBusConnection isn't allowed
+ * to reference it. However, as long as the Connection is still
+ * alive, its ->filters list owns a reference to the same Python
+ * object, so the object should also still be alive.
+ *
+ * To ensure that this works, be careful whenever manipulating the
+ * filters list! (always put things in the list *before* giving
+ * them to libdbus, etc.)
+ */
+#ifdef DBUS_PYTHON_DISABLE_CHECKS
+ callable = (PyObject *)user_data;
+#else
+ size = PyList_GET_SIZE(conn_obj->filters);
+ for (i = 0; i < size; i++) {
+ callable = PyList_GET_ITEM(conn_obj->filters, i);
+ if (callable == user_data) {
+ Py_INCREF(callable);
+ }
+ else {
+ callable = NULL;
+ }
+ }
+
+ if (!callable) {
+ DBG("... filter %p has vanished from ->filters, so not calling it",
+ user_data);
+ ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ goto out;
+ }
+#endif
+
+ ret = DBusPyConnection_HandleMessage(conn_obj, msg_obj, callable);
+out:
+ Py_XDECREF(msg_obj);
+ Py_XDECREF(conn_obj);
+ Py_XDECREF(callable);
+ PyGILState_Release(gil);
+ return ret;
+}
+
PyDoc_STRVAR(Connection_close__doc__,
"close()\n\n"
"Close the connection.");
@@ -109,7 +284,7 @@ Connection_send_message(Connection *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O", &obj)) return NULL;
- msg = Message_BorrowDBusMessage(obj);
+ msg = DBusPyMessage_BorrowDBusMessage(obj);
if (!msg) return NULL;
Py_BEGIN_ALLOW_THREADS
@@ -158,7 +333,7 @@ Connection_send_message_with_reply(Connection *self, PyObject *args)
return NULL;
}
- msg = Message_BorrowDBusMessage(obj);
+ msg = DBusPyMessage_BorrowDBusMessage(obj);
if (!msg) return NULL;
if (timeout_s < 0) {
@@ -181,7 +356,7 @@ Connection_send_message_with_reply(Connection *self, PyObject *args)
return PyErr_NoMemory();
}
- return PendingCall_ConsumeDBusPendingCall(pending, callable);
+ return DBusPyPendingCall_ConsumeDBusPendingCall(pending, callable);
}
/* Again, the timeout is in seconds, since that's conventional in Python. */
@@ -222,7 +397,7 @@ Connection_send_message_with_reply_and_block(Connection *self, PyObject *args)
return NULL;
}
- msg = Message_BorrowDBusMessage(obj);
+ msg = DBusPyMessage_BorrowDBusMessage(obj);
if (!msg) return NULL;
if (timeout_s < 0) {
@@ -243,9 +418,9 @@ Connection_send_message_with_reply_and_block(Connection *self, PyObject *args)
Py_END_ALLOW_THREADS
if (!reply) {
- return DBusException_ConsumeError(&error);
+ return DBusPyException_ConsumeError(&error);
}
- return Message_ConsumeDBusMessage(reply);
+ return DBusPyMessage_ConsumeDBusMessage(reply);
}
PyDoc_STRVAR(Connection_flush__doc__,
@@ -464,7 +639,7 @@ Connection__register_object_path(Connection *self, PyObject *args,
return NULL;
}
- if (!_validate_object_path(PyString_AS_STRING(path))) {
+ if (!dbus_py_validate_object_path(PyString_AS_STRING(path))) {
Py_DECREF(path);
return NULL;
}
@@ -663,7 +838,7 @@ Connection__unregister_object_path(Connection *self, PyObject *args,
/* dbus_connection_get_outgoing_size - almost certainly unneeded */
-static struct PyMethodDef Connection_tp_methods[] = {
+struct PyMethodDef DBusPyConnection_tp_methods[] = {
#define ENTRY(name, flags) {#name, (PyCFunction)Connection_##name, flags, Connection_##name##__doc__}
ENTRY(close, METH_NOARGS),
ENTRY(flush, METH_NOARGS),
diff --git a/_dbus_bindings/conn-impl.h b/_dbus_bindings/conn.c
index 4396a04..ed79096 100644
--- a/_dbus_bindings/conn-impl.h
+++ b/_dbus_bindings/conn.c
@@ -23,6 +23,9 @@
*
*/
+#include "dbus_bindings-internal.h"
+#include "conn-internal.h"
+
/* Connection definition ============================================ */
PyDoc_STRVAR(Connection_tp_doc,
@@ -30,207 +33,6 @@ PyDoc_STRVAR(Connection_tp_doc,
"Connection(address: str, mainloop=None) -> Connection\n"
);
-typedef struct Connection {
- PyObject_HEAD
- DBusConnection *conn;
- /* A list of filter callbacks. */
- PyObject *filters;
- /* A dict mapping object paths to one of:
- * - tuples (unregister_callback or None, message_callback)
- * - None (meaning unregistration from libdbus is in progress and nobody
- * should touch this entry til we're finished)
- */
- PyObject *object_paths;
-
- PyObject *weaklist;
-} Connection;
-
-static PyTypeObject ConnectionType;
-
-static inline int Connection_Check(PyObject *o)
-{
- return PyObject_TypeCheck(o, &ConnectionType);
-}
-
-/* Helpers ========================================================== */
-
-static PyObject *Connection_ExistingFromDBusConnection(DBusConnection *);
-static PyObject *Connection_GetObjectPathHandlers(Connection *, PyObject *);
-static DBusHandlerResult Connection_HandleMessage(Connection *, Message *,
- PyObject *);
-
-static void
-_object_path_unregister(DBusConnection *conn, void *user_data)
-{
- PyGILState_STATE gil = PyGILState_Ensure();
- PyObject *tuple = NULL;
- Connection *conn_obj = NULL;
- PyObject *callable;
-
- conn_obj = (Connection *)Connection_ExistingFromDBusConnection(conn);
- if (!conn_obj) goto out;
-
- DBG("Connection at %p unregistering object path %s",
- conn_obj, PyString_AS_STRING((PyObject *)user_data));
- tuple = Connection_GetObjectPathHandlers(conn_obj, (PyObject *)user_data);
- if (!tuple) goto out;
- if (tuple == Py_None) goto out;
-
- DBG("%s", "... yes we have handlers for that object path");
-
- /* 0'th item is the unregisterer (if that's a word) */
- callable = PyTuple_GetItem(tuple, 0);
- if (callable && callable != Py_None) {
- DBG("%s", "... and we even have an unregisterer");
- /* any return from the unregisterer is ignored */
- Py_XDECREF(PyObject_CallFunctionObjArgs(callable, conn_obj, NULL));
- }
-out:
- Py_XDECREF(conn_obj);
- Py_XDECREF(tuple);
- /* the user_data (a Python str) is no longer ref'd by the DBusConnection */
- Py_XDECREF((PyObject *)user_data);
- if (PyErr_Occurred()) {
- PyErr_Print();
- }
- PyGILState_Release(gil);
-}
-
-static DBusHandlerResult
-_object_path_message(DBusConnection *conn, DBusMessage *message,
- void *user_data)
-{
- DBusHandlerResult ret;
- PyGILState_STATE gil = PyGILState_Ensure();
- Connection *conn_obj = NULL;
- PyObject *tuple = NULL;
- Message *msg_obj;
- PyObject *callable; /* borrowed */
-
- dbus_message_ref(message);
- msg_obj = (Message *)Message_ConsumeDBusMessage(message);
- if (!msg_obj) {
- ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
- goto out;
- }
-
- conn_obj = (Connection *)Connection_ExistingFromDBusConnection(conn);
- if (!conn_obj) {
- ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- goto out;
- }
-
- DBG("Connection at %p messaging object path %s",
- conn_obj, PyString_AS_STRING((PyObject *)user_data));
- DBG_DUMP_MESSAGE(message);
- tuple = Connection_GetObjectPathHandlers(conn_obj, (PyObject *)user_data);
- if (!tuple || tuple == Py_None) {
- ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- goto out;
- }
-
- DBG("%s", "... yes we have handlers for that object path");
-
- /* 1st item (0-based) is the message callback */
- callable = PyTuple_GetItem(tuple, 1);
- if (!callable) {
- DBG("%s", "... error getting message handler from tuple");
- ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- else if (callable == Py_None) {
- /* there was actually no handler after all */
- DBG("%s", "... but those handlers don't do messages");
- ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- else {
- DBG("%s", "... and we have a message handler for that object path");
- ret = Connection_HandleMessage(conn_obj, msg_obj, callable);
- }
-
-out:
- Py_XDECREF(msg_obj);
- Py_XDECREF(conn_obj);
- Py_XDECREF(tuple);
- if (PyErr_Occurred()) {
- PyErr_Print();
- }
- PyGILState_Release(gil);
- return ret;
-}
-
-static const DBusObjectPathVTable _object_path_vtable = {
- _object_path_unregister,
- _object_path_message,
-};
-
-static DBusHandlerResult
-_filter_message(DBusConnection *conn, DBusMessage *message, void *user_data)
-{
- DBusHandlerResult ret;
- PyGILState_STATE gil = PyGILState_Ensure();
- Connection *conn_obj = NULL;
- PyObject *callable = NULL;
- Message *msg_obj;
-#ifndef DBUS_PYTHON_DISABLE_CHECKS
- int i, size;
-#endif
-
- dbus_message_ref(message);
- msg_obj = (Message *)Message_ConsumeDBusMessage(message);
- if (!msg_obj) {
- DBG("%s", "OOM while trying to construct Message");
- ret = DBUS_HANDLER_RESULT_NEED_MEMORY;
- goto out;
- }
-
- conn_obj = (Connection *)Connection_ExistingFromDBusConnection(conn);
- if (!conn_obj) {
- DBG("%s", "failed to traverse DBusConnection -> Connection weakref");
- ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- goto out;
- }
-
- /* The user_data is a pointer to a Python object. To avoid
- * cross-library reference cycles, the DBusConnection isn't allowed
- * to reference it. However, as long as the Connection is still
- * alive, its ->filters list owns a reference to the same Python
- * object, so the object should also still be alive.
- *
- * To ensure that this works, be careful whenever manipulating the
- * filters list! (always put things in the list *before* giving
- * them to libdbus, etc.)
- */
-#ifdef DBUS_PYTHON_DISABLE_CHECKS
- callable = (PyObject *)user_data;
-#else
- size = PyList_GET_SIZE(conn_obj->filters);
- for (i = 0; i < size; i++) {
- callable = PyList_GET_ITEM(conn_obj->filters, i);
- if (callable == user_data) {
- Py_INCREF(callable);
- }
- else {
- callable = NULL;
- }
- }
-
- if (!callable) {
- DBG("... filter %p has vanished from ->filters, so not calling it",
- user_data);
- ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- goto out;
- }
-#endif
-
- ret = Connection_HandleMessage(conn_obj, msg_obj, callable);
-out:
- Py_XDECREF(msg_obj);
- Py_XDECREF(conn_obj);
- Py_XDECREF(callable);
- PyGILState_Release(gil);
- return ret;
-}
-
/* D-Bus Connection user data slot, containing an owned reference to either
* the Connection, or a weakref to the Connection.
*/
@@ -240,12 +42,12 @@ static dbus_int32_t _connection_python_slot;
/* Return a borrowed reference to the DBusConnection which underlies this
* Connection. */
-static DBusConnection *
-Connection_BorrowDBusConnection(PyObject *self)
+DBusConnection *
+DBusPyConnection_BorrowDBusConnection(PyObject *self)
{
DBusConnection *dbc;
- if (!Connection_Check(self)) {
+ if (!DBusPyConnection_Check(self)) {
PyErr_SetString(PyExc_TypeError, "A dbus.Connection is required");
return NULL;
}
@@ -261,8 +63,10 @@ Connection_BorrowDBusConnection(PyObject *self)
/* Internal C API =================================================== */
/* Pass a message through a handler. */
-static DBusHandlerResult
-Connection_HandleMessage(Connection *conn, Message *msg, PyObject *callable)
+DBusHandlerResult
+DBusPyConnection_HandleMessage(Connection *conn,
+ PyObject *msg,
+ PyObject *callable)
{
PyObject *obj = PyObject_CallFunctionObjArgs(callable, conn, msg,
NULL);
@@ -312,10 +116,11 @@ Connection_HandleMessage(Connection *conn, Message *msg, PyObject *callable)
}
/* On KeyError or if unregistration is in progress, return None. */
-static PyObject *
-Connection_GetObjectPathHandlers(Connection *self, PyObject *path)
+PyObject *
+DBusPyConnection_GetObjectPathHandlers(PyObject *self, PyObject *path)
{
- PyObject *callbacks = PyDict_GetItem(self->object_paths, path);
+ PyObject *callbacks = PyDict_GetItem(((Connection *)self)->object_paths,
+ path);
if (!callbacks) {
if (PyErr_ExceptionMatches(PyExc_KeyError)) {
PyErr_Clear();
@@ -331,8 +136,8 @@ Connection_GetObjectPathHandlers(Connection *self, PyObject *path)
*
* Raises AssertionError if the DBusConnection does not have a Connection.
*/
-static PyObject *
-Connection_ExistingFromDBusConnection(DBusConnection *conn)
+PyObject *
+DBusPyConnection_ExistingFromDBusConnection(DBusConnection *conn)
{
PyObject *self, *ref;
@@ -342,7 +147,7 @@ Connection_ExistingFromDBusConnection(DBusConnection *conn)
Py_END_ALLOW_THREADS
if (ref) {
self = PyWeakref_GetObject(ref); /* still a borrowed ref */
- if (self && self != Py_None && Connection_Check(self)) {
+ if (self && self != Py_None && DBusPyConnection_Check(self)) {
Py_INCREF(self);
return self;
}
@@ -360,10 +165,10 @@ Connection_ExistingFromDBusConnection(DBusConnection *conn)
*
* Raises AssertionError if the DBusConnection already has a Connection.
*/
-static PyObject *
-Connection_NewConsumingDBusConnection(PyTypeObject *cls,
- DBusConnection *conn,
- PyObject *mainloop)
+PyObject *
+DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *cls,
+ DBusConnection *conn,
+ PyObject *mainloop)
{
Connection *self = NULL;
PyObject *ref;
@@ -387,7 +192,7 @@ Connection_NewConsumingDBusConnection(PyTypeObject *cls,
ref = NULL;
if (!mainloop || mainloop == Py_None) {
- mainloop = default_main_loop;
+ mainloop = dbus_py_get_default_main_loop();
if (!mainloop || mainloop == Py_None) {
PyErr_SetString(PyExc_ValueError,
"D-Bus connections must be attached to a main "
@@ -396,9 +201,9 @@ Connection_NewConsumingDBusConnection(PyTypeObject *cls,
goto err;
}
}
- /* Make sure there's a ref to the main loop (in case someone changes the
- * default) */
- Py_INCREF(mainloop);
+ else {
+ Py_INCREF(mainloop);
+ }
DBG("Constructing Connection from DBusConnection at %p", conn);
@@ -417,7 +222,7 @@ Connection_NewConsumingDBusConnection(PyTypeObject *cls,
Py_BEGIN_ALLOW_THREADS
ok = dbus_connection_set_data(conn, _connection_python_slot,
(void *)ref,
- (DBusFreeFunction)Glue_TakeGILAndXDecref);
+ (DBusFreeFunction)dbus_py_take_gil_and_xdecref);
Py_END_ALLOW_THREADS
if (!ok) {
@@ -427,7 +232,7 @@ Connection_NewConsumingDBusConnection(PyTypeObject *cls,
self->conn = conn;
- if (!dbus_python_set_up_connection((PyObject *)self, mainloop)) {
+ if (!dbus_py_set_up_connection((PyObject *)self, mainloop)) {
goto err;
}
@@ -476,10 +281,10 @@ Connection_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Py_END_ALLOW_THREADS
if (!conn) {
- DBusException_ConsumeError(&error);
+ DBusPyException_ConsumeError(&error);
return NULL;
}
- self = Connection_NewConsumingDBusConnection(cls, conn, mainloop);
+ self = DBusPyConnection_NewConsumingDBusConnection(cls, conn, mainloop);
return self;
}
@@ -515,9 +320,6 @@ static void Connection_tp_dealloc(Connection *self)
(self->ob_type->tp_free)((PyObject *)self);
}
-/* Connection_tp_methods */
-#include "conn-methods-impl.h"
-
/* Connection type object =========================================== */
static PyTypeObject ConnectionType = {
@@ -550,7 +352,7 @@ static PyTypeObject ConnectionType = {
offsetof(Connection, weaklist), /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
- Connection_tp_methods, /*tp_methods*/
+ DBusPyConnection_tp_methods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
@@ -568,8 +370,6 @@ static PyTypeObject ConnectionType = {
static inline dbus_bool_t
init_conn_types(void)
{
- default_main_loop = NULL;
-
/* Get a slot to store our weakref on DBus Connections */
_connection_python_slot = -1;
if (!dbus_connection_allocate_data_slot(&_connection_python_slot))
diff --git a/_dbus_bindings/dbus_bindings-internal.h b/_dbus_bindings/dbus_bindings-internal.h
new file mode 100644
index 0000000..babd2b3
--- /dev/null
+++ b/_dbus_bindings/dbus_bindings-internal.h
@@ -0,0 +1,113 @@
+/* _dbus_bindings internal API. For use within _dbus_bindings only.
+ *
+ * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef DBUS_BINDINGS_INTERNAL_H
+#define DBUS_BINDINGS_INTERNAL_H
+
+#include <Python.h>
+#define INSIDE_DBUS_BINDINGS
+#include "dbus_bindings.h"
+
+/* no need for extern "C", this is only for internal use */
+
+/* on/off switch for debugging support (see below) */
+#undef USING_DBG
+/* #define USING_DBG */
+
+/* conn.c */
+extern PyTypeObject DBusPyConnectionType;
+#define DBusPyConnection_Check(o) PyObject_TypeCheck(o, &DBusPyConnectionType)
+extern PyObject *DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *,
+ DBusConnection *,
+ PyObject *);
+extern dbus_bool_t dbus_py_init_conn_types(void);
+extern dbus_bool_t dbus_py_insert_conn_types(PyObject *this_module);
+
+/* exceptions.c */
+extern PyObject *DBusPyException;
+extern PyObject *DBusPyException_ConsumeError(DBusError *error);
+
+/* generic */
+extern void dbus_py_take_gil_and_xdecref(PyObject *);
+
+/* message.c */
+extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg);
+extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *);
+
+/* pending-call.c */
+extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *,
+ PyObject *);
+
+/* mainloop.c */
+extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn,
+ PyObject *mainloop);
+extern PyObject *dbus_py_get_default_main_loop(void);
+
+/* validation.c */
+dbus_bool_t dbus_py_validate_bus_name(const char *name,
+ dbus_bool_t may_be_unique,
+ dbus_bool_t may_be_not_unique);
+dbus_bool_t dbus_py_validate_member_name(const char *name);
+dbus_bool_t dbus_py_validate_interface_name(const char *name);
+dbus_bool_t dbus_py_validate_object_path(const char *path);
+#define dbus_py_validate_error_name dbus_py_validate_interface_name
+
+/* debugging support */
+#ifdef USING_DBG
+
+# include <sys/types.h>
+# include <unistd.h>
+
+void _dbus_py_dbg_exc(void);
+void _dbus_py_dbg_dump_message(DBusMessage *);
+
+# define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
+ __VA_ARGS__)
+# define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
+ _dbus_py_dbg_exc();} while (0)
+# define DBG_DUMP_MESSAGE(x) _dbg_dump_message(x)
+
+#else /* !defined(USING_DBG) */
+
+# define DBG(format, ...) do {} while (0)
+# define DBG_EXC(format, ...) do {} while (0)
+# define DBG_DUMP_MESSAGE(x) do {} while(0)
+
+#endif /* !defined(USING_DBG) */
+
+/* General-purpose Python glue */
+
+#define DEFERRED_ADDRESS(ADDR) 0
+
+#if defined(__GNUC__)
+# if __GNUC__ >= 3
+# define UNUSED __attribute__((__unused__))
+# else
+# define UNUSED /*nothing*/
+# endif
+#else
+# define UNUSED /*nothing*/
+#endif
+
+#endif
diff --git a/_dbus_bindings/debug-impl.h b/_dbus_bindings/debug-impl.h
index ae87794..5dbe356 100644
--- a/_dbus_bindings/debug-impl.h
+++ b/_dbus_bindings/debug-impl.h
@@ -22,14 +22,8 @@
*
*/
-#if 0
-# include <sys/types.h>
-# include <unistd.h>
-
-# define USING_DBG
-# define DBG(format, ...) fprintf(stderr, "DEBUG: " format "\n",\
- __VA_ARGS__)
-static void _dbg_exc(void)
+#ifdef USING_DBG
+void _dbus_py_dbg_exc(void)
{
PyObject *c, *v, *t;
/* This is a little mad. We want to get the traceback without
@@ -40,10 +34,27 @@ static void _dbg_exc(void)
PyErr_Print();
PyErr_Restore(c, v, t); /* steals another 3 refs */
}
-# define DBG_EXC(format, ...) do {DBG(format, __VA_ARGS__); \
- _dbg_exc();} while (0)
-#else
-# undef USING_DBG
-# define DBG(format, ...) do {} while (0)
-# define DBG_EXC(format, ...) do {} while (0)
+
+static void
+_dbus_py_dbg_dump_message(DBusMessage *message)
+{
+ const char *s;
+ fprintf(stderr, "DBusMessage at %p\n", message);
+
+ s = dbus_message_get_destination(message);
+ if (!s) s = "(null)";
+ fprintf(stderr, "\tdestination %s\n", s);
+
+ s = dbus_message_get_interface(message);
+ if (!s) s = "(null)";
+ fprintf(stderr, "\tinterface %s\n", s);
+
+ s = dbus_message_get_member(message);
+ if (!s) s = "(null)";
+ fprintf(stderr, "\tmember %s\n", s);
+
+ s = dbus_message_get_path(message);
+ if (!s) s = "(null)";
+ fprintf(stderr, "\tpath %s\n", s);
+}
#endif
diff --git a/_dbus_bindings/exceptions-impl.h b/_dbus_bindings/exceptions-impl.h
index 6ba0c19..690f402 100644
--- a/_dbus_bindings/exceptions-impl.h
+++ b/_dbus_bindings/exceptions-impl.h
@@ -22,47 +22,47 @@
*
*/
-static PyObject *DBusException;
+PyObject *DBusPyException;
PyDoc_STRVAR(DBusException__doc__, "Represents any D-Bus-related error.");
-static inline PyObject *
-DBusException_ConsumeError (DBusError *error)
+PyObject *
+DBusPyException_ConsumeError(DBusError *error)
{
- PyErr_Format (DBusException, "%s: %s", error->name, error->message);
+ PyErr_Format(DBusPyException, "%s: %s", error->name, error->message);
dbus_error_free(error);
return NULL;
}
static inline PyObject *
-DBusException_UnusableMessage (void)
+DBusException_UnusableMessage(void)
{
- PyErr_SetString (DBusException,
- "Message object is uninitialized, or has become unusable "
+ PyErr_SetString(DBusPyException,
+ "Message object is uninitialized, or has become unusable "
"due to error while appending arguments");
return NULL;
}
static inline int
-init_exception_types (void)
+init_exception_types(void)
{
PyObject *docstring;
/* We call it dbus.DBusException because that's where you should import it
from. */
- DBusException = PyErr_NewException("dbus.DBusException", NULL, NULL);
- if (!DBusException) return 0;
+ DBusPyException = PyErr_NewException("dbus.DBusException", NULL, NULL);
+ if (!DBusPyException) return 0;
docstring = PyString_FromString(DBusException__doc__);
if (!docstring) return 0;
- if (PyObject_SetAttrString (DBusException, "__doc__", docstring)) return 0;
- Py_DECREF (docstring);
+ if (PyObject_SetAttrString(DBusPyException, "__doc__", docstring)) return 0;
+ Py_DECREF(docstring);
return 1;
}
static inline int
-insert_exception_types (PyObject *this_module)
+insert_exception_types(PyObject *this_module)
{
- if (PyModule_AddObject(this_module, "DBusException", DBusException) < 0) {
+ if (PyModule_AddObject(this_module, "DBusException", DBusPyException) < 0) {
return 0;
}
return 1;
diff --git a/_dbus_bindings/generic-impl.h b/_dbus_bindings/generic-impl.h
index 6043285..cae3f43 100644
--- a/_dbus_bindings/generic-impl.h
+++ b/_dbus_bindings/generic-impl.h
@@ -23,18 +23,6 @@
*
*/
-#define DEFERRED_ADDRESS(ADDR) 0
-
-#if defined(__GNUC__)
-# if __GNUC__ >= 3
-# define UNUSED __attribute__((__unused__))
-# else
-# define UNUSED /*nothing*/
-# endif
-#else
-# define UNUSED /*nothing*/
-#endif
-
#define DEFINE_CHECK(type) \
static inline int type##_Check (PyObject *o) \
{ \
@@ -78,8 +66,8 @@ Glue_immutable_setattro(PyObject *obj UNUSED,
/* Take the global interpreter lock and decrement the reference count.
* Suitable for calling from a C callback. */
-static void
-Glue_TakeGILAndXDecref(PyObject *obj)
+void
+dbus_py_take_gil_and_xdecref(PyObject *obj)
{
PyGILState_STATE gil = PyGILState_Ensure();
Py_XDECREF(obj);
diff --git a/_dbus_bindings/mainloop-impl.h b/_dbus_bindings/mainloop-impl.h
index 3490934..9242154 100644
--- a/_dbus_bindings/mainloop-impl.h
+++ b/_dbus_bindings/mainloop-impl.h
@@ -147,7 +147,7 @@ Watch_BorrowFromDBusWatch(DBusWatch *watch, PyObject *mainloop)
Py_INCREF(self);
dbus_watch_set_data(watch, self,
- (DBusFreeFunction)Glue_TakeGILAndXDecref);
+ (DBusFreeFunction)dbus_py_take_gil_and_xdecref);
return (PyObject *)self;
}
@@ -303,7 +303,7 @@ Timeout_BorrowFromDBusTimeout(DBusTimeout *timeout, PyObject *mainloop)
Py_INCREF(self);
dbus_timeout_set_data(timeout, self,
- (DBusFreeFunction)Glue_TakeGILAndXDecref);
+ (DBusFreeFunction)dbus_py_take_gil_and_xdecref);
return (PyObject *)self;
}
@@ -450,13 +450,13 @@ check_mainloop_sanity(PyObject *mainloop)
return FALSE;
}
-static dbus_bool_t
-dbus_python_set_up_connection(PyObject *conn, PyObject *mainloop)
+dbus_bool_t
+dbus_py_set_up_connection(PyObject *conn, PyObject *mainloop)
{
if (NativeMainLoop_Check(mainloop)) {
/* Native mainloops are allowed to do arbitrary strange things */
NativeMainLoop *nml = (NativeMainLoop *)mainloop;
- DBusConnection *dbc = Connection_BorrowDBusConnection(conn);
+ DBusConnection *dbc = DBusPyConnection_BorrowDBusConnection(conn);
if (!dbc) {
return FALSE;
@@ -471,6 +471,17 @@ dbus_python_set_up_connection(PyObject *conn, PyObject *mainloop)
/* The main loop if none is passed to the constructor */
static PyObject *default_main_loop;
+/* Return a new reference to the default main loop */
+PyObject *
+dbus_py_get_default_main_loop(void)
+{
+ if (!default_main_loop) {
+ Py_RETURN_NONE;
+ }
+ Py_INCREF(default_main_loop);
+ return default_main_loop;
+}
+
/* Python API ======================================================= */
PyDoc_STRVAR(get_default_main_loop__doc__,
@@ -485,11 +496,7 @@ static PyObject *
get_default_main_loop(PyObject *always_null UNUSED,
PyObject *no_args UNUSED)
{
- if (!default_main_loop) {
- Py_RETURN_NONE;
- }
- Py_INCREF(default_main_loop);
- return default_main_loop;
+ return dbus_py_get_default_main_loop();
}
PyDoc_STRVAR(set_default_main_loop__doc__,
@@ -531,11 +538,11 @@ set_default_main_loop(PyObject *always_null UNUSED,
/* C API ============================================================ */
-static PyObject *
-NativeMainLoop_New4(dbus_bool_t (*conn_cb)(DBusConnection *, void *),
- dbus_bool_t (*server_cb)(DBusServer *, void *),
- void (*free_cb)(void *),
- void *data)
+PyObject *
+DBusPyNativeMainLoop_New4(dbus_bool_t (*conn_cb)(DBusConnection *, void *),
+ dbus_bool_t (*server_cb)(DBusServer *, void *),
+ void (*free_cb)(void *),
+ void *data)
{
NativeMainLoop *self = PyObject_New(NativeMainLoop, &NativeMainLoopType);
if (self) {
@@ -563,6 +570,8 @@ noop_main_loop_cb(void *conn_or_server UNUSED, void *data UNUSED)
static inline int
init_mainloop (void)
{
+ default_main_loop = NULL;
+
if (PyType_Ready (&WatchType) < 0) return 0;
if (PyType_Ready (&TimeoutType) < 0) return 0;
if (PyType_Ready (&NativeMainLoopType) < 0) return 0;
@@ -577,10 +586,10 @@ init_mainloop (void)
static inline int
insert_mainloop_types (PyObject *this_module)
{
- PyObject *null_main_loop = NativeMainLoop_New4(noop_conn_cb,
- noop_server_cb,
- NULL,
- NULL);
+ PyObject *null_main_loop = DBusPyNativeMainLoop_New4(noop_conn_cb,
+ noop_server_cb,
+ NULL,
+ NULL);
if (!null_main_loop) return 0;
if (PyModule_AddObject (this_module, "Watch",
diff --git a/_dbus_bindings/message-impl.h b/_dbus_bindings/message-impl.h
index c53dc75..e0189a7 100644
--- a/_dbus_bindings/message-impl.h
+++ b/_dbus_bindings/message-impl.h
@@ -23,33 +23,6 @@
*
*/
-#ifdef USING_DBG
-static void _dbg_dump_message(DBusMessage *message)
-{
- const char *s;
- fprintf(stderr, "DBusMessage at %p\n", message);
-
- s = dbus_message_get_destination(message);
- if (!s) s = "(null)";
- fprintf(stderr, "\tdestination %s\n", s);
-
- s = dbus_message_get_interface(message);
- if (!s) s = "(null)";
- fprintf(stderr, "\tinterface %s\n", s);
-
- s = dbus_message_get_member(message);
- if (!s) s = "(null)";
- fprintf(stderr, "\tmember %s\n", s);
-
- s = dbus_message_get_path(message);
- if (!s) s = "(null)";
- fprintf(stderr, "\tpath %s\n", s);
-}
-# define DBG_DUMP_MESSAGE(x) _dbg_dump_message(x)
-#else
-# define DBG_DUMP_MESSAGE(x) do {} while(0)
-#endif
-
static PyTypeObject MessageType, SignalMessageType, ErrorMessageType;
static PyTypeObject MethodReturnMessageType, MethodCallMessageType;
@@ -102,10 +75,10 @@ MethodCallMessage_tp_init (Message *self, PyObject *args, PyObject *kwargs)
&method)) {
return -1;
}
- if (destination && !_validate_bus_name(destination, 1, 1)) return -1;
- if (!_validate_object_path(path)) return -1;
- if (interface && !_validate_interface_name(interface)) return -1;
- if (!_validate_member_name(method)) return -1;
+ if (destination && !dbus_py_validate_bus_name(destination, 1, 1)) return -1;
+ if (!dbus_py_validate_object_path(path)) return -1;
+ if (interface && !dbus_py_validate_interface_name(interface)) return -1;
+ if (!dbus_py_validate_member_name(method)) return -1;
if (self->msg) {
dbus_message_unref (self->msg);
self->msg = NULL;
@@ -155,9 +128,9 @@ SignalMessage_tp_init (Message *self, PyObject *args, PyObject *kwargs)
&path, &interface, &name)) {
return -1;
}
- if (!_validate_object_path(path)) return -1;
- if (!_validate_interface_name(interface)) return -1;
- if (!_validate_member_name(name)) return -1;
+ if (!dbus_py_validate_object_path(path)) return -1;
+ if (!dbus_py_validate_interface_name(interface)) return -1;
+ if (!dbus_py_validate_member_name(name)) return -1;
if (self->msg) {
dbus_message_unref (self->msg);
self->msg = NULL;
@@ -185,7 +158,7 @@ ErrorMessage_tp_init (Message *self, PyObject *args, PyObject *kwargs)
&error_message)) {
return -1;
}
- if (!_validate_error_name(error_name)) return -1;
+ if (!dbus_py_validate_error_name(error_name)) return -1;
if (self->msg) {
dbus_message_unref (self->msg);
self->msg = NULL;
@@ -198,8 +171,8 @@ ErrorMessage_tp_init (Message *self, PyObject *args, PyObject *kwargs)
return 0;
}
-static DBusMessage *
-Message_BorrowDBusMessage (PyObject *msg)
+DBusMessage *
+DBusPyMessage_BorrowDBusMessage(PyObject *msg)
{
if (!Message_Check (msg)) {
PyErr_SetString (PyExc_TypeError,
@@ -443,7 +416,7 @@ Message_set_member (Message *self, PyObject *args)
return NULL;
}
if (!self->msg) return DBusException_UnusableMessage();
- if (!_validate_member_name(name)) return NULL;
+ if (!dbus_py_validate_member_name(name)) return NULL;
if (!dbus_message_set_member (self->msg, name)) return PyErr_NoMemory();
Py_RETURN_NONE;
}
@@ -606,7 +579,7 @@ Message_set_sender (Message *self, PyObject *args)
return NULL;
}
if (!self->msg) return DBusException_UnusableMessage();
- if (!_validate_bus_name(name, 1, 0)) return NULL;
+ if (!dbus_py_validate_bus_name(name, 1, 0)) return NULL;
if (!dbus_message_set_sender (self->msg, name)) return PyErr_NoMemory();
Py_RETURN_NONE;
}
@@ -652,7 +625,7 @@ Message_set_destination (Message *self, PyObject *args)
return NULL;
}
if (!self->msg) return DBusException_UnusableMessage();
- if (!_validate_bus_name(name, 1, 1)) return NULL;
+ if (!dbus_py_validate_bus_name(name, 1, 1)) return NULL;
if (!dbus_message_set_destination (self->msg, name)) return PyErr_NoMemory();
Py_RETURN_NONE;
}
@@ -697,7 +670,7 @@ Message_set_interface (Message *self, PyObject *args)
return NULL;
}
if (!self->msg) return DBusException_UnusableMessage();
- if (!_validate_interface_name(name)) return NULL;
+ if (!dbus_py_validate_interface_name(name)) return NULL;
if (!dbus_message_set_interface (self->msg, name)) return PyErr_NoMemory();
Py_RETURN_NONE;
}
@@ -728,7 +701,7 @@ Message_set_error_name(Message *self, PyObject *args)
return NULL;
}
if (!self->msg) return DBusException_UnusableMessage();
- if (!_validate_error_name(name)) return NULL;
+ if (!dbus_py_validate_error_name(name)) return NULL;
if (!dbus_message_set_error_name(self->msg, name)) return PyErr_NoMemory();
Py_RETURN_NONE;
}
diff --git a/_dbus_bindings/module.c b/_dbus_bindings/module.c
index 8ab937d..a29fd49 100644
--- a/_dbus_bindings/module.c
+++ b/_dbus_bindings/module.c
@@ -25,8 +25,7 @@
#include <Python.h>
#include <structmember.h>
-#define INSIDE_DBUS_BINDINGS
-#include "dbus_bindings.h"
+#include "dbus_bindings-internal.h"
PyDoc_STRVAR(module_doc,
"Low-level Python bindings for libdbus. Don't use this module directly -\n"
@@ -50,7 +49,6 @@ PyDoc_STRVAR(module_doc,
#include "message-impl.h" /* Message and subclasses */
#include "pending-call-impl.h" /* PendingCall */
#include "mainloop-impl.h" /* NativeMainLoop */
-#include "conn-impl.h" /* Connection */
#include "bus-impl.h" /* Bus */
static PyMethodDef module_functions[] = {
@@ -90,7 +88,7 @@ init_dbus_bindings(void)
if (!init_message_types()) return;
if (!init_pending_call()) return;
if (!init_mainloop()) return;
- if (!init_conn_types()) return;
+ if (!dbus_py_init_conn_types()) return;
if (!init_bus_types()) return;
this_module = Py_InitModule3("_dbus_bindings", module_functions, module_doc);
@@ -106,7 +104,7 @@ init_dbus_bindings(void)
if (!insert_message_types(this_module)) return;
if (!insert_pending_call(this_module)) return;
if (!insert_mainloop_types(this_module)) return;
- if (!insert_conn_types(this_module)) return;
+ if (!dbus_py_insert_conn_types(this_module)) return;
if (!insert_bus_types(this_module)) return;
#define ADD_CONST_VAL(x, v) \
diff --git a/_dbus_bindings/pending-call-impl.h b/_dbus_bindings/pending-call-impl.h
index 8fd4fe6..25965d4 100644
--- a/_dbus_bindings/pending-call-impl.h
+++ b/_dbus_bindings/pending-call-impl.h
@@ -139,8 +139,9 @@ PendingCall_get_completed(PendingCall *self, PyObject *unused UNUSED)
}
/* Steals the reference to the pending call. */
-static PyObject *
-PendingCall_ConsumeDBusPendingCall (DBusPendingCall *pc, PyObject *callable)
+PyObject *
+DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *pc,
+ PyObject *callable)
{
dbus_bool_t ret;
PyObject *list = PyList_New(1);
@@ -166,7 +167,7 @@ PendingCall_ConsumeDBusPendingCall (DBusPendingCall *pc, PyObject *callable)
Py_BEGIN_ALLOW_THREADS
ret = dbus_pending_call_set_notify(pc,
(DBusPendingCallNotifyFunction)_pending_call_notify_function,
- (void *)list, (DBusFreeFunction)Glue_TakeGILAndXDecref);
+ (void *)list, (DBusFreeFunction)dbus_py_take_gil_and_xdecref);
Py_END_ALLOW_THREADS
if (!ret) {
diff --git a/_dbus_bindings/types-impl.h b/_dbus_bindings/types-impl.h
index 67e5f48..e4bb567 100644
--- a/_dbus_bindings/types-impl.h
+++ b/_dbus_bindings/types-impl.h
@@ -876,7 +876,7 @@ ObjectPath_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|l:__new__", argnames,
&str, &variantness)) return NULL;
- if (!_validate_object_path(str)) {
+ if (!dbus_py_validate_object_path(str)) {
return NULL;
}
return (DBusPythonStringType.tp_new)(cls, args, kwargs);
diff --git a/_dbus_bindings/validation-impl.h b/_dbus_bindings/validation-impl.h
index e721a54..2e776f7 100644
--- a/_dbus_bindings/validation-impl.h
+++ b/_dbus_bindings/validation-impl.h
@@ -22,9 +22,10 @@
*
*/
-static dbus_bool_t _validate_bus_name(const char *name,
- dbus_bool_t may_be_unique,
- dbus_bool_t may_be_not_unique)
+dbus_bool_t
+dbus_py_validate_bus_name(const char *name,
+ dbus_bool_t may_be_unique,
+ dbus_bool_t may_be_not_unique)
{
dbus_bool_t dot = FALSE;
dbus_bool_t unique;
@@ -136,13 +137,14 @@ validate_bus_name(PyObject *unused UNUSED, PyObject *args, PyObject *kwargs)
&allow_well_known)) {
return NULL;
}
- if (!_validate_bus_name(name, !!allow_unique, !!allow_well_known)) {
+ if (!dbus_py_validate_bus_name(name, !!allow_unique, !!allow_well_known)) {
return NULL;
}
Py_RETURN_NONE;
}
-static dbus_bool_t _validate_member_name(const char *name)
+dbus_bool_t
+dbus_py_validate_member_name(const char *name)
{
const char *ptr;
@@ -191,13 +193,14 @@ validate_member_name(PyObject *unused UNUSED, PyObject *args)
if (!PyArg_ParseTuple(args, "s:validate_member_name", &name)) {
return NULL;
}
- if (!_validate_member_name(name)) {
+ if (!dbus_py_validate_member_name(name)) {
return NULL;
}
Py_RETURN_NONE;
}
-static dbus_bool_t _validate_interface_name(const char *name)
+dbus_bool_t
+dbus_py_validate_interface_name(const char *name)
{
dbus_bool_t dot = FALSE;
char last;
@@ -283,18 +286,15 @@ validate_interface_name(PyObject *unused UNUSED, PyObject *args)
if (!PyArg_ParseTuple(args, "s:validate_interface_name", &name)) {
return NULL;
}
- if (!_validate_interface_name(name)) {
+ if (!dbus_py_validate_interface_name(name)) {
return NULL;
}
Py_RETURN_NONE;
}
-static inline dbus_bool_t _validate_error_name(const char *name)
-{
- return _validate_interface_name(name);
-}
-static dbus_bool_t _validate_object_path(const char *path)
+dbus_bool_t
+dbus_py_validate_object_path(const char *path)
{
const char *ptr;
@@ -343,7 +343,7 @@ validate_object_path(PyObject *unused UNUSED, PyObject *args)
if (!PyArg_ParseTuple(args, "s:validate_object_path", &name)) {
return NULL;
}
- if (!_validate_object_path(name)) {
+ if (!dbus_py_validate_object_path(name)) {
return NULL;
}
Py_RETURN_NONE;
diff --git a/include/dbus_bindings.h b/include/dbus_bindings.h
index 6d80cec..bd1ee55 100644
--- a/include/dbus_bindings.h
+++ b/include/dbus_bindings.h
@@ -25,6 +25,7 @@
#ifndef DBUS_BINDINGS_H
#define DBUS_BINDINGS_H
+#include <Python.h>
#define DBUS_API_SUBJECT_TO_CHANGE 1
#include <dbus/dbus.h>
@@ -34,8 +35,10 @@ DBUS_BEGIN_DECLS
#ifdef INSIDE_DBUS_BINDINGS
-static DBusConnection *Connection_BorrowDBusConnection(PyObject *);
-static PyObject *NativeMainLoop_New4(dbus_bool_t (*)(DBusConnection *, void *),
+#define Connection_BorrowDBusConnection DBusPyConnection_BorrowDBusConnection
+#define NativeMainLoop_New4 DBusPyNativeMainLoop_New4
+extern DBusConnection *DBusPyConnection_BorrowDBusConnection(PyObject *);
+extern PyObject *DBusPyNativeMainLoop_New4(dbus_bool_t (*)(DBusConnection *, void *),
dbus_bool_t (*)(DBusServer *, void *),
void (*)(void *),
void *);
diff --git a/setup.py b/setup.py
index ceddc70..8c9b0d4 100644
--- a/setup.py
+++ b/setup.py
@@ -155,7 +155,11 @@ setup(
"dbus/mainloop/glib",
],
ext_modules=[
- Extension("_dbus_bindings", ["_dbus_bindings/module.c"],
+ Extension("_dbus_bindings", [
+ "_dbus_bindings/module.c",
+ "_dbus_bindings/conn.c",
+ "_dbus_bindings/conn-methods.c",
+ ],
include_dirs=dbus_includes,
library_dirs=dbus_libs,
libraries=["dbus-1"],