# HG changeset patch # User Nicolas Dumazet # Date 1242893352 -32400 # Node ID 8ef1f63e554c5a5f5fdfc0fd012ad9c9cfaca3ac # Parent aeaa0bd9dc2439a1ed59848c11042ee67bce53e9 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. diff -r aeaa0bd9dc24 -r 8ef1f63e554c hgext/inotify/server.py --- 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