Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

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