server.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Fri Aug 5 15:59:05 2016
  4. Model author: Yentl Van Tendeloo
  5. Model name: broken
  6. Model description:
  7. Broken!
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "broken"
  11. class A(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. A.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 /x
  32. self.states["/x"] = State(1, self)
  33. self.states["/x"].setEnter(self._x_enter)
  34. # state /ready
  35. self.states["/ready"] = State(2, self)
  36. self.states["/ready"].setEnter(self._ready_enter)
  37. # state /done
  38. self.states["/done"] = State(3, self)
  39. # add children
  40. self.states[""].addChild(self.states["/x"])
  41. self.states[""].addChild(self.states["/ready"])
  42. self.states[""].addChild(self.states["/done"])
  43. self.states[""].fixTree()
  44. self.states[""].default_state = self.states["/x"]
  45. # transition /x
  46. _x_0 = Transition(self, self.states["/x"], [self.states["/ready"]])
  47. _x_0.setAction(self._x_0_exec)
  48. _x_0.trigger = Event("instance_created", None)
  49. self.states["/x"].addTransition(_x_0)
  50. # transition /ready
  51. _ready_0 = Transition(self, self.states["/ready"], [self.states["/done"]])
  52. _ready_0.setAction(self._ready_0_exec)
  53. _ready_0.trigger = Event("close", None)
  54. self.states["/ready"].addTransition(_ready_0)
  55. def _x_enter(self):
  56. self.big_step.outputEventOM(Event("create_instance", None, [self, 'child', 'B']))
  57. def _ready_enter(self):
  58. self.big_step.outputEventOM(Event("start_instance", None, [self, self.instancename]))
  59. def _x_0_exec(self, parameters):
  60. instancename = parameters[0]
  61. self.instancename = instancename
  62. print(self.instancename)
  63. def _ready_0_exec(self, parameters):
  64. print("CLOSED")
  65. self.big_step.outputEventOM(Event("delete_instance", None, [self, self.instancename]))
  66. def initializeStatechart(self):
  67. # enter default state
  68. states = self.states["/x"].getEffectiveTargetStates()
  69. self.updateConfiguration(states)
  70. for state in states:
  71. if state.enter:
  72. state.enter()
  73. class B(RuntimeClassBase):
  74. def __init__(self, controller):
  75. RuntimeClassBase.__init__(self, controller)
  76. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  77. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  78. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  79. self.semantics.priority = StatechartSemantics.SourceParent
  80. self.semantics.concurrency = StatechartSemantics.Single
  81. # build Statechart structure
  82. self.build_statechart_structure()
  83. # call user defined constructor
  84. B.user_defined_constructor(self)
  85. def user_defined_constructor(self):
  86. print("READY")
  87. def user_defined_destructor(self):
  88. pass
  89. # builds Statechart structure
  90. def build_statechart_structure(self):
  91. # state <root>
  92. self.states[""] = State(0, self)
  93. # state /z
  94. self.states["/z"] = State(1, self)
  95. self.states["/z"].setEnter(self._z_enter)
  96. self.states["/z"].setExit(self._z_exit)
  97. # add children
  98. self.states[""].addChild(self.states["/z"])
  99. self.states[""].fixTree()
  100. self.states[""].default_state = self.states["/z"]
  101. # transition /z
  102. _z_0 = Transition(self, self.states["/z"], [self.states["/z"]])
  103. _z_0.setAction(self._z_0_exec)
  104. _z_0.trigger = Event("_0after")
  105. self.states["/z"].addTransition(_z_0)
  106. def _z_enter(self):
  107. self.addTimer(0, 0)
  108. print("RUN")
  109. def _z_exit(self):
  110. self.removeTimer(0)
  111. def _z_0_exec(self, parameters):
  112. print("RAISE")
  113. self.big_step.outputEventOM(Event("broad_cast", None, [Event("close", None, [])]))
  114. def initializeStatechart(self):
  115. # enter default state
  116. states = self.states["/z"].getEffectiveTargetStates()
  117. self.updateConfiguration(states)
  118. for state in states:
  119. if state.enter:
  120. state.enter()
  121. class ObjectManager(ObjectManagerBase):
  122. def __init__(self, controller):
  123. ObjectManagerBase.__init__(self, controller)
  124. def instantiate(self, class_name, construct_params):
  125. if class_name == "A":
  126. instance = A(self.controller)
  127. instance.associations = {}
  128. instance.associations["child"] = Association("B", 0, 1)
  129. elif class_name == "B":
  130. instance = B(self.controller)
  131. instance.associations = {}
  132. instance.associations["parent"] = Association("A", 1, 1)
  133. else:
  134. raise Exception("Cannot instantiate class " + class_name)
  135. return instance
  136. class Controller(ThreadsControllerBase):
  137. def __init__(self, keep_running = None):
  138. if keep_running == None: keep_running = True
  139. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  140. self.object_manager.createInstance("A", [])