enter_exit_hierarchy.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Mon Aug 08 09:49:18 2016
  3. Model author: Glenn De Jonghe
  4. Model name: TestEnterExitHierarchy
  5. Model description:
  6. Testing the enter and exit hierarchy.*/
  7. // package "TestEnterExitHierarchy"
  8. var TestEnterExitHierarchy = {};
  9. (function() {
  10. var Class1 = 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.SourceParent;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // call user defined constructor
  20. Class1.prototype.user_defined_constructor.call(this);
  21. };
  22. Class1.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. Class1.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. Class1.prototype.user_defined_constructor = function() {
  30. };
  31. Class1.prototype.user_defined_destructor = function() {
  32. };
  33. // builds Statechart structure
  34. Class1.prototype.build_statechart_structure = function() {
  35. // state <root>
  36. this.states[""] = new State(0, this);
  37. // state /outside
  38. this.states["/outside"] = new State(1, this);
  39. // state /composite
  40. this.states["/composite"] = new State(2, this);
  41. // state /composite/state1
  42. this.states["/composite/state1"] = new State(3, this);
  43. this.states["/composite/state1"].setEnter(this._composite_state1_enter);
  44. this.states["/composite/state1"].setExit(this._composite_state1_exit);
  45. // state /composite/state1/inner1
  46. this.states["/composite/state1/inner1"] = new State(4, this);
  47. this.states["/composite/state1/inner1"].setEnter(this._composite_state1_inner1_enter);
  48. this.states["/composite/state1/inner1"].setExit(this._composite_state1_inner1_exit);
  49. // state /composite/state1/inner2
  50. this.states["/composite/state1/inner2"] = new State(5, this);
  51. this.states["/composite/state1/inner2"].setEnter(this._composite_state1_inner2_enter);
  52. this.states["/composite/state1/inner2"].setExit(this._composite_state1_inner2_exit);
  53. // state /composite/state2
  54. this.states["/composite/state2"] = new State(6, this);
  55. this.states["/composite/state2"].setEnter(this._composite_state2_enter);
  56. this.states["/composite/state2"].setExit(this._composite_state2_exit);
  57. // state /composite/state2/inner3
  58. this.states["/composite/state2/inner3"] = new State(7, this);
  59. this.states["/composite/state2/inner3"].setEnter(this._composite_state2_inner3_enter);
  60. this.states["/composite/state2/inner3"].setExit(this._composite_state2_inner3_exit);
  61. // state /composite/state2/inner4
  62. this.states["/composite/state2/inner4"] = new State(8, this);
  63. this.states["/composite/state2/inner4"].setEnter(this._composite_state2_inner4_enter);
  64. this.states["/composite/state2/inner4"].setExit(this._composite_state2_inner4_exit);
  65. // add children
  66. this.states[""].addChild(this.states["/outside"]);
  67. this.states[""].addChild(this.states["/composite"]);
  68. this.states["/composite"].addChild(this.states["/composite/state1"]);
  69. this.states["/composite"].addChild(this.states["/composite/state2"]);
  70. this.states["/composite/state1"].addChild(this.states["/composite/state1/inner1"]);
  71. this.states["/composite/state1"].addChild(this.states["/composite/state1/inner2"]);
  72. this.states["/composite/state2"].addChild(this.states["/composite/state2/inner3"]);
  73. this.states["/composite/state2"].addChild(this.states["/composite/state2/inner4"]);
  74. this.states[""].fixTree();
  75. this.states[""].default_state = this.states["/outside"];
  76. this.states["/composite"].default_state = this.states["/composite/state1"];
  77. this.states["/composite/state1"].default_state = this.states["/composite/state1/inner1"];
  78. this.states["/composite/state2"].default_state = this.states["/composite/state2/inner3"];
  79. // transition /outside
  80. var _outside_0 = new Transition(this, this.states["/outside"], [this.states["/composite"]]);
  81. _outside_0.setTrigger(new Event("to_composite", "test_input"));
  82. this.states["/outside"].addTransition(_outside_0);
  83. var _outside_1 = new Transition(this, this.states["/outside"], [this.states["/composite/state2/inner3"]]);
  84. _outside_1.setTrigger(new Event("to_inner3", "test_input"));
  85. this.states["/outside"].addTransition(_outside_1);
  86. var _outside_2 = new Transition(this, this.states["/outside"], [this.states["/composite/state2/inner4"]]);
  87. _outside_2.setTrigger(new Event("to_inner4", "test_input"));
  88. this.states["/outside"].addTransition(_outside_2);
  89. // transition /composite/state1/inner1
  90. var _composite_state1_inner1_0 = new Transition(this, this.states["/composite/state1/inner1"], [this.states["/composite/state1/inner2"]]);
  91. _composite_state1_inner1_0.setTrigger(new Event("to_inner2", "test_input"));
  92. this.states["/composite/state1/inner1"].addTransition(_composite_state1_inner1_0);
  93. // transition /composite
  94. var _composite_0 = new Transition(this, this.states["/composite"], [this.states["/outside"]]);
  95. _composite_0.setTrigger(new Event("to_outside", "test_input"));
  96. this.states["/composite"].addTransition(_composite_0);
  97. };
  98. Class1.prototype._composite_state1_enter = function() {
  99. this.big_step.outputEvent(new Event("enter_state1", "test_output", new Array()));
  100. };
  101. Class1.prototype._composite_state1_exit = function() {
  102. this.big_step.outputEvent(new Event("exit_state1", "test_output", new Array()));
  103. };
  104. Class1.prototype._composite_state2_enter = function() {
  105. this.big_step.outputEvent(new Event("enter_state2", "test_output", new Array()));
  106. };
  107. Class1.prototype._composite_state2_exit = function() {
  108. this.big_step.outputEvent(new Event("exit_state2", "test_output", new Array()));
  109. };
  110. Class1.prototype._composite_state1_inner1_enter = function() {
  111. this.big_step.outputEvent(new Event("enter_inner1", "test_output", new Array()));
  112. };
  113. Class1.prototype._composite_state1_inner1_exit = function() {
  114. this.big_step.outputEvent(new Event("exit_inner1", "test_output", new Array()));
  115. };
  116. Class1.prototype._composite_state1_inner2_enter = function() {
  117. this.big_step.outputEvent(new Event("enter_inner2", "test_output", new Array()));
  118. };
  119. Class1.prototype._composite_state1_inner2_exit = function() {
  120. this.big_step.outputEvent(new Event("exit_inner2", "test_output", new Array()));
  121. };
  122. Class1.prototype._composite_state2_inner3_enter = function() {
  123. this.big_step.outputEvent(new Event("enter_inner3", "test_output", new Array()));
  124. };
  125. Class1.prototype._composite_state2_inner3_exit = function() {
  126. this.big_step.outputEvent(new Event("exit_inner3", "test_output", new Array()));
  127. };
  128. Class1.prototype._composite_state2_inner4_enter = function() {
  129. this.big_step.outputEvent(new Event("enter_inner4", "test_output", new Array()));
  130. };
  131. Class1.prototype._composite_state2_inner4_exit = function() {
  132. this.big_step.outputEvent(new Event("exit_inner4", "test_output", new Array()));
  133. };
  134. Class1.prototype.initializeStatechart = function() {
  135. // enter default state
  136. var states = this.states["/outside"].getEffectiveTargetStates();
  137. this.updateConfiguration(states);
  138. for (var state_idx in states) {
  139. if (!states.hasOwnProperty(state_idx)) continue;
  140. var state = states[state_idx]
  141. if (state.enter) {
  142. state.enter();
  143. }
  144. }
  145. };
  146. // add symbol 'Class1' to package 'TestEnterExitHierarchy'
  147. TestEnterExitHierarchy.Class1 = Class1;
  148. var ObjectManager = function(controller) {
  149. ObjectManagerBase.call(this, controller);
  150. };
  151. ObjectManager.prototype = new Object();
  152. (function() {
  153. var proto = new ObjectManagerBase();
  154. for (prop in proto) {
  155. ObjectManager.prototype[prop] = proto[prop];
  156. }
  157. })();
  158. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  159. if (class_name === "Class1") {
  160. var instance = new Class1(this.controller);
  161. instance.associations = new Object();
  162. } else {
  163. throw new Error("Cannot instantiate class " + class_name);
  164. }
  165. return instance;
  166. };
  167. // add symbol 'ObjectManager' to package 'TestEnterExitHierarchy'
  168. TestEnterExitHierarchy.ObjectManager = ObjectManager;
  169. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  170. if (finished_callback === undefined) finished_callback = null;
  171. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  172. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  173. this.addInputPort("test_input");
  174. this.addOutputPort("test_output");
  175. this.object_manager.createInstance("Class1", new Array());
  176. };
  177. Controller.prototype = new Object();
  178. (function() {
  179. var proto = new EventLoopControllerBase();
  180. for (prop in proto) {
  181. Controller.prototype[prop] = proto[prop];
  182. }
  183. })();
  184. // add symbol 'Controller' to package 'TestEnterExitHierarchy'
  185. TestEnterExitHierarchy.Controller = Controller;
  186. var InputEvent = function(name, port, parameters, time_offset) {
  187. this.name = name;
  188. this.port = port;
  189. this.parameters = parameters;
  190. this.time_offset = time_offset;
  191. };
  192. // add symbol 'InputEvent' to package 'TestEnterExitHierarchy'
  193. TestEnterExitHierarchy.InputEvent = InputEvent;
  194. var Test = function() {
  195. };
  196. Test.prototype.input_events = [new InputEvent("to_composite", "test_input", new Array(), 0.0), new InputEvent("to_inner2", "test_input", new Array(), 0.0), new InputEvent("to_outside", "test_input", new Array(), 0.0), new InputEvent("to_inner3", "test_input", new Array(), 0.0), new InputEvent("to_outside", "test_input", new Array(), 0.0), new InputEvent("to_inner4", "test_input", new Array(), 0.0)];
  197. Test.prototype.expected_events = [[new Event("enter_state1", "test_output", new Array())], [new Event("enter_inner1", "test_output", new Array())], [new Event("exit_inner1", "test_output", new Array())], [new Event("enter_inner2", "test_output", new Array())], [new Event("exit_inner2", "test_output", new Array())], [new Event("exit_state1", "test_output", new Array())], [new Event("enter_state2", "test_output", new Array())], [new Event("enter_inner3", "test_output", new Array())], [new Event("exit_inner3", "test_output", new Array())], [new Event("exit_state2", "test_output", new Array())], [new Event("enter_state2", "test_output", new Array())], [new Event("enter_inner4", "test_output", new Array())]];
  198. // add symbol 'Test' to package 'TestEnterExitHierarchy'
  199. TestEnterExitHierarchy.Test = Test;
  200. })();