|
@@ -0,0 +1,115 @@
|
|
|
|
+"""
|
|
|
|
+Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
|
|
|
|
+
|
|
|
|
+Date: Wed Aug 23 16:04:59 2017
|
|
|
|
+
|
|
|
|
+Model author: Yentl Van Tendeloo
|
|
|
|
+Model name: Logging
|
|
|
|
+Model description:
|
|
|
|
+For testing: I/O Statechart for the Modelverse
|
|
|
|
+"""
|
|
|
|
+
|
|
|
|
+from sccd.runtime.statecharts_core import *
|
|
|
|
+
|
|
|
|
+# package "Logging"
|
|
|
|
+
|
|
|
|
+class Logging(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
|
|
|
|
+ Logging.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 <root>
|
|
|
|
+ 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"))
|
|
|
|
+ self.states["/init"].addTransition(_init_0)
|
|
|
|
+ _init_1 = Transition(self, self.states["/init"], [self.states["/init"]])
|
|
|
|
+ _init_1.setTrigger(Event("_0after"))
|
|
|
|
+ self.states["/init"].addTransition(_init_1)
|
|
|
|
+ _init_2 = Transition(self, self.states["/init"], [self.states["/finished"]])
|
|
|
|
+ _init_2.setTrigger(Event("terminate", "inp"))
|
|
|
|
+ self.states["/init"].addTransition(_init_2)
|
|
|
|
+ _init_3 = Transition(self, self.states["/init"], [self.states["/init"]])
|
|
|
|
+ _init_3.setAction(self._init_3_exec)
|
|
|
|
+ _init_3.setTrigger(Event("raw_inp", "user_inp"))
|
|
|
|
+ self.states["/init"].addTransition(_init_3)
|
|
|
|
+
|
|
|
|
+ def _init_enter(self):
|
|
|
|
+ self.addTimer(0, 10)
|
|
|
|
+
|
|
|
|
+ def _init_exit(self):
|
|
|
|
+ self.removeTimer(0)
|
|
|
|
+
|
|
|
|
+ def _init_0_exec(self, parameters):
|
|
|
|
+ value = parameters[0]
|
|
|
|
+ print(value)
|
|
|
|
+
|
|
|
|
+ def _init_3_exec(self, parameters):
|
|
|
|
+ inp = parameters[0]
|
|
|
|
+ print("Got raw input")
|
|
|
|
+ self.big_step.outputEvent(Event("output", "outp", [inp]))
|
|
|
|
+
|
|
|
|
+ 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 == "Logging":
|
|
|
|
+ instance = Logging(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("user_inp")
|
|
|
|
+ self.addInputPort("inp")
|
|
|
|
+ self.addOutputPort("outp")
|
|
|
|
+ self.object_manager.createInstance("Logging", [])
|