test.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Tue Aug 09 14:27:20 2016
  4. Model author: Yentl Van Tendeloo
  5. Model name: broken
  6. Model description:
  7. Broken!
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "broken"
  11. class A(RuntimeClassBase):
  12. def __init__(self, controller):
  13. RuntimeClassBase.__init__(self, controller)
  14. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  15. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  16. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  17. self.semantics.priority = StatechartSemantics.SourceParent
  18. self.semantics.concurrency = StatechartSemantics.Single
  19. # build Statechart structure
  20. self.build_statechart_structure()
  21. # call user defined constructor
  22. A.user_defined_constructor(self)
  23. def user_defined_constructor(self):
  24. pass
  25. def user_defined_destructor(self):
  26. pass
  27. # builds Statechart structure
  28. def build_statechart_structure(self):
  29. # state <root>
  30. self.states[""] = State(0, self)
  31. # state /x
  32. self.states["/x"] = State(1, self)
  33. self.states["/x"].setEnter(self._x_enter)
  34. # state /ready
  35. self.states["/ready"] = State(2, self)
  36. self.states["/ready"].setEnter(self._ready_enter)
  37. self.states["/ready"].setExit(self._ready_exit)
  38. # state /done
  39. self.states["/done"] = State(3, self)
  40. # add children
  41. self.states[""].addChild(self.states["/x"])
  42. self.states[""].addChild(self.states["/ready"])
  43. self.states[""].addChild(self.states["/done"])
  44. self.states[""].fixTree()
  45. self.states[""].default_state = self.states["/x"]
  46. # transition /x
  47. _x_0 = Transition(self, self.states["/x"], [self.states["/ready"]])
  48. _x_0.setAction(self._x_0_exec)
  49. _x_0.setTrigger(Event("instance_created", None))
  50. self.states["/x"].addTransition(_x_0)
  51. # transition /ready
  52. _ready_0 = Transition(self, self.states["/ready"], [self.states["/ready"]])
  53. _ready_0.setAction(self._ready_0_exec)
  54. _ready_0.setTrigger(Event("_0after"))
  55. self.states["/ready"].addTransition(_ready_0)
  56. _ready_1 = Transition(self, self.states["/ready"], [self.states["/done"]])
  57. _ready_1.setAction(self._ready_1_exec)
  58. _ready_1.setTrigger(Event("close", None))
  59. self.states["/ready"].addTransition(_ready_1)
  60. def _x_enter(self):
  61. self.big_step.outputEventOM(Event("create_instance", None, [self, 'child', 'B']))
  62. def _ready_enter(self):
  63. self.addTimer(0, 0.001)
  64. def _ready_exit(self):
  65. self.removeTimer(0)
  66. def _x_0_exec(self, parameters):
  67. instancename = parameters[0]
  68. self.instancename = instancename
  69. self.big_step.outputEventOM(Event("start_instance", None, [self, self.instancename]))
  70. def _ready_0_exec(self, parameters):
  71. for _ in range(100000):
  72. pass
  73. def _ready_1_exec(self, parameters):
  74. self.big_step.outputEventOM(Event("delete_instance", None, [self, self.instancename]))
  75. def initializeStatechart(self):
  76. # enter default state
  77. self.default_targets = self.states["/x"].getEffectiveTargetStates()
  78. RuntimeClassBase.initializeStatechart(self)
  79. class B(RuntimeClassBase):
  80. def __init__(self, controller):
  81. RuntimeClassBase.__init__(self, controller)
  82. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  83. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  84. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  85. self.semantics.priority = StatechartSemantics.SourceParent
  86. self.semantics.concurrency = StatechartSemantics.Single
  87. # build Statechart structure
  88. self.build_statechart_structure()
  89. # call user defined constructor
  90. B.user_defined_constructor(self)
  91. def user_defined_constructor(self):
  92. pass
  93. def user_defined_destructor(self):
  94. pass
  95. # builds Statechart structure
  96. def build_statechart_structure(self):
  97. # state <root>
  98. self.states[""] = State(0, self)
  99. # state /z
  100. self.states["/z"] = State(1, self)
  101. # add children
  102. self.states[""].addChild(self.states["/z"])
  103. self.states[""].fixTree()
  104. self.states[""].default_state = self.states["/z"]
  105. # transition /z
  106. _z_0 = Transition(self, self.states["/z"], [self.states["/z"]])
  107. _z_0.setAction(self._z_0_exec)
  108. _z_0.setTrigger(Event("stop", "input"))
  109. self.states["/z"].addTransition(_z_0)
  110. def _z_0_exec(self, parameters):
  111. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent[0]', Event("close", None, [])]))
  112. def initializeStatechart(self):
  113. # enter default state
  114. self.default_targets = self.states["/z"].getEffectiveTargetStates()
  115. RuntimeClassBase.initializeStatechart(self)
  116. class ObjectManager(ObjectManagerBase):
  117. def __init__(self, controller):
  118. ObjectManagerBase.__init__(self, controller)
  119. def instantiate(self, class_name, construct_params):
  120. if class_name == "A":
  121. instance = A(self.controller)
  122. instance.associations = {}
  123. instance.associations["child"] = Association("B", 0, 1)
  124. elif class_name == "B":
  125. instance = B(self.controller)
  126. instance.associations = {}
  127. instance.associations["parent"] = Association("A", 1, 1)
  128. else:
  129. raise Exception("Cannot instantiate class " + class_name)
  130. return instance
  131. class Controller(ThreadsControllerBase):
  132. def __init__(self, keep_running = None, behind_schedule_callback = None):
  133. if keep_running == None: keep_running = True
  134. if behind_schedule_callback == None: behind_schedule_callback = None
  135. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  136. self.addInputPort("input")
  137. self.object_manager.createInstance("A", [])