Example #1
0
 def addCallable(self, callable):
     """Add a callable to list of callables for this topic node"""
     try:
         id = self.__callables.index(_getWeakRef(callable))
         return self.__callables[id]
     except ValueError:
         wrCall = _getWeakRef(callable, _NodeCallback(self.__notifyDead))
         self.__callables.append(wrCall)
         return wrCall
Example #2
0
 def addCallable(self, callable):
     """Add a callable to list of callables for this topic node"""
     try:
         id = self.__callables.index(_getWeakRef(callable))
         return self.__callables[id]
     except ValueError:
         wrCall = _getWeakRef(callable, _NodeCallback(self.__notifyDead))
         self.__callables.append(wrCall)
         return wrCall
Example #3
0
 def __init__(self):
     self.__callbackDict  = {}
     self.__callbackDictCleanup = 0
     # all child nodes will call our __rootNotifyDead method
     # when one of their registered listeners dies 
     _TopicTreeNode.__init__(self, (ALL_TOPICS,), 
                             _getWeakRef(self.__rootNotifyDead))
Example #4
0
 def hasCallable(self, callable):
     """Return true if callable in this node"""
     try: 
         self.__callables.index(_getWeakRef(callable))
         return True
     except ValueError:
         return False
Example #5
0
 def getTopics(self, listener):
     """Return the list of topics for given listener"""
     weakNodes = self.__callbackDict.get(_getWeakRef(listener), [])
     return [
         weakNode().getPathname() for weakNode in weakNodes
         if weakNode() is not None
     ]
Example #6
0
 def __init__(self):
     self.__callbackDict = {}
     self.__callbackDictCleanup = 0
     # all child nodes will call our __rootNotifyDead method
     # when one of their registered listeners dies
     _TopicTreeNode.__init__(self, (ALL_TOPICS, ),
                             _getWeakRef(self.__rootNotifyDead))
Example #7
0
 def hasCallable(self, callable):
     """Return true if callable in this node"""
     try:
         self.__callables.index(_getWeakRef(callable))
         return True
     except ValueError:
         return False
Example #8
0
 def removeCallable(self, callable):
     """Remove weak callable from our node (and return True). 
     Does nothing if not here (and returns False)."""
     try: 
         self.__callables.remove(_getWeakRef(callable))
         return True
     except ValueError:
         return False
Example #9
0
 def removeCallable(self, callable):
     """Remove weak callable from our node (and return True). 
     Does nothing if not here (and returns False)."""
     try:
         self.__callables.remove(_getWeakRef(callable))
         return True
     except ValueError:
         return False
Example #10
0
 def isSubscribed(self, listener, topic=None):
     """Return true if listener is registered for topic specified. 
     If no topic specified, return true if subscribed to something.
     Use topic=getStrAllTopics() to determine if a listener will receive 
     messages for all topics."""
     weakCB = _getWeakRef(listener)
     if topic is None: 
         return self.__callbackDict.has_key(weakCB)
     else:
         topicPath = _tupleize(topic)
         for weakNode in self.__callbackDict[weakCB]:
             if topicPath == weakNode().getPathname():
                 return True
         return False
Example #11
0
 def isSubscribed(self, listener, topic=None):
     """Return true if listener is registered for topic specified. 
     If no topic specified, return true if subscribed to something.
     Use topic=getStrAllTopics() to determine if a listener will receive 
     messages for all topics."""
     weakCB = _getWeakRef(listener)
     if topic is None:
         return self.__callbackDict.has_key(weakCB)
     else:
         topicPath = _tupleize(topic)
         for weakNode in self.__callbackDict[weakCB]:
             if topicPath == weakNode().getPathname():
                 return True
         return False
Example #12
0
    def unsubscribe(self, listener, topicList):
        """Remove listener from given list of topics. If topicList
        doesn't have any topics for which listener has subscribed,
        nothing happens."""
        weakCB = _getWeakRef(listener)
        if not self.__callbackDict.has_key(weakCB):
            return
        
        cbNodes = self.__callbackDict[weakCB] 
        if topicList is None:
            for weakNode in cbNodes:
                weakNode().removeCallable(listener)
            del self.__callbackDict[weakCB] 
            return

        for weakNode in cbNodes:
            node = weakNode()
            if node is not None and node.getPathname() in topicList:
                success = node.removeCallable(listener)
                assert success == True
                cbNodes.remove(weakNode)
                assert not self.isSubscribed(listener, node.getPathname())
Example #13
0
    def unsubscribe(self, listener, topicList):
        """Remove listener from given list of topics. If topicList
        doesn't have any topics for which listener has subscribed,
        nothing happens."""
        weakCB = _getWeakRef(listener)
        if not self.__callbackDict.has_key(weakCB):
            return

        cbNodes = self.__callbackDict[weakCB]
        if topicList is None:
            for weakNode in cbNodes:
                weakNode().removeCallable(listener)
            del self.__callbackDict[weakCB]
            return

        for weakNode in cbNodes:
            node = weakNode()
            if node is not None and node.getPathname() in topicList:
                success = node.removeCallable(listener)
                assert success == True
                cbNodes.remove(weakNode)
                assert not self.isSubscribed(listener, node.getPathname())
Example #14
0
 def getTopics(self, listener):
     """Return the list of topics for given listener"""
     weakNodes = self.__callbackDict.get(_getWeakRef(listener), [])
     return [weakNode().getPathname() for weakNode in weakNodes 
             if weakNode() is not None]
Example #15
0
 def __init__(self, obj):
     self.objRef = _getWeakRef(obj)
Example #16
0
 def __init__(self, obj):
     self.objRef = _getWeakRef(obj)