Subversion Repositories HomeAutomation

Rev

Rev 748 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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