""" Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration) Model author: Yentl Van Tendeloo Model name: Logging Model description: For testing: send 2 values and wait for the sum """ from sccd.runtime.statecharts_core import * # package "Logging" class Exec_AL(RuntimeClassBase): def __init__(self, controller): RuntimeClassBase.__init__(self, controller) self.semantics.big_step_maximality = StatechartSemantics.TakeMany self.semantics.internal_event_lifeline = StatechartSemantics.Queue self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep self.semantics.priority = StatechartSemantics.SourceParent self.semantics.concurrency = StatechartSemantics.Single # build Statechart structure self.build_statechart_structure() # call user defined constructor Exec_AL.user_defined_constructor(self) def user_defined_constructor(self): pass def user_defined_destructor(self): pass # builds Statechart structure def build_statechart_structure(self): # state self.states[""] = State(0, "", self) # state /init self.states["/init"] = State(1, "/init", self) self.states["/init"].setEnter(self._init_enter) self.states["/init"].setExit(self._init_exit) # state /finished self.states["/finished"] = State(2, "/finished", self) # add children self.states[""].addChild(self.states["/init"]) self.states[""].addChild(self.states["/finished"]) self.states[""].fixTree() self.states[""].default_state = self.states["/init"] # transition /init _init_0 = Transition(self, self.states["/init"], [self.states["/init"]]) _init_0.setAction(self._init_0_exec) _init_0.setTrigger(Event("input", "inp")) _init_0.setGuard(self._init_0_guard) self.states["/init"].addTransition(_init_0) _init_1 = Transition(self, self.states["/init"], [self.states["/init"]]) _init_1.setAction(self._init_1_exec) _init_1.setTrigger(Event("input", "inp")) _init_1.setGuard(self._init_1_guard) self.states["/init"].addTransition(_init_1) _init_2 = Transition(self, self.states["/init"], [self.states["/finished"]]) _init_2.setTrigger(Event("_0after")) self.states["/init"].addTransition(_init_2) _init_3 = Transition(self, self.states["/init"], [self.states["/finished"]]) _init_3.setAction(self._init_3_exec) _init_3.setTrigger(Event("terminate", "inp")) self.states["/init"].addTransition(_init_3) def _init_enter(self): self.addTimer(0, 30) def _init_exit(self): self.removeTimer(0) def _init_0_exec(self, parameters): value = parameters[0] self.big_step.outputEvent(Event("output", "outp", [2])) self.big_step.outputEvent(Event("output", "outp", [3])) print("RAISE EVENT ON PORT") def _init_0_guard(self, parameters): value = parameters[0] return value == 'init' def _init_1_exec(self, parameters): value = parameters[0] print("Got: " + str(value)) def _init_1_guard(self, parameters): value = parameters[0] return type(value) == int def _init_3_exec(self, parameters): print("Got terminate") def initializeStatechart(self): # enter default state self.default_targets = self.states["/init"].getEffectiveTargetStates() RuntimeClassBase.initializeStatechart(self) class ObjectManager(ObjectManagerBase): def __init__(self, controller): ObjectManagerBase.__init__(self, controller) def instantiate(self, class_name, construct_params): if class_name == "Exec_AL": instance = Exec_AL(self.controller) instance.associations = {} else: raise Exception("Cannot instantiate class " + class_name) return instance class Controller(ThreadsControllerBase): def __init__(self, keep_running = None, behind_schedule_callback = None): if keep_running == None: keep_running = True if behind_schedule_callback == None: behind_schedule_callback = None ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback) self.addInputPort("inp") self.addOutputPort("outp") self.object_manager.createInstance("Exec_AL", [])