changeset 8610:8ef1f63e554c

inotify: server: use a common 'pollable' interface for server & repowatcher Mainly for documentation purposes: it easily explains the role of handle_event and handle_timeout, and why both server & repowatcher implement those methods.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Thu, 21 May 2009 17:09:12 +0900
parents aeaa0bd9dc24
children ba42e3c6e602
files hgext/inotify/server.py
diffstat 1 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/inotify/server.py	Thu May 21 19:26:15 2009 +0900
+++ b/hgext/inotify/server.py	Thu May 21 17:09:12 2009 +0900
@@ -113,8 +113,33 @@
     raise util.Abort(_('cannot watch %s until inotify watch limit is raised')
                      % repo.root)
 
-class repowatcher(object):
+class pollable(object):
+    """
+    Interface to support polling.
+    The file descriptor returned by fileno() is registered to a polling
+    object.
+    Usage:
+        Every tick, check if an event has happened since the last tick:
+        * If yes, call handle_events
+        * If no, call handle_timeout
+    """
     poll_events = select.POLLIN
+    def fileno(self):
+        raise NotImplementedError
+
+    def handle_events(self, events):
+        raise NotImplementedError
+
+    def handle_timeout(self):
+        raise NotImplementedError
+
+    def shutdown(self):
+        raise NotImplementedError
+
+class repowatcher(pollable):
+    """
+    Watches inotify events
+    """
     statuskeys = 'almr!?'
     mask = (
         inotify.IN_ATTRIB |
@@ -540,7 +565,7 @@
                 self.ui.note(_('%s hooking back up with %d bytes readable\n') %
                              (self.event_time(), self.threshold.readable()))
             self.read_events(0)
-            self.master.poll.register(self, select.POLLIN)
+            self.master.poll.register(self, self.poll_events)
             self.registered = True
 
         self.timeout = None
@@ -555,9 +580,10 @@
         """
         return sorted(tuple[0][len(self.wprefix):] for tuple in self.watcher)
 
-class server(object):
-    poll_events = select.POLLIN
-
+class server(pollable):
+    """
+    Listens for client queries on unix socket inotify.sock
+    """
     def __init__(self, ui, repo, repowatcher, timeout):
         self.ui = ui
         self.repo = repo