poll_print.py 4.2 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: Mon Aug 28 10:54:41 2017
  4. Model author: Yentl Van Tendeloo
  5. Model name: Logging
  6. Model description:
  7. For testing: I/O Statechart for the Modelverse
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "Logging"
  11. class Logging(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. Logging.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 /init
  32. self.states["/init"] = State(1, "/init", self)
  33. self.states["/init"].setEnter(self._init_enter)
  34. self.states["/init"].setExit(self._init_exit)
  35. # state /finished
  36. self.states["/finished"] = State(2, "/finished", self)
  37. # add children
  38. self.states[""].addChild(self.states["/init"])
  39. self.states[""].addChild(self.states["/finished"])
  40. self.states[""].fixTree()
  41. self.states[""].default_state = self.states["/init"]
  42. # transition /init
  43. _init_0 = Transition(self, self.states["/init"], [self.states["/init"]])
  44. _init_0.setAction(self._init_0_exec)
  45. _init_0.setTrigger(Event("input", "inp"))
  46. self.states["/init"].addTransition(_init_0)
  47. _init_1 = Transition(self, self.states["/init"], [self.states["/init"]])
  48. _init_1.setTrigger(Event("_0after"))
  49. self.states["/init"].addTransition(_init_1)
  50. _init_2 = Transition(self, self.states["/init"], [self.states["/finished"]])
  51. _init_2.setTrigger(Event("terminate", "inp"))
  52. self.states["/init"].addTransition(_init_2)
  53. _init_3 = Transition(self, self.states["/init"], [self.states["/init"]])
  54. _init_3.setAction(self._init_3_exec)
  55. _init_3.setTrigger(Event("raw_inp", "user_inp"))
  56. self.states["/init"].addTransition(_init_3)
  57. def _init_enter(self):
  58. self.addTimer(0, 0.1)
  59. def _init_exit(self):
  60. self.removeTimer(0)
  61. def _init_0_exec(self, parameters):
  62. value = parameters[0]
  63. print(value)
  64. def _init_3_exec(self, parameters):
  65. inp = parameters[0]
  66. print("Got raw input")
  67. self.big_step.outputEvent(Event("output", "outp", [inp]))
  68. def initializeStatechart(self):
  69. # enter default state
  70. self.default_targets = self.states["/init"].getEffectiveTargetStates()
  71. RuntimeClassBase.initializeStatechart(self)
  72. class ObjectManager(ObjectManagerBase):
  73. def __init__(self, controller):
  74. ObjectManagerBase.__init__(self, controller)
  75. def instantiate(self, class_name, construct_params):
  76. if class_name == "Logging":
  77. instance = Logging(self.controller)
  78. instance.associations = {}
  79. else:
  80. raise Exception("Cannot instantiate class " + class_name)
  81. return instance
  82. class Controller(ThreadsControllerBase):
  83. def __init__(self, keep_running = None, behind_schedule_callback = None):
  84. if keep_running == None: keep_running = True
  85. if behind_schedule_callback == None: behind_schedule_callback = None
  86. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  87. self.addInputPort("user_inp")
  88. self.addInputPort("inp")
  89. self.addOutputPort("outp")
  90. self.object_manager.createInstance("Logging", [])