exec_AL.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Model author: Yentl Van Tendeloo
  4. Model name: Logging
  5. Model description:
  6. For testing: send 2 values and wait for the sum
  7. """
  8. from sccd.runtime.statecharts_core import *
  9. # package "Logging"
  10. class Exec_AL(RuntimeClassBase):
  11. def __init__(self, controller):
  12. RuntimeClassBase.__init__(self, controller)
  13. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  14. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  15. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  16. self.semantics.priority = StatechartSemantics.SourceParent
  17. self.semantics.concurrency = StatechartSemantics.Single
  18. # build Statechart structure
  19. self.build_statechart_structure()
  20. # call user defined constructor
  21. Exec_AL.user_defined_constructor(self)
  22. def user_defined_constructor(self):
  23. pass
  24. def user_defined_destructor(self):
  25. pass
  26. # builds Statechart structure
  27. def build_statechart_structure(self):
  28. # state <root>
  29. self.states[""] = State(0, "", self)
  30. # state /init
  31. self.states["/init"] = State(1, "/init", self)
  32. self.states["/init"].setEnter(self._init_enter)
  33. self.states["/init"].setExit(self._init_exit)
  34. # state /finished
  35. self.states["/finished"] = State(2, "/finished", self)
  36. # add children
  37. self.states[""].addChild(self.states["/init"])
  38. self.states[""].addChild(self.states["/finished"])
  39. self.states[""].fixTree()
  40. self.states[""].default_state = self.states["/init"]
  41. # transition /init
  42. _init_0 = Transition(self, self.states["/init"], [self.states["/init"]])
  43. _init_0.setAction(self._init_0_exec)
  44. _init_0.setTrigger(Event("input", "inp"))
  45. _init_0.setGuard(self._init_0_guard)
  46. self.states["/init"].addTransition(_init_0)
  47. _init_1 = Transition(self, self.states["/init"], [self.states["/init"]])
  48. _init_1.setAction(self._init_1_exec)
  49. _init_1.setTrigger(Event("input", "inp"))
  50. _init_1.setGuard(self._init_1_guard)
  51. self.states["/init"].addTransition(_init_1)
  52. _init_2 = Transition(self, self.states["/init"], [self.states["/finished"]])
  53. _init_2.setTrigger(Event("_0after"))
  54. self.states["/init"].addTransition(_init_2)
  55. _init_3 = Transition(self, self.states["/init"], [self.states["/finished"]])
  56. _init_3.setAction(self._init_3_exec)
  57. _init_3.setTrigger(Event("terminate", "inp"))
  58. self.states["/init"].addTransition(_init_3)
  59. def _init_enter(self):
  60. self.addTimer(0, 30)
  61. def _init_exit(self):
  62. self.removeTimer(0)
  63. def _init_0_exec(self, parameters):
  64. value = parameters[0]
  65. self.big_step.outputEvent(Event("output", "outp", [2]))
  66. self.big_step.outputEvent(Event("output", "outp", [3]))
  67. print("RAISE EVENT ON PORT")
  68. def _init_0_guard(self, parameters):
  69. value = parameters[0]
  70. return value == 'init'
  71. def _init_1_exec(self, parameters):
  72. value = parameters[0]
  73. print("Got: " + str(value))
  74. def _init_1_guard(self, parameters):
  75. value = parameters[0]
  76. return type(value) == int
  77. def _init_3_exec(self, parameters):
  78. print("Got terminate")
  79. def initializeStatechart(self):
  80. # enter default state
  81. self.default_targets = self.states["/init"].getEffectiveTargetStates()
  82. RuntimeClassBase.initializeStatechart(self)
  83. class ObjectManager(ObjectManagerBase):
  84. def __init__(self, controller):
  85. ObjectManagerBase.__init__(self, controller)
  86. def instantiate(self, class_name, construct_params):
  87. if class_name == "Exec_AL":
  88. instance = Exec_AL(self.controller)
  89. instance.associations = {}
  90. else:
  91. raise Exception("Cannot instantiate class " + class_name)
  92. return instance
  93. class Controller(ThreadsControllerBase):
  94. def __init__(self, keep_running = None, behind_schedule_callback = None):
  95. if keep_running == None: keep_running = True
  96. if behind_schedule_callback == None: behind_schedule_callback = None
  97. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  98. self.addInputPort("inp")
  99. self.addOutputPort("outp")
  100. self.object_manager.createInstance("Exec_AL", [])