associate_event.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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: TestAssociateEvent
  5. Model description:
  6. Testing the object manager*/
  7. // package "TestAssociateEvent"
  8. var TestAssociateEvent = {};
  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 /start
  38. this.states["/start"] = new State(1, this);
  39. // state /wait
  40. this.states["/wait"] = new State(2, this);
  41. // add children
  42. this.states[""].addChild(this.states["/start"]);
  43. this.states[""].addChild(this.states["/wait"]);
  44. this.states[""].fixTree();
  45. this.states[""].default_state = this.states["/start"];
  46. // transition /start
  47. var _start_0 = new Transition(this, this.states["/start"], [this.states["/wait"]]);
  48. _start_0.setAction(this._start_0_exec);
  49. _start_0.setTrigger(new Event("create", "test_input"));
  50. this.states["/start"].addTransition(_start_0);
  51. // transition /wait
  52. var _wait_0 = new Transition(this, this.states["/wait"], [this.states["/start"]]);
  53. _wait_0.setAction(this._wait_0_exec);
  54. _wait_0.setTrigger(new Event("instance_created", null));
  55. this.states["/wait"].addTransition(_wait_0);
  56. };
  57. Class1.prototype._start_0_exec = function(parameters) {
  58. this.big_step.outputEventOM(new Event("create_instance", null, [this, "test2_association"]));
  59. this.big_step.outputEvent(new Event("request_send", "test_output", new Array()));
  60. };
  61. Class1.prototype._wait_0_exec = function(parameters) {
  62. var association_name = parameters[0];
  63. this.big_step.outputEvent(new Event("instance_created", "test_output", new Array()));
  64. this.big_step.outputEventOM(new Event("start_instance", null, [this, "test2_association"]));
  65. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, "test2_association", new Event("hello", null, new Array())]));
  66. this.big_step.outputEventOM(new Event("associate_instance", null, [this, "test2_association", "test3_association"]));
  67. };
  68. Class1.prototype.initializeStatechart = function() {
  69. // enter default state
  70. var states = this.states["/start"].getEffectiveTargetStates();
  71. this.updateConfiguration(states);
  72. for (var state_idx in states) {
  73. if (!states.hasOwnProperty(state_idx)) continue;
  74. var state = states[state_idx]
  75. if (state.enter) {
  76. state.enter();
  77. }
  78. }
  79. };
  80. // add symbol 'Class1' to package 'TestAssociateEvent'
  81. TestAssociateEvent.Class1 = Class1;
  82. var Class2 = function(controller) {
  83. RuntimeClassBase.call(this, controller);
  84. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  85. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  86. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  87. this.semantics.priority = StatechartSemantics.SourceParent;
  88. this.semantics.concurrency = StatechartSemantics.Single;
  89. // build Statechart structure
  90. this.build_statechart_structure();
  91. // call user defined constructor
  92. Class2.prototype.user_defined_constructor.call(this);
  93. };
  94. Class2.prototype = new Object();
  95. (function() {
  96. var proto = new RuntimeClassBase();
  97. for (prop in proto) {
  98. Class2.prototype[prop] = proto[prop];
  99. }
  100. })();
  101. Class2.prototype.user_defined_constructor = function() {
  102. };
  103. Class2.prototype.user_defined_destructor = function() {
  104. };
  105. // builds Statechart structure
  106. Class2.prototype.build_statechart_structure = function() {
  107. // state <root>
  108. this.states[""] = new State(0, this);
  109. // state /start
  110. this.states["/start"] = new State(1, this);
  111. // add children
  112. this.states[""].addChild(this.states["/start"]);
  113. this.states[""].fixTree();
  114. this.states[""].default_state = this.states["/start"];
  115. // transition /start
  116. var _start_0 = new Transition(this, this.states["/start"], [this.states["/start"]]);
  117. _start_0.setAction(this._start_0_exec);
  118. _start_0.setTrigger(new Event("hello", null));
  119. this.states["/start"].addTransition(_start_0);
  120. };
  121. Class2.prototype._start_0_exec = function(parameters) {
  122. this.big_step.outputEvent(new Event("second_working", "test_output", new Array()));
  123. };
  124. Class2.prototype.initializeStatechart = function() {
  125. // enter default state
  126. var states = this.states["/start"].getEffectiveTargetStates();
  127. this.updateConfiguration(states);
  128. for (var state_idx in states) {
  129. if (!states.hasOwnProperty(state_idx)) continue;
  130. var state = states[state_idx]
  131. if (state.enter) {
  132. state.enter();
  133. }
  134. }
  135. };
  136. // add symbol 'Class2' to package 'TestAssociateEvent'
  137. TestAssociateEvent.Class2 = Class2;
  138. var ObjectManager = function(controller) {
  139. ObjectManagerBase.call(this, controller);
  140. };
  141. ObjectManager.prototype = new Object();
  142. (function() {
  143. var proto = new ObjectManagerBase();
  144. for (prop in proto) {
  145. ObjectManager.prototype[prop] = proto[prop];
  146. }
  147. })();
  148. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  149. if (class_name === "Class1") {
  150. var instance = new Class1(this.controller);
  151. instance.associations = new Object();
  152. instance.associations["test2_association"] = new Association("Class2", 0, -1);
  153. instance.associations["test3_association"] = new Association("Class2", 0, -1);
  154. } else if (class_name === "Class2") {
  155. var instance = new Class2(this.controller);
  156. instance.associations = new Object();
  157. } else {
  158. throw new Error("Cannot instantiate class " + class_name);
  159. }
  160. return instance;
  161. };
  162. // add symbol 'ObjectManager' to package 'TestAssociateEvent'
  163. TestAssociateEvent.ObjectManager = ObjectManager;
  164. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  165. if (finished_callback === undefined) finished_callback = null;
  166. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  167. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  168. this.addInputPort("test_input");
  169. this.addOutputPort("test_output");
  170. this.object_manager.createInstance("Class1", new Array());
  171. };
  172. Controller.prototype = new Object();
  173. (function() {
  174. var proto = new EventLoopControllerBase();
  175. for (prop in proto) {
  176. Controller.prototype[prop] = proto[prop];
  177. }
  178. })();
  179. // add symbol 'Controller' to package 'TestAssociateEvent'
  180. TestAssociateEvent.Controller = Controller;
  181. var InputEvent = function(name, port, parameters, time_offset) {
  182. this.name = name;
  183. this.port = port;
  184. this.parameters = parameters;
  185. this.time_offset = time_offset;
  186. };
  187. // add symbol 'InputEvent' to package 'TestAssociateEvent'
  188. TestAssociateEvent.InputEvent = InputEvent;
  189. var Test = function() {
  190. };
  191. Test.prototype.input_events = [new InputEvent("create", "test_input", new Array(), 0.0)];
  192. Test.prototype.expected_events = [[new Event("request_send", "test_output", new Array())], [new Event("instance_created", "test_output", new Array())], [new Event("second_working", "test_output", new Array())]];
  193. // add symbol 'Test' to package 'TestAssociateEvent'
  194. TestAssociateEvent.Test = Test;
  195. })();