01_source_child.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Wed Aug 03 16:10:20 2016
  3. Model author: Herr Joeri Exelmans
  4. Model name: source_child
  5. Model description:
  6. 'Source Child' priority-semantics: If 2 transitions are enabled, and the source state of the first is an ancestor of the second, only the second is executed.*/
  7. // package "source_child"
  8. var source_child = {};
  9. (function() {
  10. var c = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  13. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  14. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  15. this.semantics.priority = StatechartSemantics.SourceChild;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // call user defined constructor
  20. c.prototype.user_defined_constructor.call(this);
  21. };
  22. c.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. c.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. c.prototype.user_defined_constructor = function() {
  30. };
  31. c.prototype.user_defined_destructor = function() {
  32. };
  33. // builds Statechart structure
  34. c.prototype.build_statechart_structure = function() {
  35. // state <root>
  36. this.states[""] = new State(0, this);
  37. // state /parent
  38. this.states["/parent"] = new State(1, this);
  39. this.states["/parent"].setEnter(this._parent_enter);
  40. // state /parent/a
  41. this.states["/parent/a"] = new State(2, this);
  42. this.states["/parent/a"].setEnter(this._parent_a_enter);
  43. // state /parent/b
  44. this.states["/parent/b"] = new State(3, this);
  45. this.states["/parent/b"].setEnter(this._parent_b_enter);
  46. // state /c
  47. this.states["/c"] = new State(4, this);
  48. this.states["/c"].setEnter(this._c_enter);
  49. // add children
  50. this.states[""].addChild(this.states["/parent"]);
  51. this.states[""].addChild(this.states["/c"]);
  52. this.states["/parent"].addChild(this.states["/parent/a"]);
  53. this.states["/parent"].addChild(this.states["/parent/b"]);
  54. this.states[""].fixTree();
  55. this.states[""].default_state = this.states["/parent"];
  56. this.states["/parent"].default_state = this.states["/parent/a"];
  57. // transition /parent/a
  58. var _parent_a_0 = new Transition(this, this.states["/parent/a"], [this.states["/parent/b"]]);
  59. this.states["/parent/a"].addTransition(_parent_a_0);
  60. // transition /parent
  61. var _parent_0 = new Transition(this, this.states["/parent"], [this.states["/c"]]);
  62. this.states["/parent"].addTransition(_parent_0);
  63. };
  64. c.prototype._parent_enter = function() {
  65. this.big_step.outputEvent(new Event("entered_parent", "out", new Array()));
  66. };
  67. c.prototype._parent_a_enter = function() {
  68. this.big_step.outputEvent(new Event("entered_a", "out", new Array()));
  69. };
  70. c.prototype._parent_b_enter = function() {
  71. this.big_step.outputEvent(new Event("entered_b", "out", new Array()));
  72. };
  73. c.prototype._c_enter = function() {
  74. this.big_step.outputEvent(new Event("entered_c", "out", new Array()));
  75. };
  76. c.prototype.initializeStatechart = function() {
  77. // enter default state
  78. var states = this.states["/parent"].getEffectiveTargetStates();
  79. this.updateConfiguration(states);
  80. for (var state_idx in states) {
  81. if (!states.hasOwnProperty(state_idx)) continue;
  82. var state = states[state_idx]
  83. if (state.enter) {
  84. state.enter();
  85. }
  86. }
  87. };
  88. // add symbol 'c' to package 'source_child'
  89. source_child.c = c;
  90. var ObjectManager = function(controller) {
  91. ObjectManagerBase.call(this, controller);
  92. };
  93. ObjectManager.prototype = new Object();
  94. (function() {
  95. var proto = new ObjectManagerBase();
  96. for (prop in proto) {
  97. ObjectManager.prototype[prop] = proto[prop];
  98. }
  99. })();
  100. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  101. if (class_name === "c") {
  102. var instance = new c(this.controller);
  103. instance.associations = new Object();
  104. }
  105. return instance;
  106. };
  107. // add symbol 'ObjectManager' to package 'source_child'
  108. source_child.ObjectManager = ObjectManager;
  109. var Controller = function(event_loop_callbacks, finished_callback) {
  110. if (finished_callback === undefined) finished_callback = null;
  111. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback);
  112. this.addInputPort("in");
  113. this.addOutputPort("out");
  114. this.object_manager.createInstance("c", new Array());
  115. };
  116. Controller.prototype = new Object();
  117. (function() {
  118. var proto = new EventLoopControllerBase();
  119. for (prop in proto) {
  120. Controller.prototype[prop] = proto[prop];
  121. }
  122. })();
  123. // add symbol 'Controller' to package 'source_child'
  124. source_child.Controller = Controller;
  125. var InputEvent = function(name, port, parameters, time_offset) {
  126. this.name = name;
  127. this.port = port;
  128. this.parameters = parameters;
  129. this.time_offset = time_offset;
  130. };
  131. // add symbol 'InputEvent' to package 'source_child'
  132. source_child.InputEvent = InputEvent;
  133. var Test = function() {
  134. };
  135. Test.prototype.input_events = new Array();
  136. Test.prototype.expected_events = [[new Event("entered_parent", "out", new Array()), new Event("entered_a", "out", new Array())], [new Event("entered_b", "out", new Array()), new Event("entered_c", "out", new Array())]];
  137. // add symbol 'Test' to package 'source_child'
  138. source_child.Test = Test;
  139. })();