outer_first.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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:25 2016
  4. Model author: Glenn De Jonghe
  5. Model name: TestOuterFirst
  6. Model description:
  7. Testing outer first.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "TestOuterFirst"
  11. class Class1(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. Class1.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 /state1
  32. self.states["/state1"] = State(1, self)
  33. # state /state1/state1
  34. self.states["/state1/state1"] = State(2, self)
  35. # state /state1/statea
  36. self.states["/state1/statea"] = State(3, self)
  37. self.states["/state1/statea"].setEnter(self._state1_statea_enter)
  38. # state /stateb
  39. self.states["/stateb"] = State(4, self)
  40. self.states["/stateb"].setEnter(self._stateb_enter)
  41. # add children
  42. self.states[""].addChild(self.states["/state1"])
  43. self.states[""].addChild(self.states["/stateb"])
  44. self.states["/state1"].addChild(self.states["/state1/state1"])
  45. self.states["/state1"].addChild(self.states["/state1/statea"])
  46. self.states[""].fixTree()
  47. self.states[""].default_state = self.states["/state1"]
  48. self.states["/state1"].default_state = self.states["/state1/state1"]
  49. # transition /state1/state1
  50. _state1_state1_0 = Transition(self, self.states["/state1/state1"], [self.states["/state1/statea"]])
  51. _state1_state1_0.setTrigger(Event("event", "test_input"))
  52. self.states["/state1/state1"].addTransition(_state1_state1_0)
  53. # transition /state1
  54. _state1_0 = Transition(self, self.states["/state1"], [self.states["/stateb"]])
  55. _state1_0.setTrigger(Event("event", "test_input"))
  56. self.states["/state1"].addTransition(_state1_0)
  57. def _state1_statea_enter(self):
  58. self.big_step.outputEvent(Event("in_a", "test_output", []))
  59. def _stateb_enter(self):
  60. self.big_step.outputEvent(Event("in_b", "test_output", []))
  61. def initializeStatechart(self):
  62. # enter default state
  63. states = self.states["/state1"].getEffectiveTargetStates()
  64. self.updateConfiguration(states)
  65. for state in states:
  66. if state.enter:
  67. state.enter()
  68. class ObjectManager(ObjectManagerBase):
  69. def __init__(self, controller):
  70. ObjectManagerBase.__init__(self, controller)
  71. def instantiate(self, class_name, construct_params):
  72. if class_name == "Class1":
  73. instance = Class1(self.controller)
  74. instance.associations = {}
  75. else:
  76. raise Exception("Cannot instantiate class " + class_name)
  77. return instance
  78. class Controller(ThreadsControllerBase):
  79. def __init__(self, keep_running = None):
  80. if keep_running == None: keep_running = True
  81. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  82. self.addInputPort("test_input")
  83. self.addOutputPort("test_output")
  84. self.object_manager.createInstance("Class1", [])
  85. class InputEvent:
  86. def __init__(self, name, port, parameters, time_offset):
  87. self.name = name
  88. self.port = port
  89. self.parameters = parameters
  90. self.time_offset = time_offset
  91. class Test:
  92. def __init__(self):
  93. pass
  94. input_events = [InputEvent("event", "test_input", [], 0.0)]
  95. expected_events = [[Event("in_b", "test_output", [])]]