[PATCH] Add a Connection.get_c_connection() method which returns the DBusConnection pointer

Jan Luebbe jluebbe at lasnet.de
Thu Oct 23 13:17:14 PDT 2008


This method is needed when Python extension modules writen in C or Vala need
access to a connection that has been created from Python. DBus-Python
currently creates all connections as private, so extension modules can't
reuse them. Using the same well-known bus name from native Python and
extension modules at the same time is only possible with the same
connection.
---
 _dbus_bindings/conn-methods.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/_dbus_bindings/conn-methods.c b/_dbus_bindings/conn-methods.c
index 81c4514..42c7d34 100644
--- a/_dbus_bindings/conn-methods.c
+++ b/_dbus_bindings/conn-methods.c
@@ -275,6 +275,18 @@ Connection_get_is_authenticated (Connection *self, PyObject *args UNUSED)
     return PyBool_FromLong(ret);
 }
 
+PyDoc_STRVAR(Connection_get_c_connection__doc__,
+"get_c_connection() -> long\n\n"
+"Return the address of the DBusConnection C struct. This can be use to pass a\n"
+"connection to an external C library.\n");
+static PyObject *
+Connection_get_c_connection (Connection *self, PyObject *args UNUSED)
+{
+    TRACE(self);
+    DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self->conn);
+    return PyLong_FromVoidPtr((void *)self->conn);
+}
+
 PyDoc_STRVAR(Connection_set_exit_on_disconnect__doc__,
 "set_exit_on_disconnect(bool)\n\n"
 "Set whether the C function ``_exit`` will be called when this Connection\n"
@@ -1007,6 +1019,7 @@ struct PyMethodDef DBusPyConnection_tp_methods[] = {
     ENTRY(_require_main_loop, METH_NOARGS),
     ENTRY(close, METH_NOARGS),
     ENTRY(flush, METH_NOARGS),
+    ENTRY(get_c_connection, METH_NOARGS),
     ENTRY(get_is_connected, METH_NOARGS),
     ENTRY(get_is_authenticated, METH_NOARGS),
     ENTRY(set_exit_on_disconnect, METH_VARARGS),
-- 
1.5.6.5



More information about the dbus mailing list