1 from operationscore.Behavior import *
2 import util.ComponentRegistry as compReg
3 from logger import main_log
4 import pdb
6 """BehaviorChain is a class which chains together multiple behavior. BehaviorChain is in itself a
7 behavior, and behaves and can be used accordingly. BehaviorChain also supports recursive hooks to
8 be set on its constituent behaviors. ChainedBehaviors should be specified in <Args> as follows:
9
10 <ChainedBehaviors>
11 <Id>behavior1Id</Id>
12 <Id>behavior2Id</Id>
13 </ChainedBehaviors>
14
15 Behaviors may also be appended programmatically via the appendBehavior method.
16
17 Recursive hooks should be specified with Python dict syntax as follows:
18
19 <RecursiveHooks>{'behavior1Id':'hookid'}</RecursiveHooks>
20
21 Behavior Chain manages all recurrences that its constituents propogate. At this point, it does not
22 support recurrences in its hooks."""
23
25 self.feedback = {}
26 self.hooks = self['RecursiveHooks']
27 if self.hooks == None:
28 self.hooks = {}
29
31 response = sensorInputs
32 for behaviorId in self['ChainedBehaviors']:
33 behavior = compReg.getComponent(behaviorId)
34 if behaviorId in self.feedback:
35 recurrence = self.feedback[behaviorId]
36 else:
37 recurrence = []
38 (response,recurrence) = behavior.immediateProcessInput(response,\
39 recurrence)
40
41 if behaviorId in self.hooks:
42 hookBehavior = compReg.getComponent(self.hooks[behaviorId])
43
44 (recurrence, hookRecurrence) = \
45 hookBehavior.immediateProcessInput(recurrence, \
46 [])
47 if hookRecurrence != []:
48 main_log.warn('Hook recurrences are not currently supported.')
49 self.feedback[behaviorId] = recurrence
50 return (response, [])
51
53 bid = compReg.registerComponent(behavior)
54
55 self['ChainedBehaviors'].append(bid)
56