multiple_afters_running_behind.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 Jun 14 14:49:34 2017
  4. Model name: multiple-afters-running-behind
  5. """
  6. from sccd.runtime.statecharts_core import *
  7. # package "multiple-afters-running-behind"
  8. class Main(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. Main.user_defined_constructor(self)
  20. def user_defined_constructor(self):
  21. pass
  22. def user_defined_destructor(self):
  23. pass
  24. # user defined method
  25. def cond(self):
  26. return True
  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. self.states["/x"].setExit(self._x_exit)
  35. # add children
  36. self.states[""].addChild(self.states["/x"])
  37. self.states[""].fixTree()
  38. self.states[""].default_state = self.states["/x"]
  39. # transition /x
  40. _x_0 = Transition(self, self.states["/x"], [self.states["/x"]])
  41. _x_0.setTrigger(Event("_0after"))
  42. _x_0.setGuard(self._x_0_guard)
  43. self.states["/x"].addTransition(_x_0)
  44. _x_1 = Transition(self, self.states["/x"], [self.states["/x"]])
  45. _x_1.setTrigger(Event("_1after"))
  46. _x_1.setGuard(self._x_1_guard)
  47. self.states["/x"].addTransition(_x_1)
  48. _x_2 = Transition(self, self.states["/x"], [self.states["/x"]])
  49. _x_2.setTrigger(Event("_2after"))
  50. _x_2.setGuard(self._x_2_guard)
  51. self.states["/x"].addTransition(_x_2)
  52. def _x_enter(self):
  53. import time
  54. print 'time.time() = %s' % time.time()
  55. time.sleep(0.1)
  56. print self.sccd_yield()
  57. self.addTimer(0, self.sccd_yield() + 0.5)
  58. self.addTimer(1, self.sccd_yield() + 0.5)
  59. self.addTimer(2, self.sccd_yield() + 0.5)
  60. def _x_exit(self):
  61. self.removeTimer(0)
  62. self.removeTimer(1)
  63. self.removeTimer(2)
  64. def _x_0_guard(self, parameters):
  65. return self.cond()
  66. def _x_1_guard(self, parameters):
  67. return self.cond()
  68. def _x_2_guard(self, parameters):
  69. return self.cond()
  70. def initializeStatechart(self):
  71. # enter default state
  72. self.default_targets = self.states["/x"].getEffectiveTargetStates()
  73. RuntimeClassBase.initializeStatechart(self)
  74. class ObjectManager(ObjectManagerBase):
  75. def __init__(self, controller):
  76. ObjectManagerBase.__init__(self, controller)
  77. def instantiate(self, class_name, construct_params):
  78. if class_name == "Main":
  79. instance = Main(self.controller)
  80. instance.associations = {}
  81. else:
  82. raise Exception("Cannot instantiate class " + class_name)
  83. return instance
  84. class Controller(ThreadsControllerBase):
  85. def __init__(self, keep_running = None, behind_schedule_callback = None):
  86. if keep_running == None: keep_running = True
  87. if behind_schedule_callback == None: behind_schedule_callback = None
  88. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  89. self.object_manager.createInstance("Main", [])