multiple_raises_parallel.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Fri Jul 28 15:14:50 2017
  4. Model name: multiple-raises-parallel
  5. """
  6. from sccd.runtime.statecharts_core import *
  7. # package "multiple-raises-parallel"
  8. class A(RuntimeClassBase):
  9. def __init__(self, controller):
  10. RuntimeClassBase.__init__(self, controller)
  11. self.semantics.big_step_maximality = StatechartSemantics.TakeOne
  12. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  13. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  14. self.semantics.priority = StatechartSemantics.SourceParent
  15. self.semantics.concurrency = StatechartSemantics.Single
  16. # build Statechart structure
  17. self.build_statechart_structure()
  18. # call user defined constructor
  19. A.user_defined_constructor(self)
  20. def user_defined_constructor(self):
  21. pass
  22. def user_defined_destructor(self):
  23. pass
  24. # builds Statechart structure
  25. def build_statechart_structure(self):
  26. # state <root>
  27. self.states[""] = State(0, "", self)
  28. # state /x
  29. self.states["/x"] = ParallelState(1, "/x", self)
  30. # state /x/x1
  31. self.states["/x/x1"] = State(2, "/x/x1", self)
  32. # state /x/x1/x1
  33. self.states["/x/x1/x1"] = State(3, "/x/x1/x1", self)
  34. # state /x/x1/end
  35. self.states["/x/x1/end"] = State(4, "/x/x1/end", self)
  36. # state /x/x2
  37. self.states["/x/x2"] = State(5, "/x/x2", self)
  38. # state /x/x2/x2
  39. self.states["/x/x2/x2"] = State(6, "/x/x2/x2", self)
  40. # state /x/x2/end
  41. self.states["/x/x2/end"] = State(7, "/x/x2/end", self)
  42. # state /x/x3
  43. self.states["/x/x3"] = State(8, "/x/x3", self)
  44. # state /x/x3/x3
  45. self.states["/x/x3/x3"] = State(9, "/x/x3/x3", self)
  46. # state /x/x3/end
  47. self.states["/x/x3/end"] = State(10, "/x/x3/end", self)
  48. # state /x/receiving
  49. self.states["/x/receiving"] = State(11, "/x/receiving", self)
  50. # state /x/receiving/receiving
  51. self.states["/x/receiving/receiving"] = State(12, "/x/receiving/receiving", self)
  52. # add children
  53. self.states[""].addChild(self.states["/x"])
  54. self.states["/x"].addChild(self.states["/x/x1"])
  55. self.states["/x"].addChild(self.states["/x/x2"])
  56. self.states["/x"].addChild(self.states["/x/x3"])
  57. self.states["/x"].addChild(self.states["/x/receiving"])
  58. self.states["/x/x1"].addChild(self.states["/x/x1/x1"])
  59. self.states["/x/x1"].addChild(self.states["/x/x1/end"])
  60. self.states["/x/x2"].addChild(self.states["/x/x2/x2"])
  61. self.states["/x/x2"].addChild(self.states["/x/x2/end"])
  62. self.states["/x/x3"].addChild(self.states["/x/x3/x3"])
  63. self.states["/x/x3"].addChild(self.states["/x/x3/end"])
  64. self.states["/x/receiving"].addChild(self.states["/x/receiving/receiving"])
  65. self.states[""].fixTree()
  66. self.states[""].default_state = self.states["/x"]
  67. self.states["/x/x1"].default_state = self.states["/x/x1/x1"]
  68. self.states["/x/x2"].default_state = self.states["/x/x2/x2"]
  69. self.states["/x/x3"].default_state = self.states["/x/x3/x3"]
  70. self.states["/x/receiving"].default_state = self.states["/x/receiving/receiving"]
  71. # transition /x/x1/x1
  72. _x_x1_x1_0 = Transition(self, self.states["/x/x1/x1"], [self.states["/x/x1/end"]])
  73. _x_x1_x1_0.setAction(self._x_x1_x1_0_exec)
  74. _x_x1_x1_0.setTrigger(None)
  75. self.states["/x/x1/x1"].addTransition(_x_x1_x1_0)
  76. # transition /x/x2/x2
  77. _x_x2_x2_0 = Transition(self, self.states["/x/x2/x2"], [self.states["/x/x2/end"]])
  78. _x_x2_x2_0.setAction(self._x_x2_x2_0_exec)
  79. _x_x2_x2_0.setTrigger(None)
  80. self.states["/x/x2/x2"].addTransition(_x_x2_x2_0)
  81. # transition /x/x3/x3
  82. _x_x3_x3_0 = Transition(self, self.states["/x/x3/x3"], [self.states["/x/x3/end"]])
  83. _x_x3_x3_0.setAction(self._x_x3_x3_0_exec)
  84. _x_x3_x3_0.setTrigger(None)
  85. self.states["/x/x3/x3"].addTransition(_x_x3_x3_0)
  86. # transition /x/receiving/receiving
  87. _x_receiving_receiving_0 = Transition(self, self.states["/x/receiving/receiving"], [self.states["/x/receiving/receiving"]])
  88. _x_receiving_receiving_0.setAction(self._x_receiving_receiving_0_exec)
  89. _x_receiving_receiving_0.setTrigger(Event("z", None))
  90. self.states["/x/receiving/receiving"].addTransition(_x_receiving_receiving_0)
  91. def _x_x1_x1_0_exec(self, parameters):
  92. self.raiseInternalEvent(Event("z", None, []))
  93. print 'raised event in x1'
  94. def _x_x2_x2_0_exec(self, parameters):
  95. self.raiseInternalEvent(Event("z", None, []))
  96. print 'raised event in x2'
  97. def _x_x3_x3_0_exec(self, parameters):
  98. self.raiseInternalEvent(Event("z", None, []))
  99. print 'raised event in x3'
  100. def _x_receiving_receiving_0_exec(self, parameters):
  101. print 'received event...'
  102. def initializeStatechart(self):
  103. # enter default state
  104. self.default_targets = self.states["/x"].getEffectiveTargetStates()
  105. RuntimeClassBase.initializeStatechart(self)
  106. class ObjectManager(ObjectManagerBase):
  107. def __init__(self, controller):
  108. ObjectManagerBase.__init__(self, controller)
  109. def instantiate(self, class_name, construct_params):
  110. if class_name == "A":
  111. instance = A(self.controller)
  112. instance.associations = {}
  113. else:
  114. raise Exception("Cannot instantiate class " + class_name)
  115. return instance
  116. class Controller(ThreadsControllerBase):
  117. def __init__(self, keep_running = None, behind_schedule_callback = None):
  118. if keep_running == None: keep_running = True
  119. if behind_schedule_callback == None: behind_schedule_callback = None
  120. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  121. self.object_manager.createInstance("A", [])