aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-05-17 14:56:37 +0200
committerMattias Andrée <maandree@operamail.com>2015-05-17 14:56:37 +0200
commit25bc2d11234f353858da5259d8c14627c677a8bc (patch)
treef098974e1771aa62b8d330268b15fa5bf184df4c
parentupdate dist (diff)
downloadpython-bus-25bc2d11234f353858da5259d8c14627c677a8bc.tar.gz
python-bus-25bc2d11234f353858da5259d8c14627c677a8bc.tar.bz2
python-bus-25bc2d11234f353858da5259d8c14627c677a8bc.tar.xz
update poll
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/bus.py18
-rw-r--r--src/native_bus.pyx38
2 files changed, 26 insertions, 30 deletions
diff --git a/src/bus.py b/src/bus.py
index ad7d3a5..dcc6e80 100644
--- a/src/bus.py
+++ b/src/bus.py
@@ -184,7 +184,7 @@ class Bus:
raise self.__oserror()
- def poll_start(self, flags : int = 0):
+ def poll_start(self):
'''
Announce that the thread is listening on the bus.
This is required so the will does not miss any
@@ -192,13 +192,9 @@ class Bus:
not calling this function will cause the bus the
misbehave, is `Bus.poll` is written to expect
this function to have been called.
-
- @param flags:int `Bus.NOWAIT` if the bus should fail with `os.errno.EAGAIN`
- if there isn't already a message available on the bus when
- `Bus.poll` is called
'''
from native_bus import bus_poll_start_wrapped
- (r, e) = bus_poll_start_wrapped(self.bus, flags)
+ (r, e) = bus_poll_start_wrapped(self.bus)
if r == -1:
raise self.__oserror(e)
@@ -215,7 +211,7 @@ class Bus:
raise self.__oserror(e)
- def poll(self) -> bytes:
+ def poll(self, flags : int = 0) -> bytes:
'''
Wait for a message to be broadcasted on the bus.
The caller should make a copy of the received message,
@@ -224,11 +220,13 @@ class Bus:
started, the caller of this function should then
either call `Bus.poll` again or `Bus.poll_stop`.
- @return :bytes The received message
- NB! The received message will not be decoded from UTF-8
+ @param flags:int `Bus.NOWAIT` if the bus should fail with `os.errno.EAGAIN`
+ if there isn't already a message available on the bus
+ @return :bytes The received message
+ NB! The received message will not be decoded from UTF-8
'''
from native_bus import bus_poll_wrapped
- (message, e) = bus_poll_wrapped(self.bus)
+ (message, e) = bus_poll_wrapped(self.bus, flags)
if message is None:
raise self.__oserror(e)
return message
diff --git a/src/native_bus.pyx b/src/native_bus.pyx
index 7dd0601..15215c8 100644
--- a/src/native_bus.pyx
+++ b/src/native_bus.pyx
@@ -100,7 +100,7 @@ Listen (in a loop, forever) for new message on a bus
@return 0 on success, -1 on error
'''
-cdef extern int bus_poll_start(long, int)
+cdef extern int bus_poll_start(long)
'''
Announce that the thread is listening on the bus.
This is required so the will does not miss any
@@ -109,11 +109,8 @@ not calling this function will cause the bus the
misbehave, is `bus_poll` is written to expect
this function to have been called.
-@param bus Bus information
-@param flags `BUS_NOWAIT` if the bus should fail and set `errno` to
- `EAGAIN` if there isn't already a message available on
- the bus when `bus_poll` is called
-@return 0 on success, -1 on error
+@param bus Bus information
+@return 0 on success, -1 on error
'''
cdef extern int bus_poll_stop(long)
@@ -126,7 +123,7 @@ to wait indefinitely.
@return 0 on success, -1 on error
'''
-cdef extern const char *bus_poll(long)
+cdef extern const char *bus_poll(long, int)
'''
Wait for a message to be broadcasted on the bus.
The caller should make a copy of the received message,
@@ -135,8 +132,10 @@ separate thread. When the new thread has started be
started, the caller of this function should then
either call `bus_poll` again or `bus_poll_stop`.
-@param bus Bus information
-@return The received message, `NULL` on error
+@param bus Bus information
+@param flags `BUS_NOWAIT` if the bus should fail and set `errno` to
+ `EAGAIN` if there isn't already a message available on the bus
+@return The received message, `NULL` on error
'''
cdef extern int bus_chown(const char *, uid_t, gid_t)
@@ -323,7 +322,7 @@ def bus_read_wrapped(bus : int, callback : callable, user_data) -> tuple:
return (r, e)
-def bus_poll_start_wrapped(bus : int, flags : int) -> tuple:
+def bus_poll_start_wrapped(bus : int) -> tuple:
'''
Announce that the thread is listening on the bus.
This is required so the will does not miss any
@@ -333,14 +332,10 @@ def bus_poll_start_wrapped(bus : int, flags : int) -> tuple:
this function to have been called.
@param bus:int Bus information
- @param flags:int `BUS_NOWAIT` if the bus should fail and set `errno` to
- `os.errno.EAGAIN` if there isn't already a message
- available on
- the bus when `bus_poll` is called
@return :int 0 on success, -1 on error
@return :int The value of `errno`
'''
- r = bus_poll_start(<long>bus, <int>flags)
+ r = bus_poll_start(<long>bus)
e = errno
return (r, e)
@@ -360,7 +355,7 @@ def bus_poll_stop_wrapped(bus : int) -> tuple:
return (r, e)
-def bus_poll_wrapped(bus : int) -> tuple:
+def bus_poll_wrapped(bus : int, flags : int) -> tuple:
'''
Wait for a message to be broadcasted on the bus.
The caller should make a copy of the received message,
@@ -370,13 +365,16 @@ def bus_poll_wrapped(bus : int) -> tuple:
either call `bus_poll_wrapped` again or
`bus_poll_stop_wrapped`.
- @param bus::int Bus information
- @return :bytes The received message, `None` on error
- @return :int The value of `errno`
+ @param bus::int Bus information
+ @param flags:int `BUS_NOWAIT` if the bus should fail and set `errno`
+ to `os.errno.EAGAIN` if there isn't already a message
+ available on the bus
+ @return :bytes The received message, `None` on error
+ @return :int The value of `errno`
'''
cdef const char* msg
cdef bytes bs
- msg = bus_poll(<long>bus)
+ msg = bus_poll(<long>bus, <int>flags)
e = errno
if msg is NULL:
return (None, e)