aboutsummaryrefslogtreecommitdiffstats
path: root/src/native_bus.pyx
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-23 05:06:08 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-23 05:06:08 +0200
commit69b62ab9e9fbb57f47f9f0bb3cbaab1b6d0f3087 (patch)
treeaec14cec2dcb02354878ab3809d279a140248b8b /src/native_bus.pyx
parentfix some errors (diff)
downloadpython-bus-69b62ab9e9fbb57f47f9f0bb3cbaab1b6d0f3087.tar.gz
python-bus-69b62ab9e9fbb57f47f9f0bb3cbaab1b6d0f3087.tar.bz2
python-bus-69b62ab9e9fbb57f47f9f0bb3cbaab1b6d0f3087.tar.xz
suppress error on exit and fix callback1.0
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/native_bus.pyx')
-rw-r--r--src/native_bus.pyx9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/native_bus.pyx b/src/native_bus.pyx
index 016fa3c..b6f3127 100644
--- a/src/native_bus.pyx
+++ b/src/native_bus.pyx
@@ -200,6 +200,12 @@ def bus_write_wrapped(bus : int, message : str) -> int:
return bus_write(<long>bus, cmessage)
+cdef int bus_callback_wrapper(const char *message, user_data):
+ cdef bytes bs = message
+ callback, user_data = tuple(<object>user_data)
+ return <int>callback(bs, user_data)
+
+
def bus_read_wrapped(bus : int, callback : callable, user_data) -> int:
'''
Listen (in a loop, forever) for new message on a bus
@@ -217,5 +223,6 @@ def bus_read_wrapped(bus : int, callback : callable, user_data) -> int:
-1: an error has occurred
@return 0 on success, -1 on error
'''
- return bus_read(<long>bus, <int (*)(const char *, void *)><void *>callback, <void *>user_data)
+ user = (callback, user_data)
+ return bus_read(<long>bus, <int (*)(const char *, void *)>&bus_callback_wrapper, <void *>user)