added bboard removal tracking

This commit is contained in:
Darren Ranalli 2006-05-25 23:19:59 +00:00
parent 346936dbe2
commit 6c57da8086
2 changed files with 27 additions and 17 deletions

View File

@ -19,6 +19,9 @@ class BulletinBoard:
def getEvent(self, postName):
return 'bboard-%s' % postName
def getRemoveEvent(self, postName):
return 'bboard-remove-%s' % postName
def post(self, postName, value=None):
if postName in self._dict:
BulletinBoard.notify.warning('changing %s from %s to %s' % (
@ -35,6 +38,7 @@ class BulletinBoard:
def remove(self, postName):
if postName in self._dict:
del self._dict[postName]
messenger.send(self.getRemoveEvent(postName))
def removeIfEqual(self, postName, value):
# only remove the post if its value is a particular value

View File

@ -1,27 +1,33 @@
from direct.directnotify import DirectNotifyGlobal
from direct.showbase.PythonUtil import Functor
from direct.showbase.PythonUtil import Functor, makeList
from direct.showbase import DirectObject
class BulletinBoardWatcher(DirectObject.DirectObject):
"""This class allows you to wait for a set of posts to be made to the
bulletin board, and give you a notification when all posts have been
made. Values of posts are not examined."""
""" This class allows you to wait for a set of posts to be made to (or
removed from) the bulletin board, and gives you a notification when all
posts have been made. Values of posts are not examined."""
notify = DirectNotifyGlobal.directNotify.newCategory('BulletinBoardWatcher')
def __init__(self, name, postNames, callback):
def __init__(self, name, postNames, callback, removeNames=None):
self.notify.debug('__init__: %s, %s, %s' % (name, postNames, callback))
if removeNames is None:
removeNames = []
self.name = name
if type(postNames) == type(''):
postNames = [postNames]
self.postNames = postNames
self.postNames = makeList(postNames)
self.removeNames = makeList(removeNames)
self.callback = callback
self.waitingOn = {}
for name in postNames:
self.waitingOn = set()
for name in self.postNames:
if not bboard.has(name):
eventName = bboard.getEvent(name)
self.acceptOnce(eventName, Functor(self.handlePost, eventName))
self.waitingOn[eventName] = None
self.checkDone()
self.waitingOn.add(eventName)
self.acceptOnce(eventName, Functor(self._handleEvent, eventName))
for name in self.removeNames:
if bboard.has(name):
eventName = bboard.getRemoveEvent(name)
self.waitingOn.add(eventName)
self.acceptOnce(eventName, Functor(self._handleEvent, eventName))
self._checkDone()
def destroy(self):
self.ignoreAll()
@ -31,13 +37,13 @@ class BulletinBoardWatcher(DirectObject.DirectObject):
def isDone(self):
return len(self.waitingOn) == 0
def checkDone(self):
def _checkDone(self):
if self.isDone():
self.notify.debug('%s: done' % self.name)
self.callback()
def handlePost(self, eventName):
def _handleEvent(self, eventName):
self.notify.debug('%s: handlePost(%s)' % (self.name, eventName))
assert eventName in self.waitingOn
del self.waitingOn[eventName]
self.checkDone()
self.waitingOn.remove(eventName)
self._checkDone()