kuuko pushed a commit to branch master.
commit 79022bf27b101e106dc0c2e9935ae725ef299bcb
Author: Kai Huuhko <[email protected]>
Date: Sun Apr 7 17:40:21 2013 +0300
Convert dbus_mainloop C code to Cython.
---
efl/dbus_mainloop/dbus_mainloop.pxd | 27 ++++++++++++++++++
efl/dbus_mainloop/dbus_mainloop.pyx | 57 +++++++++++++++++++++++++++++++++++++
setup.py | 5 ++--
3 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/efl/dbus_mainloop/dbus_mainloop.pxd
b/efl/dbus_mainloop/dbus_mainloop.pxd
new file mode 100644
index 0000000..3a363a5
--- /dev/null
+++ b/efl/dbus_mainloop/dbus_mainloop.pxd
@@ -0,0 +1,27 @@
+from cpython cimport PyObject
+from libc.string cimport const_char
+
+cdef extern from "dbus/dbus.h":
+ ctypedef int dbus_bool_t
+ ctypedef struct DBusConnection
+ ctypedef struct DBusServer
+
+cdef extern from "dbus/dbus-python.h":
+ ctypedef dbus_bool_t (*_dbus_py_conn_setup_func)(DBusConnection *, void *)
+ ctypedef dbus_bool_t (*_dbus_py_srv_setup_func)(DBusServer *, void *)
+ ctypedef void (*_dbus_py_free_func)(void *)
+ PyObject *DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func conn_func,
_dbus_py_srv_setup_func srv_func, _dbus_py_free_func free_func, void *)
+ int import_dbus_bindings(const_char *this_module_name)
+
+cdef extern from "Ecore.h":
+ int ecore_init()
+ void ecore_shutdown()
+
+cdef extern from "e_dbus.h":
+ ctypedef struct E_DBus_Connection
+
+ int e_dbus_init()
+ int e_dbus_shutdown()
+ E_DBus_Connection *e_dbus_connection_setup(DBusConnection *conn)
+ void e_dbus_connection_close(E_DBus_Connection *conn)
+
diff --git a/efl/dbus_mainloop/dbus_mainloop.pyx
b/efl/dbus_mainloop/dbus_mainloop.pyx
new file mode 100644
index 0000000..dfd18df
--- /dev/null
+++ b/efl/dbus_mainloop/dbus_mainloop.pyx
@@ -0,0 +1,57 @@
+# Copyright (C) 2007-2013 various contributors (see AUTHORS)
+#
+# This file is part of Python-EFL.
+#
+# Python-EFL is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# Python-EFL 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+D-Bus python integration for Ecore main loop.
+
+"""
+
+import dbus
+import dbus.mainloop
+import atexit
+
+cdef dbus_bool_t dbus_py_ecore_set_up_conn(DBusConnection *conn, void *data)
with gil:
+ e_dbus_connection_setup(conn)
+ return True
+
+cdef object dbus_ecore_native_mainloop():
+ return <object>DBusPyNativeMainLoop_New4(dbus_py_ecore_set_up_conn,
+ NULL, NULL, NULL)
+
+def DBusEcoreMainLoop(set_as_default = None):
+ """Returns a NativeMainLoop to attach the Ecore main loop to D-Bus
+ from within Python."""
+
+ ml = dbus_ecore_native_mainloop()
+
+ if ml is not None and set_as_default:
+ dbus.set_default_main_loop(ml)
+
+ return ml
+
+def module_cleanup():
+ e_dbus_shutdown()
+ ecore_shutdown()
+
+if import_dbus_bindings("efl.dbus_mainloop") < 0:
+ raise ImportError("failed to import D-Bus bindings")
+
+ecore_init()
+e_dbus_init()
+
+atexit.register(module_cleanup)
diff --git a/setup.py b/setup.py
index 9202d63..07b9769 100755
--- a/setup.py
+++ b/setup.py
@@ -123,10 +123,11 @@ else:
# dbus mainloop integration
dbus_cflags, dbus_libs = pkg_config('DBus', 'dbus-python', "0.83.0")
dbus_ml_ext = Extension("efl.dbus_mainloop",
- ["efl/dbus_mainloop/module.c",
+ ["efl/dbus_mainloop/dbus_mainloop.pyx",
"efl/dbus_mainloop/e_dbus.c"],
extra_compile_args = dbus_cflags + ecore_cflags,
extra_link_args = dbus_libs + ecore_libs)
+ modules.append(dbus_ml_ext)
# Elementary
elm_exts = [
@@ -228,5 +229,5 @@ if __name__ == "__main__":
#"builder": (None, "coverage"),
},
},
- ext_modules = cythonize(modules, include_path=["include"]) +
[dbus_ml_ext],
+ ext_modules = cythonize(modules, include_path=["include"]),
)
--
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html