Subversion Repositories HomeAutomation

Rev

Rev 748 | Blame | Last modification | View Log | SVN | RSS feed

  1. ###########################################################
  2. #
  3. # The default implementation of the packet handler
  4. #
  5. ###########################################################
  6. from CanPktHandlerBase import CanPktHandlerBase
  7. from CanPkt import CanPkt
  8.  
  9. class SpacePort():
  10.    
  11.     filterSpaces = {}
  12.    
  13.     def __init__ (self, filterSpaces):
  14.         for fs in filterSpaces:
  15.             sName = fs.__module__.split('.')[1] # implies module name is statespace.XXX
  16.             self.filterSpaces[sName] = fs
  17.    
  18.     def runAll(self, args):
  19.         for fs in self.filterSpaces.values():
  20.             relatedSpaces = fs.__RELATED_SPACES__
  21.             fs.run(relatedSpaces, args)
  22.         return True
  23.    
  24.     def run(self, spaceName, args):
  25.         if not self.filterSpaces.has_key(spaceName):
  26.             return False
  27.         else:
  28.             relatedSpaces = self.filterSpaces[spaceName].__RELATED_SPACES__
  29.             self.filtersSpaces[spaceName].run(relatedSpaces, args)
  30.             return True
  31.  
  32. class CanPktHandler1(CanPktHandlerBase):
  33.    
  34.     daemonCfg = None
  35.    
  36.     def __init__ (self, daemonCfg):
  37.         self.daemonCfg = daemonCfg
  38.        
  39.     def input(self, strdata):
  40.         """Make data buffer into CanPkt and do early discard check """
  41.         """Call all filters in chain """
  42.  
  43.         if len(strdata) < 2:
  44.             return
  45.         if strdata[0:3] != 'PKT':
  46.             return
  47.  
  48. #        print strdata
  49.         pkt = CanPkt.stringToCanPkt(self, strdata)
  50. #        print 'incoming: ' + pkt.toString()
  51.  
  52.         for filter in self.daemonCfg.filterChain:
  53.             fObj = self.daemonCfg.filterCfg.filterModules[filter]
  54.             sp = SpacePort(fObj.__ASSOCIATED_SPACES__)
  55.             fObj.filter('', pkt, sp) # FIXME: use if name
  56.  
  57.  
  58.     def output(self, data):
  59.         pass
  60.