Commits

Ronny Pfannschmidt committed ceb4493

add some more code to the watchers, some tests from socket pass now

Comments (0)

Files changed (1)

     def fork(self, ref=True):
         return fork(self)
 
+    def handle_error(self, *exc_info):
+        pass #XXX:
+
     def run(self):
         gtk.main()
 
 
 
+class watcher(object):
+    @property
+    def active(self):
+        return self.callback is not None
 
-class io(object):
+
+class io(watcher):
     def __init__(self, loop, fd, events):
         self.loop = loop
         self.fd = fd
         self.events = events
         self.callback = None
         self.args = None
+        self.source_id = None
 
     def start(self, callback, *args):
         self.callback = callback
             self.callback(*self.args)
         except:
             self.loop.handle_error(callback, *sys.exc_info())
+        return False
 
     def stop(self):
         self.callback = None
         self.args = None
         #XXX: check this never raises
-        glib.source_remove(self.source_id)
+        if self.source_id is not None:
+            glib.source_remove(self.source_id)
+            self.source_id = None
 
-class timer(object):
+class timer(watcher):
     def __init__(self, loop, after, repeat=0):
         self.loop = loop
         self.after = after
         self.source_id = None
         self.callback = None
         self.args = None
+        self.pending = False
 
+    
     def first_callback(self):
         print 'sleep callback'
         try:
             self.callback(*self.args)
+            return True
         except:
             self.loop.handle_error(callback, *sys.exc_info())
-        return False
+            self.stop()
+            return False
 
     def start(self, callback, *args):
         self.callback = callback
         self.args = args
+        self.pending = True #XXX
 
         self.source_id = glib.timeout_add(
             self.after*1000,
     def stop(self):
         self.callback = None
         self.args = None
+        self.pending = False
         #XXX: check this never raises
-        glib.source_remove(self.source_id)
+        print type(self.source_id), self.source_id
+        if self.source_id is not None:
+            glib.source_remove(self.source_id)
+            self.source_id = None
 
-class callback(object):
+class callback(watcher):
     def __init__(self, loop):
         self.callback = None
         self.args = None
     def stop(self):
         pass
 
-class fork(object):
+class fork(watcher):
     #XXX: noop
     def __init__(self, loop):
         pass
+    def start(self, callback):
+        pass