interface.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Sun Oct 15 20:24:57 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("mv_input", "input"))
  45. self.states["/running"].addTransition(_running_1)
  46. def _running_0_exec(self, parameters):
  47. params = parameters[0]
  48. print 'sending output to the console'
  49. self.big_step.outputEvent(Event("mv_output", "output", [params]))
  50. def _running_1_exec(self, parameters):
  51. params = parameters[0]
  52. print 'sending output to the modelverse'
  53. self.big_step.outputEvent(Event("output", "mv_output", [params]))
  54. def initializeStatechart(self):
  55. # enter default state
  56. self.default_targets = self.states["/running"].getEffectiveTargetStates()
  57. RuntimeClassBase.initializeStatechart(self)
  58. class ObjectManager(ObjectManagerBase):
  59. def __init__(self, controller):
  60. ObjectManagerBase.__init__(self, controller)
  61. def instantiate(self, class_name, construct_params):
  62. if class_name == "Interface":
  63. instance = Interface(self.controller)
  64. instance.associations = {}
  65. else:
  66. raise Exception("Cannot instantiate class " + class_name)
  67. return instance
  68. class Controller(ThreadsControllerBase):
  69. def __init__(self, keep_running = None, behind_schedule_callback = None):
  70. if keep_running == None: keep_running = True
  71. if behind_schedule_callback == None: behind_schedule_callback = None
  72. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  73. self.addInputPort("input")
  74. self.addInputPort("mv_input")
  75. self.addOutputPort("output")
  76. self.addOutputPort("mv_output")
  77. self.object_manager.createInstance("Interface", [])