01_source_child.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 09:35:58 2016
  4. Model author: Herr Joeri Exelmans
  5. Model name: source_child
  6. Model description:
  7. 'Source Child' priority-semantics: If 2 transitions are enabled, and the source state of the first is an ancestor of the second, only the second is executed.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "source_child"
  11. class c(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.SourceChild
  18. self.semantics.concurrency = StatechartSemantics.Single
  19. # build Statechart structure
  20. self.build_statechart_structure()
  21. # call user defined constructor
  22. c.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 /parent
  32. self.states["/parent"] = State(1, self)
  33. self.states["/parent"].setEnter(self._parent_enter)
  34. # state /parent/a
  35. self.states["/parent/a"] = State(2, self)
  36. self.states["/parent/a"].setEnter(self._parent_a_enter)
  37. # state /parent/b
  38. self.states["/parent/b"] = State(3, self)
  39. self.states["/parent/b"].setEnter(self._parent_b_enter)
  40. # state /c
  41. self.states["/c"] = State(4, self)
  42. self.states["/c"].setEnter(self._c_enter)
  43. # add children
  44. self.states[""].addChild(self.states["/parent"])
  45. self.states[""].addChild(self.states["/c"])
  46. self.states["/parent"].addChild(self.states["/parent/a"])
  47. self.states["/parent"].addChild(self.states["/parent/b"])
  48. self.states[""].fixTree()
  49. self.states[""].default_state = self.states["/parent"]
  50. self.states["/parent"].default_state = self.states["/parent/a"]
  51. # transition /parent/a
  52. _parent_a_0 = Transition(self, self.states["/parent/a"], [self.states["/parent/b"]])
  53. _parent_a_0.setTrigger(None)
  54. self.states["/parent/a"].addTransition(_parent_a_0)
  55. # transition /parent
  56. _parent_0 = Transition(self, self.states["/parent"], [self.states["/c"]])
  57. _parent_0.setTrigger(None)
  58. self.states["/parent"].addTransition(_parent_0)
  59. def _parent_enter(self):
  60. self.big_step.outputEvent(Event("entered_parent", "out", []))
  61. def _parent_a_enter(self):
  62. self.big_step.outputEvent(Event("entered_a", "out", []))
  63. def _parent_b_enter(self):
  64. self.big_step.outputEvent(Event("entered_b", "out", []))
  65. def _c_enter(self):
  66. self.big_step.outputEvent(Event("entered_c", "out", []))
  67. def initializeStatechart(self):
  68. # enter default state
  69. self.default_targets = self.states["/parent"].getEffectiveTargetStates()
  70. RuntimeClassBase.initializeStatechart(self)
  71. class ObjectManager(ObjectManagerBase):
  72. def __init__(self, controller):
  73. ObjectManagerBase.__init__(self, controller)
  74. def instantiate(self, class_name, construct_params):
  75. if class_name == "c":
  76. instance = c(self.controller)
  77. instance.associations = {}
  78. else:
  79. raise Exception("Cannot instantiate class " + class_name)
  80. return instance
  81. class Controller(ThreadsControllerBase):
  82. def __init__(self, keep_running = None, behind_schedule_callback = None):
  83. if keep_running == None: keep_running = True
  84. if behind_schedule_callback == None: behind_schedule_callback = None
  85. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  86. self.addInputPort("in")
  87. self.addOutputPort("out")
  88. self.object_manager.createInstance("c", [])
  89. class InputEvent:
  90. def __init__(self, name, port, parameters, time_offset):
  91. self.name = name
  92. self.port = port
  93. self.parameters = parameters
  94. self.time_offset = time_offset
  95. class Test:
  96. def __init__(self):
  97. pass
  98. input_events = []
  99. expected_events = [[Event("entered_parent", "out", []), Event("entered_a", "out", [])], [Event("entered_b", "out", []), Event("entered_c", "out", [])]]