summaryrefslogtreecommitdiff
path: root/efl/dbus_mainloop/dbus_mainloop.pyx
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/dbus_mainloop.pyx
parent89ec2edd8830986219952c874fe44cb8fe89824a (diff)
Convert dbus_mainloop C code to Cython.
Diffstat (limited to 'efl/dbus_mainloop/dbus_mainloop.pyx')
-rw-r--r--efl/dbus_mainloop/dbus_mainloop.pyx57
1 files changed, 57 insertions, 0 deletions
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)