eventloop_bug.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 Sep 27 15:08:22 2017
  4. Model name: multiple-raises-parallel
  5. """
  6. from sccd.runtime.statecharts_core import *
  7. # package "multiple-raises-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 /listening
  29. self.states["/listening"] = State(1, "/listening", self)
  30. self.states["/listening"].setEnter(self._listening_enter)
  31. self.states["/listening"].setExit(self._listening_exit)
  32. # add children
  33. self.states[""].addChild(self.states["/listening"])
  34. self.states[""].fixTree()
  35. self.states[""].default_state = self.states["/listening"]
  36. # transition /listening
  37. _listening_0 = Transition(self, self.states["/listening"], [self.states["/listening"]])
  38. _listening_0.setAction(self._listening_0_exec)
  39. _listening_0.setTrigger(Event("input", "input"))
  40. self.states["/listening"].addTransition(_listening_0)
  41. _listening_1 = Transition(self, self.states["/listening"], [self.states["/listening"]])
  42. _listening_1.setTrigger(Event("_0after"))
  43. self.states["/listening"].addTransition(_listening_1)
  44. def _listening_enter(self):
  45. self.addTimer(0, 1)
  46. def _listening_exit(self):
  47. self.removeTimer(0)
  48. def _listening_0_exec(self, parameters):
  49. value = parameters[0]
  50. print(value)
  51. def initializeStatechart(self):
  52. # enter default state
  53. self.default_targets = self.states["/listening"].getEffectiveTargetStates()
  54. RuntimeClassBase.initializeStatechart(self)
  55. class ObjectManager(ObjectManagerBase):
  56. def __init__(self, controller):
  57. ObjectManagerBase.__init__(self, controller)
  58. def instantiate(self, class_name, construct_params):
  59. if class_name == "A":
  60. instance = A(self.controller)
  61. instance.associations = {}
  62. else:
  63. raise Exception("Cannot instantiate class " + class_name)
  64. return instance
  65. class Controller(EventLoopControllerBase):
  66. def __init__(self, event_loop_callbacks, finished_callback = None, behind_schedule_callback = None):
  67. if finished_callback == None: finished_callback = None
  68. if behind_schedule_callback == None: behind_schedule_callback = None
  69. EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback, behind_schedule_callback)
  70. self.addInputPort("input")
  71. self.object_manager.createInstance("A", [])