summaryrefslogtreecommitdiff
path: root/efl/dbus_mainloop
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-04-07 17:40:21 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2013-04-07 17:41:10 +0300
commit79022bf27b101e106dc0c2e9935ae725ef299bcb (patch)
tree1f03de050776d7947c8f6dd0523238d8fe907ed0 /efl/dbus_mainloop
parent89ec2edd8830986219952c874fe44cb8fe89824a (diff)
Convert dbus_mainloop C code to Cython.
Diffstat (limited to 'efl/dbus_mainloop')
-rw-r--r--efl/dbus_mainloop/dbus_mainloop.pxd27
-rw-r--r--efl/dbus_mainloop/dbus_mainloop.pyx57
2 files changed, 84 insertions, 0 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 @@
1from cpython cimport PyObject
2from libc.string cimport const_char
3
4cdef extern from "dbus/dbus.h":
5 ctypedef int dbus_bool_t
6 ctypedef struct DBusConnection
7 ctypedef struct DBusServer
8
9cdef extern from "dbus/dbus-python.h":
10 ctypedef dbus_bool_t (*_dbus_py_conn_setup_func)(DBusConnection *, void *)
11 ctypedef dbus_bool_t (*_dbus_py_srv_setup_func)(DBusServer *, void *)
12 ctypedef void (*_dbus_py_free_func)(void *)
13 PyObject *DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func conn_func, _dbus_py_srv_setup_func srv_func, _dbus_py_free_func free_func, void *)
14 int import_dbus_bindings(const_char *this_module_name)
15
16cdef extern from "Ecore.h":
17 int ecore_init()
18 void ecore_shutdown()
19
20cdef extern from "e_dbus.h":
21 ctypedef struct E_DBus_Connection
22
23 int e_dbus_init()
24 int e_dbus_shutdown()
25 E_DBus_Connection *e_dbus_connection_setup(DBusConnection *conn)
26 void e_dbus_connection_close(E_DBus_Connection *conn)
27
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 @@
1# Copyright (C) 2007-2013 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18"""
19
20D-Bus python integration for Ecore main loop.
21
22"""
23
24import dbus
25import dbus.mainloop
26import atexit
27
28cdef dbus_bool_t dbus_py_ecore_set_up_conn(DBusConnection *conn, void *data) with gil:
29 e_dbus_connection_setup(conn)
30 return True
31
32cdef object dbus_ecore_native_mainloop():
33 return <object>DBusPyNativeMainLoop_New4(dbus_py_ecore_set_up_conn,
34 NULL, NULL, NULL)
35
36def DBusEcoreMainLoop(set_as_default = None):
37 """Returns a NativeMainLoop to attach the Ecore main loop to D-Bus
38 from within Python."""
39
40 ml = dbus_ecore_native_mainloop()
41
42 if ml is not None and set_as_default:
43 dbus.set_default_main_loop(ml)
44
45 return ml
46
47def module_cleanup():
48 e_dbus_shutdown()
49 ecore_shutdown()
50
51if import_dbus_bindings("efl.dbus_mainloop") < 0:
52 raise ImportError("failed to import D-Bus bindings")
53
54ecore_init()
55e_dbus_init()
56
57atexit.register(module_cleanup)