target.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration) and Sam Pieters (DEVS)
  3. Model author: Sam Pieters
  4. Model name: AfterTransitionTest
  5. Model description:
  6. Test 2:
  7. """
  8. from sccd.runtime.DEVS_statecharts_core import *
  9. # package "AfterTransitionTest"
  10. class MainAppInstance(RuntimeClassBase):
  11. def __init__(self, atomdevs, id, start_port_id):
  12. RuntimeClassBase.__init__(self, atomdevs, id)
  13. self.associations = {}
  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. MainAppInstance.user_defined_constructor(self)
  23. port_name = addInputPort("<narrow_cast>", start_port_id)
  24. atomdevs.addInPort(port_name)
  25. atomdevs.state.port_mappings[port_name] = id
  26. def user_defined_constructor(self):
  27. pass
  28. def user_defined_destructor(self):
  29. pass
  30. # builds Statechart structure
  31. def build_statechart_structure(self):
  32. # state <root>
  33. self.states[""] = State(0, "", self)
  34. # state /state1
  35. self.states["/state1"] = State(1, "/state1", self)
  36. # add children
  37. self.states[""].addChild(self.states["/state1"])
  38. self.states[""].fixTree()
  39. self.states[""].default_state = self.states["/state1"]
  40. def initializeStatechart(self):
  41. # enter default state
  42. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  43. RuntimeClassBase.initializeStatechart(self)
  44. class MainApp(ClassBase):
  45. def __init__(self, name):
  46. ClassBase.__init__(self, name)
  47. self.input = self.addInPort("input")
  48. new_instance = self.constructObject(0, 0, [])
  49. self.state.instances[new_instance.instance_id] = new_instance
  50. self.state.next_instance = self.state.next_instance + 1
  51. def constructObject(self, id, start_port_id, parameters):
  52. new_instance = MainAppInstance(self, id, start_port_id)
  53. return new_instance
  54. class Dummy(ObjectManagerState):
  55. def __init__(self):
  56. ObjectManagerState.__init__(self)
  57. def instantiate(self, class_name, construct_params):
  58. instance = {}
  59. instance["name"] = class_name
  60. if class_name == "MainApp":
  61. self.narrow_cast_id = self.narrow_cast_id + 0
  62. instance["associations"] = {}
  63. else:
  64. raise Exception("Cannot instantiate class " + class_name)
  65. return instance
  66. class ObjectManager(ObjectManagerBase):
  67. def __init__(self, name):
  68. ObjectManagerBase.__init__(self, name)
  69. self.state = Dummy()
  70. self.input = self.addInPort("input")
  71. self.output["MainApp"] = self.addOutPort()
  72. self.state.createInstance("MainApp", [])
  73. self.state.to_send.append((("MainApp", 0), ("MainApp", 0), Event("start_instance", None, ["MainApp[0]"])))
  74. class Controller(CoupledDEVS):
  75. def __init__(self, name):
  76. CoupledDEVS.__init__(self, name)
  77. self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
  78. self.atomics = []
  79. self.atomics.append(self.addSubModel(MainApp("MainApp")))
  80. self.connectPorts(self.atomics[0].obj_manager_out, self.objectmanager.input)
  81. self.connectPorts(self.objectmanager.output["MainApp"], self.atomics[0].obj_manager_in)