after_0.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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: Yentl Van Tendeloo
  4. Model name: after_0
  5. Model description:
  6. Used for testing the AFTER(0) event---which should not block the deletion of the B instance.*/
  7. // package "after_0"
  8. var after_0 = {};
  9. (function() {
  10. var A = 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. A.prototype.user_defined_constructor.call(this);
  21. };
  22. A.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. A.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. A.prototype.user_defined_constructor = function() {
  30. };
  31. A.prototype.user_defined_destructor = function() {
  32. };
  33. // builds Statechart structure
  34. A.prototype.build_statechart_structure = function() {
  35. // state <root>
  36. this.states[""] = new State(0, this);
  37. // state /x
  38. this.states["/x"] = new State(1, this);
  39. this.states["/x"].setEnter(this._x_enter);
  40. // state /ready
  41. this.states["/ready"] = new State(2, this);
  42. this.states["/ready"].setEnter(this._ready_enter);
  43. // state /done
  44. this.states["/done"] = new State(3, this);
  45. // add children
  46. this.states[""].addChild(this.states["/x"]);
  47. this.states[""].addChild(this.states["/ready"]);
  48. this.states[""].addChild(this.states["/done"]);
  49. this.states[""].fixTree();
  50. this.states[""].default_state = this.states["/x"];
  51. // transition /x
  52. var _x_0 = new Transition(this, this.states["/x"], [this.states["/ready"]]);
  53. _x_0.setTrigger(new Event("instance_created", null));
  54. this.states["/x"].addTransition(_x_0);
  55. // transition /ready
  56. var _ready_0 = new Transition(this, this.states["/ready"], [this.states["/done"]]);
  57. _ready_0.setAction(this._ready_0_exec);
  58. _ready_0.setTrigger(new Event("close", null));
  59. this.states["/ready"].addTransition(_ready_0);
  60. };
  61. A.prototype._x_enter = function() {
  62. this.big_step.outputEventOM(new Event("create_instance", null, [this, 'child', 'B']));
  63. this.big_step.outputEvent(new Event("creating_instance", "test_output", new Array()));
  64. };
  65. A.prototype._ready_enter = function() {
  66. this.big_step.outputEventOM(new Event("start_instance", null, [this, 'child[0]']));
  67. this.big_step.outputEvent(new Event("starting_instance", "test_output", new Array()));
  68. };
  69. A.prototype._ready_0_exec = function(parameters) {
  70. this.big_step.outputEventOM(new Event("delete_instance", null, [this, 'child[0]']));
  71. this.big_step.outputEvent(new Event("deleting_instance", "test_output", new Array()));
  72. };
  73. A.prototype.initializeStatechart = function() {
  74. // enter default state
  75. var states = this.states["/x"].getEffectiveTargetStates();
  76. this.updateConfiguration(states);
  77. for (var state_idx in states) {
  78. if (!states.hasOwnProperty(state_idx)) continue;
  79. var state = states[state_idx]
  80. if (state.enter) {
  81. state.enter();
  82. }
  83. }
  84. };
  85. // add symbol 'A' to package 'after_0'
  86. after_0.A = A;
  87. var B = function(controller) {
  88. RuntimeClassBase.call(this, controller);
  89. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  90. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  91. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  92. this.semantics.priority = StatechartSemantics.SourceParent;
  93. this.semantics.concurrency = StatechartSemantics.Single;
  94. // build Statechart structure
  95. this.build_statechart_structure();
  96. // call user defined constructor
  97. B.prototype.user_defined_constructor.call(this);
  98. };
  99. B.prototype = new Object();
  100. (function() {
  101. var proto = new RuntimeClassBase();
  102. for (prop in proto) {
  103. B.prototype[prop] = proto[prop];
  104. }
  105. })();
  106. B.prototype.user_defined_constructor = function() {
  107. };
  108. B.prototype.user_defined_destructor = function() {
  109. };
  110. // builds Statechart structure
  111. B.prototype.build_statechart_structure = function() {
  112. // state <root>
  113. this.states[""] = new State(0, this);
  114. // state /z
  115. this.states["/z"] = new State(1, this);
  116. this.states["/z"].setEnter(this._z_enter);
  117. this.states["/z"].setExit(this._z_exit);
  118. // add children
  119. this.states[""].addChild(this.states["/z"]);
  120. this.states[""].fixTree();
  121. this.states[""].default_state = this.states["/z"];
  122. // transition /z
  123. var _z_0 = new Transition(this, this.states["/z"], [this.states["/z"]]);
  124. _z_0.setAction(this._z_0_exec);
  125. _z_0.setTrigger(new Event("_0after"));
  126. this.states["/z"].addTransition(_z_0);
  127. };
  128. B.prototype._z_enter = function() {
  129. this.addTimer(0, 0);
  130. };
  131. B.prototype._z_exit = function() {
  132. this.removeTimer(0);
  133. };
  134. B.prototype._z_0_exec = function(parameters) {
  135. this.big_step.outputEventOM(new Event("broad_cast", null, [new Event("close", null, new Array())]));
  136. this.big_step.outputEvent(new Event("after_0", "test_output", new Array()));
  137. };
  138. B.prototype.initializeStatechart = function() {
  139. // enter default state
  140. var states = this.states["/z"].getEffectiveTargetStates();
  141. this.updateConfiguration(states);
  142. for (var state_idx in states) {
  143. if (!states.hasOwnProperty(state_idx)) continue;
  144. var state = states[state_idx]
  145. if (state.enter) {
  146. state.enter();
  147. }
  148. }
  149. };
  150. // add symbol 'B' to package 'after_0'
  151. after_0.B = B;
  152. var ObjectManager = function(controller) {
  153. ObjectManagerBase.call(this, controller);
  154. };
  155. ObjectManager.prototype = new Object();
  156. (function() {
  157. var proto = new ObjectManagerBase();
  158. for (prop in proto) {
  159. ObjectManager.prototype[prop] = proto[prop];
  160. }
  161. })();
  162. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  163. if (class_name === "A") {
  164. var instance = new A(this.controller);
  165. instance.associations = new Object();
  166. instance.associations["child"] = new Association("B", 0, 1);
  167. } else if (class_name === "B") {
  168. var instance = new B(this.controller);
  169. instance.associations = new Object();
  170. instance.associations["parent"] = new Association("A", 1, 1);
  171. } else {
  172. throw new Error("Cannot instantiate class " + class_name);
  173. }
  174. return instance;
  175. };
  176. // add symbol 'ObjectManager' to package 'after_0'
  177. after_0.ObjectManager = ObjectManager;
  178. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  179. if (finished_callback === undefined) finished_callback = null;
  180. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  181. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  182. this.addOutputPort("test_output");
  183. this.object_manager.createInstance("A", new Array());
  184. };
  185. Controller.prototype = new Object();
  186. (function() {
  187. var proto = new EventLoopControllerBase();
  188. for (prop in proto) {
  189. Controller.prototype[prop] = proto[prop];
  190. }
  191. })();
  192. // add symbol 'Controller' to package 'after_0'
  193. after_0.Controller = Controller;
  194. var InputEvent = function(name, port, parameters, time_offset) {
  195. this.name = name;
  196. this.port = port;
  197. this.parameters = parameters;
  198. this.time_offset = time_offset;
  199. };
  200. // add symbol 'InputEvent' to package 'after_0'
  201. after_0.InputEvent = InputEvent;
  202. var Test = function() {
  203. };
  204. Test.prototype.input_events = new Array();
  205. Test.prototype.expected_events = [[new Event("creating_instance", "test_output", new Array())], [new Event("starting_instance", "test_output", new Array())], [new Event("after_0", "test_output", new Array())], [new Event("deleting_instance", "test_output", new Array()), new Event("after_0", "test_output", new Array())]];
  206. // add symbol 'Test' to package 'after_0'
  207. after_0.Test = Test;
  208. })();