interface.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Sep 29 15:11:02 2017
  4. Model author: Simon Van Mierlo
  5. Model name: Translational Semantics Debugging Interface
  6. Model description:
  7. A debugging interface for a formalism with translational semantics.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "Translational Semantics Debugging Interface"
  11. class Interface(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. Interface.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 /running
  32. self.states["/running"] = State(1, "/running", self)
  33. # add children
  34. self.states[""].addChild(self.states["/running"])
  35. self.states[""].fixTree()
  36. self.states[""].default_state = self.states["/running"]
  37. # transition /running
  38. _running_0 = Transition(self, self.states["/running"], [self.states["/running"]])
  39. _running_0.setAction(self._running_0_exec)
  40. _running_0.setTrigger(Event("input", "mv_input"))
  41. self.states["/running"].addTransition(_running_0)
  42. _running_1 = Transition(self, self.states["/running"], [self.states["/running"]])
  43. _running_1.setAction(self._running_1_exec)
  44. _running_1.setTrigger(Event("input", "input"))
  45. self.states["/running"].addTransition(_running_1)
  46. def _running_0_exec(self, parameters):
  47. params = parameters[0]
  48. self.big_step.outputEvent(Event("mv_output", "output", [params]))
  49. def _running_1_exec(self, parameters):
  50. params = parameters[0]
  51. self.big_step.outputEvent(Event("output", "mv_output", [params]))
  52. def initializeStatechart(self):
  53. # enter default state
  54. self.default_targets = self.states["/running"].getEffectiveTargetStates()
  55. RuntimeClassBase.initializeStatechart(self)
  56. class ObjectManager(ObjectManagerBase):
  57. def __init__(self, controller):
  58. ObjectManagerBase.__init__(self, controller)
  59. def instantiate(self, class_name, construct_params):
  60. if class_name == "Interface":
  61. instance = Interface(self.controller)
  62. instance.associations = {}
  63. else:
  64. raise Exception("Cannot instantiate class " + class_name)
  65. return instance
  66. class Controller(ThreadsControllerBase):
  67. def __init__(self, keep_running = None, behind_schedule_callback = None):
  68. if keep_running == None: keep_running = True
  69. if behind_schedule_callback == None: behind_schedule_callback = None
  70. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  71. self.addInputPort("input")
  72. self.addInputPort("mv_input")
  73. self.addOutputPort("output")
  74. self.addOutputPort("mv_output")
  75. self.object_manager.createInstance("Interface", [])