From 334f1427233510aa5249e4e2dea4b1e5c76c514f Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 10 Apr 2008 01:18:46 +0200 Subject: * host/proto: - added program io utility. - added Proto.wait. --- host/proto/proto.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'host/proto/proto.py') diff --git a/host/proto/proto.py b/host/proto/proto.py index e6d3ab32..36616d9c 100644 --- a/host/proto/proto.py +++ b/host/proto/proto.py @@ -22,7 +22,7 @@ # # }}} """Proto interface module.""" -import binascii, struct +import binascii, struct, select START = 0 BANG = 1 @@ -68,6 +68,14 @@ class Proto: self.send_head () return not self.send_queue + def wait (self, cond = None): + """Wait forever or until cond () is True.""" + while not (self.sync () and (cond is None or cond ())): + fds = select.select ((self,), (), (), self.timeout)[0] + for i in fds: + assert i is self + i.read () + def register (self, command, fmt, handler): """Register a handler for the specified command and format. The handler will receive decoded arguments.""" -- cgit v1.2.3