00_take_one.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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:55 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 sccd.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. _a_0.setTrigger(None)
  49. self.states["/a"].addTransition(_a_0)
  50. # transition /b
  51. _b_0 = Transition(self, self.states["/b"], [self.states["/c"]])
  52. _b_0.setTrigger(None)
  53. self.states["/b"].addTransition(_b_0)
  54. def _a_enter(self):
  55. self.big_step.outputEvent(Event("entered_a", "out", []))
  56. def _b_enter(self):
  57. self.big_step.outputEvent(Event("entered_b", "out", []))
  58. def _c_enter(self):
  59. self.big_step.outputEvent(Event("entered_c", "out", []))
  60. def initializeStatechart(self):
  61. # enter default state
  62. self.default_targets = self.states["/a"].getEffectiveTargetStates()
  63. RuntimeClassBase.initializeStatechart(self)
  64. class ObjectManager(ObjectManagerBase):
  65. def __init__(self, controller):
  66. ObjectManagerBase.__init__(self, controller)
  67. def instantiate(self, class_name, construct_params):
  68. if class_name == "c":
  69. instance = c(self.controller)
  70. instance.associations = {}
  71. else:
  72. raise Exception("Cannot instantiate class " + class_name)
  73. return instance
  74. class Controller(ThreadsControllerBase):
  75. def __init__(self, keep_running = None, behind_schedule_callback = None):
  76. if keep_running == None: keep_running = True
  77. if behind_schedule_callback == None: behind_schedule_callback = None
  78. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  79. self.addInputPort("in")
  80. self.addOutputPort("out")
  81. self.object_manager.createInstance("c", [])
  82. class InputEvent:
  83. def __init__(self, name, port, parameters, time_offset):
  84. self.name = name
  85. self.port = port
  86. self.parameters = parameters
  87. self.time_offset = time_offset
  88. class Test:
  89. def __init__(self):
  90. pass
  91. input_events = []
  92. expected_events = [[Event("entered_a", "out", [])], [Event("entered_b", "out", [])], [Event("entered_c", "out", [])]]