summaryrefslogtreecommitdiffhomepage
path: root/host/mex/mex
diff options
context:
space:
mode:
authorNicolas Schodet2008-04-04 13:03:24 +0200
committerNicolas Schodet2008-04-04 13:03:24 +0200
commita196211836efb555aede4fce4d161e7d327ca719 (patch)
tree472cdf4eeec6596719a49f91111261a6457f40f4 /host/mex/mex
parent7724570ce164859bd7f7fd8ff16b9e7fab17eb58 (diff)
* host/mex:
- added support for asynchronous operations.
Diffstat (limited to 'host/mex/mex')
-rw-r--r--host/mex/mex/node.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/host/mex/mex/node.py b/host/mex/mex/node.py
index aa980c61..c51d7c79 100644
--- a/host/mex/mex/node.py
+++ b/host/mex/mex/node.py
@@ -60,6 +60,30 @@ class Node:
msg = self.recv ()
self.dispatch (msg)
+ def wait_async (self, date = None):
+ """Asynchronous version of wait. This should not be called again
+ until sync return True."""
+ self.async_waited = date
+ synced = self.sync ()
+ assert not synced
+
+ def sync (self):
+ """To be called after read or wait_async. Return True if the waited
+ date is reached or signal the Hub our waiting status."""
+ if self.date == self.async_waited:
+ return True
+ else:
+ idle = Msg (mex.IDLE)
+ if self.async_waited != None:
+ idle.push ('L', self.async_waited)
+ self.send (idle)
+
+ def read (self):
+ """Used for asynchronous operations. Handle incoming data. The sync
+ method should be called after this one returns."""
+ msg = self.recv ()
+ self.dispatch (msg)
+
def send (self, msg):
"""Send a message."""
data = msg.data ()
@@ -101,6 +125,10 @@ class Node:
self.socket.close ()
self.socket = None
+ def fileno (self):
+ """Return socket fileno () for asynchronous operations."""
+ return self.socket.fileno ()
+
def recv (self):
"""Receive one message."""
head = self.socket.recv (calcsize (mex.HEADER_FMT))