bugwithsourcechild.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Wed Oct 04 16:05:54 2017
  4. Model name: sourcechildbug
  5. """
  6. from sccd.runtime.statecharts_core import *
  7. # package "sourcechildbug"
  8. class A(RuntimeClassBase):
  9. def __init__(self, controller):
  10. RuntimeClassBase.__init__(self, controller)
  11. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  12. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  13. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  14. self.semantics.priority = StatechartSemantics.SourceChild
  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. self.a = 5
  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 /running
  29. self.states["/running"] = State(1, "/running", self)
  30. # state /running/child1
  31. self.states["/running/child1"] = State(2, "/running/child1", self)
  32. # state /running/child2
  33. self.states["/running/child2"] = State(3, "/running/child2", self)
  34. # state /running/child3
  35. self.states["/running/child3"] = State(4, "/running/child3", self)
  36. # add children
  37. self.states[""].addChild(self.states["/running"])
  38. self.states["/running"].addChild(self.states["/running/child1"])
  39. self.states["/running"].addChild(self.states["/running/child2"])
  40. self.states["/running"].addChild(self.states["/running/child3"])
  41. self.states[""].fixTree()
  42. self.states[""].default_state = self.states["/running"]
  43. self.states["/running"].default_state = self.states["/running/child1"]
  44. # transition /running/child1
  45. _running_child1_0 = Transition(self, self.states["/running/child1"], [self.states["/running/child2"]])
  46. _running_child1_0.setAction(self._running_child1_0_exec)
  47. _running_child1_0.setTrigger(None)
  48. _running_child1_0.setGuard(self._running_child1_0_guard)
  49. self.states["/running/child1"].addTransition(_running_child1_0)
  50. _running_child1_1 = Transition(self, self.states["/running/child1"], [self.states["/running/child2"]])
  51. _running_child1_1.setAction(self._running_child1_1_exec)
  52. _running_child1_1.setTrigger(None)
  53. _running_child1_1.setGuard(self._running_child1_1_guard)
  54. self.states["/running/child1"].addTransition(_running_child1_1)
  55. _running_child1_2 = Transition(self, self.states["/running/child1"], [self.states["/running/child2"]])
  56. _running_child1_2.setAction(self._running_child1_2_exec)
  57. _running_child1_2.setTrigger(None)
  58. _running_child1_2.setGuard(self._running_child1_2_guard)
  59. self.states["/running/child1"].addTransition(_running_child1_2)
  60. # transition /running
  61. _running_0 = Transition(self, self.states["/running"], [self.states["/running/child3"]])
  62. _running_0.setAction(self._running_0_exec)
  63. _running_0.setTrigger(None)
  64. _running_0.setGuard(self._running_0_guard)
  65. self.states["/running"].addTransition(_running_0)
  66. def _running_0_exec(self, parameters):
  67. print('taking outer transition')
  68. self.a = -1
  69. def _running_0_guard(self, parameters):
  70. return self.a == 5
  71. def _running_child1_0_exec(self, parameters):
  72. print('taking second inner transition')
  73. self.a = -1
  74. def _running_child1_0_guard(self, parameters):
  75. return self.a == 5
  76. def _running_child1_1_exec(self, parameters):
  77. print('taking third inner transition')
  78. self.a = -1
  79. def _running_child1_1_guard(self, parameters):
  80. return self.a == 3
  81. def _running_child1_2_exec(self, parameters):
  82. print('taking fourth inner transition')
  83. self.a = -1
  84. def _running_child1_2_guard(self, parameters):
  85. return self.a == 1
  86. def initializeStatechart(self):
  87. # enter default state
  88. self.default_targets = self.states["/running"].getEffectiveTargetStates()
  89. RuntimeClassBase.initializeStatechart(self)
  90. class ObjectManager(ObjectManagerBase):
  91. def __init__(self, controller):
  92. ObjectManagerBase.__init__(self, controller)
  93. def instantiate(self, class_name, construct_params):
  94. if class_name == "A":
  95. instance = A(self.controller)
  96. instance.associations = {}
  97. else:
  98. raise Exception("Cannot instantiate class " + class_name)
  99. return instance
  100. class Controller(ThreadsControllerBase):
  101. def __init__(self, keep_running = None, behind_schedule_callback = None):
  102. if keep_running == None: keep_running = True
  103. if behind_schedule_callback == None: behind_schedule_callback = None
  104. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  105. self.addInputPort("input")
  106. self.object_manager.createInstance("A", [])