12_take_many_queue.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Mon Aug 08 09:49:23 2016
  4. Model author: Herr Joeri Exelmans
  5. Model name: take_many_queue
  6. Model description:
  7. Internal event lifeline - Queue-semantics: Internally raised events are treated like external events and are added to the object's event queue. They become present in another big step later on.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "take_many_queue"
  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.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.setAction(self._a_0_exec)
  49. _a_0.setTrigger(Event("e", "in"))
  50. self.states["/a"].addTransition(_a_0)
  51. # transition /b
  52. _b_0 = Transition(self, self.states["/b"], [self.states["/c"]])
  53. _b_0.setTrigger(Event("f", None))
  54. self.states["/b"].addTransition(_b_0)
  55. def _a_enter(self):
  56. self.big_step.outputEvent(Event("entered_a", "out", []))
  57. def _b_enter(self):
  58. self.big_step.outputEvent(Event("entered_b", "out", []))
  59. def _c_enter(self):
  60. self.big_step.outputEvent(Event("entered_c", "out", []))
  61. def _a_0_exec(self, parameters):
  62. self.raiseInternalEvent(Event("f", None, []))
  63. def initializeStatechart(self):
  64. # enter default state
  65. states = self.states["/a"].getEffectiveTargetStates()
  66. self.updateConfiguration(states)
  67. for state in states:
  68. if state.enter:
  69. state.enter()
  70. class ObjectManager(ObjectManagerBase):
  71. def __init__(self, controller):
  72. ObjectManagerBase.__init__(self, controller)
  73. def instantiate(self, class_name, construct_params):
  74. if class_name == "c":
  75. instance = c(self.controller)
  76. instance.associations = {}
  77. else:
  78. raise Exception("Cannot instantiate class " + class_name)
  79. return instance
  80. class Controller(ThreadsControllerBase):
  81. def __init__(self, keep_running = None):
  82. if keep_running == None: keep_running = True
  83. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  84. self.addInputPort("in")
  85. self.addOutputPort("out")
  86. self.object_manager.createInstance("c", [])
  87. class InputEvent:
  88. def __init__(self, name, port, parameters, time_offset):
  89. self.name = name
  90. self.port = port
  91. self.parameters = parameters
  92. self.time_offset = time_offset
  93. class Test:
  94. def __init__(self):
  95. pass
  96. input_events = [InputEvent("e", "in", [], 0.0)]
  97. expected_events = [[Event("entered_a", "out", [])], [Event("entered_b", "out", [])], [Event("entered_c", "out", [])]]