00_take_one.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 Aug 03 16:10:21 2016
  4. Model author: Herr Joeri Exelmans
  5. Model name: take_one
  6. Model description:
  7. Take One-semantics: Each big step, only one transition can be made (per orthogonal component).
  8. """
  9. from python_runtime.statecharts_core import *
  10. # package "take_one"
  11. class c(RuntimeClassBase):
  12. def __init__(self, controller):
  13. RuntimeClassBase.__init__(self, controller)
  14. self.semantics.big_step_maximality = StatechartSemantics.TakeOne
  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. 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 /a
  32. self.states["/a"] = State(1, self)
  33. self.states["/a"].setEnter(self._a_enter)
  34. # state /b
  35. self.states["/b"] = State(2, self)
  36. self.states["/b"].setEnter(self._b_enter)
  37. # state /c
  38. self.states["/c"] = State(3, self)
  39. self.states["/c"].setEnter(self._c_enter)
  40. # add children
  41. self.states[""].addChild(self.states["/a"])
  42. self.states[""].addChild(self.states["/b"])
  43. self.states[""].addChild(self.states["/c"])
  44. self.states[""].fixTree()
  45. self.states[""].default_state = self.states["/a"]
  46. # transition /a
  47. _a_0 = Transition(self, self.states["/a"], [self.states["/b"]])
  48. self.states["/a"].addTransition(_a_0)
  49. # transition /b
  50. _b_0 = Transition(self, self.states["/b"], [self.states["/c"]])
  51. self.states["/b"].addTransition(_b_0)
  52. def _a_enter(self):
  53. self.big_step.outputEvent(Event("entered_a", "out", []))
  54. def _b_enter(self):
  55. self.big_step.outputEvent(Event("entered_b", "out", []))
  56. def _c_enter(self):
  57. self.big_step.outputEvent(Event("entered_c", "out", []))
  58. def initializeStatechart(self):
  59. # enter default state
  60. states = self.states["/a"].getEffectiveTargetStates()
  61. self.updateConfiguration(states)
  62. for state in states:
  63. if state.enter:
  64. state.enter()
  65. class ObjectManager(ObjectManagerBase):
  66. def __init__(self, controller):
  67. ObjectManagerBase.__init__(self, controller)
  68. def instantiate(self, class_name, construct_params):
  69. if class_name == "c":
  70. instance = c(self.controller)
  71. instance.associations = {}
  72. return instance
  73. class Controller(ThreadsControllerBase):
  74. def __init__(self, keep_running = None):
  75. if keep_running == None: keep_running = True
  76. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  77. self.addInputPort("in")
  78. self.addOutputPort("out")
  79. self.object_manager.createInstance("c", [])
  80. class InputEvent:
  81. def __init__(self, name, port, parameters, time_offset):
  82. self.name = name
  83. self.port = port
  84. self.parameters = parameters
  85. self.time_offset = time_offset
  86. class Test:
  87. def __init__(self):
  88. pass
  89. input_events = []
  90. expected_events = [[Event("entered_a", "out", [])], [Event("entered_b", "out", [])], [Event("entered_c", "out", [])]]