@@ -9,25 +9,47 @@ def __init__(self, xml_file : str):
99 self .current_state = ""
1010 self .context = {}
1111
12- def __CheckCondition (self ,conditions ):
12+ def __CheckConditions (self ,conditions ):
1313 all_conditions_satisfied = True
1414 if (conditions != None ):
15- conditions = conditions .conditions
16- for condition in conditions :
15+ _conditions = conditions .conditions
16+ for condition in _conditions :
1717 if condition .expression in self .context :
1818 func = self .context [condition .expression ]
1919 result = None
20- if callable (func ):
21- result = func ()
20+ if callable (func ):
21+ result = func ()
22+ else :
23+ result = func
24+ if str (result ) != condition .result :
25+ all_conditions_satisfied = False
26+ break
2227 else :
23- result = func
24- if str (result ) != condition .result :
25- all_conditions_satisfied = False
26- break
28+ print ("No Found Condition Expression " , condition .expression ," in Context" )
29+ all_conditions_satisfied = False
2730 else :
28- print ("No Precondition " )
31+ print ("No Condition " )
2932 return all_conditions_satisfied
3033
34+ def __ExecActions (self ,actions ):
35+ all_action_executed = True
36+ if (actions != None ):
37+ _actions = actions .actions
38+ for action in _actions :
39+ if action .expression in self .context :
40+ func = self .context [action .expression ]
41+ if callable (func ):
42+ #print("Call ",action.expression)
43+ func ()
44+ else :
45+ func
46+ else :
47+ print ("No Found Action Expression " , action .expression ," in Context" )
48+ all_action_executed = False ;
49+ else :
50+ print ("No Action" )
51+ return all_action_executed
52+
3153 def get_current_state (self ):
3254 return self .current_state
3355
@@ -49,14 +71,16 @@ def InjectEvent(self, event : str):
4971 if event in possible_events :
5072 handled_event = possible_events [event ]
5173 ## Preconditions
52- all_pre_conditions_satisfied = self .__CheckCondition (handled_event .pre_conditions )
74+ all_pre_conditions_satisfied = self .__CheckConditions (handled_event .pre_conditions )
5375 if (all_pre_conditions_satisfied ):
5476 ## Preactions
55- ## Transition
56- print ("Transition " , self .current_state , " ------> " , handled_event .to_state )
57- self .current_state = handled_event .to_state
58- ## Postactions
59- ## Postconditions
77+ all_pre_actions_executed = self .__ExecActions (handled_event .pre_actions )
78+ if (all_pre_actions_executed ):
79+ ## Transition
80+ print ("Transition " , self .current_state , " ------> " , handled_event .to_state )
81+ self .current_state = handled_event .to_state
82+ ## Postactions
83+ ## Postconditions
6084 else :
6185 print ("Not all PreConditions satisfied" )
6286 else :
0 commit comments