target.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Model author: Sam Pieters
  4. Model name: Create and Delete Multiple Running Instance (other than the MainApp)
  5. Model description:
  6. # TODO: Still need to do this
  7. Test 15: Check if multiple running instances can be deleted after the creation.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "Create and Delete Multiple Running Instance (other than the MainApp)"
  11. class MainApp(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. MainApp.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, "/state1", self)
  33. self.states["/state1"].setEnter(self._state1_enter)
  34. # state /state2
  35. self.states["/state2"] = State(2, "/state2", self)
  36. # state /state3
  37. self.states["/state3"] = State(3, "/state3", self)
  38. self.states["/state3"].setEnter(self._state3_enter)
  39. # state /state4
  40. self.states["/state4"] = State(4, "/state4", self)
  41. self.states["/state4"].setEnter(self._state4_enter)
  42. # add children
  43. self.states[""].addChild(self.states["/state1"])
  44. self.states[""].addChild(self.states["/state2"])
  45. self.states[""].addChild(self.states["/state3"])
  46. self.states[""].addChild(self.states["/state4"])
  47. self.states[""].fixTree()
  48. self.states[""].default_state = self.states["/state1"]
  49. # transition /state1
  50. _state1_0 = Transition(self, self.states["/state1"], [self.states["/state2"]])
  51. _state1_0.setAction(self._state1_0_exec)
  52. _state1_0.setTrigger(Event("instance_created", None))
  53. self.states["/state1"].addTransition(_state1_0)
  54. # transition /state2
  55. _state2_0 = Transition(self, self.states["/state2"], [self.states["/state3"]])
  56. _state2_0.setAction(self._state2_0_exec)
  57. _state2_0.setTrigger(Event("instance_started", None))
  58. self.states["/state2"].addTransition(_state2_0)
  59. # transition /state3
  60. _state3_0 = Transition(self, self.states["/state3"], [self.states["/state4"]])
  61. _state3_0.setAction(self._state3_0_exec)
  62. _state3_0.setTrigger(Event("instance_deleted", None))
  63. self.states["/state3"].addTransition(_state3_0)
  64. def _state1_enter(self):
  65. self.big_step.outputEventOM(Event("create_instance", None, [self, "linkA", "A"]))
  66. def _state3_enter(self):
  67. self.big_step.outputEventOM(Event("delete_instance", None, [self, 'linkA[0]']))
  68. def _state4_enter(self):
  69. self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'linkA[0]', Event("sanity_check", None, [])]))
  70. def _state1_0_exec(self, parameters):
  71. association_name = parameters[0]
  72. self.big_step.outputEvent(Event("instance_created_succesfully", self.getOutPortName("ui"), [str('%.2f' % (self.getSimulatedTime() / 1000.0)), association_name]))
  73. self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
  74. def _state2_0_exec(self, parameters):
  75. association_name = parameters[0]
  76. self.big_step.outputEvent(Event("instance_started_succesfully", self.getOutPortName("ui"), [str('%.2f' % (self.getSimulatedTime() / 1000.0)), association_name]))
  77. def _state3_0_exec(self, parameters):
  78. deleted_links = parameters[0]
  79. self.big_step.outputEvent(Event("instance_deleted_succesfully", self.getOutPortName("ui"), [str('%.2f' % (self.getSimulatedTime() / 1000.0)), deleted_links]))
  80. def initializeStatechart(self):
  81. # enter default state
  82. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  83. RuntimeClassBase.initializeStatechart(self)
  84. class A(RuntimeClassBase):
  85. def __init__(self, controller):
  86. RuntimeClassBase.__init__(self, controller)
  87. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  88. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  89. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  90. self.semantics.priority = StatechartSemantics.SourceParent
  91. self.semantics.concurrency = StatechartSemantics.Single
  92. # build Statechart structure
  93. self.build_statechart_structure()
  94. # call user defined constructor
  95. A.user_defined_constructor(self)
  96. def user_defined_constructor(self):
  97. pass
  98. def user_defined_destructor(self):
  99. pass
  100. # builds Statechart structure
  101. def build_statechart_structure(self):
  102. # state <root>
  103. self.states[""] = State(0, "", self)
  104. # state /state1
  105. self.states["/state1"] = State(1, "/state1", self)
  106. self.states["/state1"].setEnter(self._state1_enter)
  107. # add children
  108. self.states[""].addChild(self.states["/state1"])
  109. self.states[""].fixTree()
  110. self.states[""].default_state = self.states["/state1"]
  111. # transition /state1
  112. _state1_0 = Transition(self, self.states["/state1"], [self.states["/state1"]])
  113. _state1_0.setAction(self._state1_0_exec)
  114. _state1_0.setTrigger(Event("sanity_check", None))
  115. self.states["/state1"].addTransition(_state1_0)
  116. def _state1_enter(self):
  117. self.big_step.outputEvent(Event("statechart_started_succesfully", self.getOutPortName("ui"), [str('%.2f' % (self.getSimulatedTime() / 1000.0))]))
  118. def _state1_0_exec(self, parameters):
  119. self.big_step.outputEvent(Event("not_possible", self.getOutPortName("ui"), [str('%.2f' % (self.getSimulatedTime() / 1000.0))]))
  120. def initializeStatechart(self):
  121. # enter default state
  122. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  123. RuntimeClassBase.initializeStatechart(self)
  124. class ObjectManager(ObjectManagerBase):
  125. def __init__(self, controller):
  126. ObjectManagerBase.__init__(self, controller)
  127. def instantiate(self, class_name, construct_params):
  128. if class_name == "MainApp":
  129. instance = MainApp(self.controller)
  130. instance.associations = {}
  131. instance.associations["linkA"] = Association("A", 0, -1)
  132. elif class_name == "A":
  133. instance = A(self.controller)
  134. instance.associations = {}
  135. else:
  136. raise Exception("Cannot instantiate class " + class_name)
  137. return instance
  138. class Controller(ThreadsControllerBase):
  139. def __init__(self, keep_running = None, behind_schedule_callback = None):
  140. if keep_running == None: keep_running = True
  141. if behind_schedule_callback == None: behind_schedule_callback = None
  142. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  143. self.addInputPort("ui")
  144. self.addOutputPort("ui")
  145. self.object_manager.createInstance("MainApp", [])