after.py 4.9 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:56 2016
  4. Model author: Glenn De Jonghe
  5. Model name: TestAfter
  6. Model description:
  7. Used for testing the AFTER event.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "TestAfter"
  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 /composite
  32. self.states["/composite"] = State(1, self)
  33. # state /composite/state_1
  34. self.states["/composite/state_1"] = State(2, self)
  35. self.states["/composite/state_1"].setEnter(self._composite_state_1_enter)
  36. self.states["/composite/state_1"].setExit(self._composite_state_1_exit)
  37. # state /composite/state_2
  38. self.states["/composite/state_2"] = State(3, self)
  39. self.states["/composite/state_2"].setEnter(self._composite_state_2_enter)
  40. # state /composite/state_3
  41. self.states["/composite/state_3"] = State(4, self)
  42. self.states["/composite/state_3"].setEnter(self._composite_state_3_enter)
  43. # add children
  44. self.states[""].addChild(self.states["/composite"])
  45. self.states["/composite"].addChild(self.states["/composite/state_1"])
  46. self.states["/composite"].addChild(self.states["/composite/state_2"])
  47. self.states["/composite"].addChild(self.states["/composite/state_3"])
  48. self.states[""].fixTree()
  49. self.states[""].default_state = self.states["/composite"]
  50. self.states["/composite"].default_state = self.states["/composite/state_1"]
  51. # transition /composite/state_1
  52. _composite_state_1_0 = Transition(self, self.states["/composite/state_1"], [self.states["/composite/state_2"]])
  53. _composite_state_1_0.setTrigger(Event("_0after"))
  54. self.states["/composite/state_1"].addTransition(_composite_state_1_0)
  55. _composite_state_1_1 = Transition(self, self.states["/composite/state_1"], [self.states["/composite/state_3"]])
  56. _composite_state_1_1.setTrigger(Event("_1after"))
  57. self.states["/composite/state_1"].addTransition(_composite_state_1_1)
  58. def _composite_state_1_enter(self):
  59. self.addTimer(0, 0.1)
  60. self.addTimer(1, 0.2)
  61. def _composite_state_1_exit(self):
  62. self.removeTimer(0)
  63. self.removeTimer(1)
  64. def _composite_state_2_enter(self):
  65. self.big_step.outputEvent(Event("in_state_2", "test_output", []))
  66. def _composite_state_3_enter(self):
  67. self.big_step.outputEvent(Event("in_state_3", "test_output", []))
  68. def initializeStatechart(self):
  69. # enter default state
  70. self.default_targets = self.states["/composite"].getEffectiveTargetStates()
  71. RuntimeClassBase.initializeStatechart(self)
  72. class ObjectManager(ObjectManagerBase):
  73. def __init__(self, controller):
  74. ObjectManagerBase.__init__(self, controller)
  75. def instantiate(self, class_name, construct_params):
  76. if class_name == "Class1":
  77. instance = Class1(self.controller)
  78. instance.associations = {}
  79. else:
  80. raise Exception("Cannot instantiate class " + class_name)
  81. return instance
  82. class Controller(ThreadsControllerBase):
  83. def __init__(self, keep_running = None, behind_schedule_callback = None):
  84. if keep_running == None: keep_running = True
  85. if behind_schedule_callback == None: behind_schedule_callback = None
  86. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  87. self.addInputPort("test_input")
  88. self.addOutputPort("test_output")
  89. self.object_manager.createInstance("Class1", [])
  90. class InputEvent:
  91. def __init__(self, name, port, parameters, time_offset):
  92. self.name = name
  93. self.port = port
  94. self.parameters = parameters
  95. self.time_offset = time_offset
  96. class Test:
  97. def __init__(self):
  98. pass
  99. input_events = []
  100. expected_events = [[Event("in_state_2", "test_output", [])]]