exit_parallel.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Wed Aug 10 11:42:10 2016
  4. Model name: exit-parallel
  5. """
  6. from sccd.runtime.statecharts_core import *
  7. # package "exit-parallel"
  8. class A(RuntimeClassBase):
  9. def __init__(self, controller):
  10. RuntimeClassBase.__init__(self, controller)
  11. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  12. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  13. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  14. self.semantics.priority = StatechartSemantics.SourceParent
  15. self.semantics.concurrency = StatechartSemantics.Single
  16. # build Statechart structure
  17. self.build_statechart_structure()
  18. # call user defined constructor
  19. A.user_defined_constructor(self)
  20. def user_defined_constructor(self):
  21. pass
  22. def user_defined_destructor(self):
  23. pass
  24. # builds Statechart structure
  25. def build_statechart_structure(self):
  26. # state <root>
  27. self.states[""] = State(0, self)
  28. # state /x
  29. self.states["/x"] = ParallelState(1, self)
  30. # state /x/x1
  31. self.states["/x/x1"] = State(2, self)
  32. # state /x/x1/x1
  33. self.states["/x/x1/x1"] = State(3, self)
  34. # state /x/x2
  35. self.states["/x/x2"] = State(4, self)
  36. # state /x/x2/x2
  37. self.states["/x/x2/x2"] = State(5, self)
  38. # state /done
  39. self.states["/done"] = State(6, self)
  40. self.states["/done"].setEnter(self._done_enter)
  41. # add children
  42. self.states[""].addChild(self.states["/x"])
  43. self.states[""].addChild(self.states["/done"])
  44. self.states["/x"].addChild(self.states["/x/x1"])
  45. self.states["/x"].addChild(self.states["/x/x2"])
  46. self.states["/x/x1"].addChild(self.states["/x/x1/x1"])
  47. self.states["/x/x2"].addChild(self.states["/x/x2/x2"])
  48. self.states[""].fixTree()
  49. self.states[""].default_state = self.states["/x"]
  50. self.states["/x/x1"].default_state = self.states["/x/x1/x1"]
  51. self.states["/x/x2"].default_state = self.states["/x/x2/x2"]
  52. # transition /x/x1/x1
  53. _x_x1_x1_0 = Transition(self, self.states["/x/x1/x1"], [self.states["/done"]])
  54. _x_x1_x1_0.setAction(self._x_x1_x1_0_exec)
  55. _x_x1_x1_0.setTrigger(None)
  56. _x_x1_x1_0.setGuard(self._x_x1_x1_0_guard)
  57. self.states["/x/x1/x1"].addTransition(_x_x1_x1_0)
  58. _x_x1_x1_1 = Transition(self, self.states["/x/x1/x1"], [self.states["/done"]])
  59. _x_x1_x1_1.setTrigger(Event("E", None))
  60. self.states["/x/x1/x1"].addTransition(_x_x1_x1_1)
  61. def _done_enter(self):
  62. print 'in done'
  63. def _x_x1_x1_0_exec(self, parameters):
  64. print 'taking transition'
  65. def _x_x1_x1_0_guard(self, parameters):
  66. return self.a == 5
  67. def initializeStatechart(self):
  68. # enter default state
  69. self.default_targets = self.states["/x"].getEffectiveTargetStates()
  70. RuntimeClassBase.initializeStatechart(self)
  71. class ObjectManager(ObjectManagerBase):
  72. def __init__(self, controller):
  73. ObjectManagerBase.__init__(self, controller)
  74. def instantiate(self, class_name, construct_params):
  75. if class_name == "A":
  76. instance = A(self.controller)
  77. instance.associations = {}
  78. else:
  79. raise Exception("Cannot instantiate class " + class_name)
  80. return instance
  81. class Controller(ThreadsControllerBase):
  82. def __init__(self, keep_running = None, behind_schedule_callback = None):
  83. if keep_running == None: keep_running = True
  84. if behind_schedule_callback == None: behind_schedule_callback = None
  85. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  86. self.object_manager.createInstance("A", [])