associate_event.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Tue Aug 09 09:35:52 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. this.default_targets = this.states["/start"].getEffectiveTargetStates();
  71. RuntimeClassBase.prototype.initializeStatechart.call(this);
  72. };
  73. // add symbol 'Class1' to package 'TestAssociateEvent'
  74. TestAssociateEvent.Class1 = Class1;
  75. var Class2 = function(controller) {
  76. RuntimeClassBase.call(this, controller);
  77. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  78. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  79. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  80. this.semantics.priority = StatechartSemantics.SourceParent;
  81. this.semantics.concurrency = StatechartSemantics.Single;
  82. // build Statechart structure
  83. this.build_statechart_structure();
  84. // call user defined constructor
  85. Class2.prototype.user_defined_constructor.call(this);
  86. };
  87. Class2.prototype = new Object();
  88. (function() {
  89. var proto = new RuntimeClassBase();
  90. for (prop in proto) {
  91. Class2.prototype[prop] = proto[prop];
  92. }
  93. })();
  94. Class2.prototype.user_defined_constructor = function() {
  95. };
  96. Class2.prototype.user_defined_destructor = function() {
  97. };
  98. // builds Statechart structure
  99. Class2.prototype.build_statechart_structure = function() {
  100. // state <root>
  101. this.states[""] = new State(0, this);
  102. // state /start
  103. this.states["/start"] = new State(1, this);
  104. // add children
  105. this.states[""].addChild(this.states["/start"]);
  106. this.states[""].fixTree();
  107. this.states[""].default_state = this.states["/start"];
  108. // transition /start
  109. var _start_0 = new Transition(this, this.states["/start"], [this.states["/start"]]);
  110. _start_0.setAction(this._start_0_exec);
  111. _start_0.setTrigger(new Event("hello", null));
  112. this.states["/start"].addTransition(_start_0);
  113. };
  114. Class2.prototype._start_0_exec = function(parameters) {
  115. this.big_step.outputEvent(new Event("second_working", "test_output", new Array()));
  116. };
  117. Class2.prototype.initializeStatechart = function() {
  118. // enter default state
  119. this.default_targets = this.states["/start"].getEffectiveTargetStates();
  120. RuntimeClassBase.prototype.initializeStatechart.call(this);
  121. };
  122. // add symbol 'Class2' to package 'TestAssociateEvent'
  123. TestAssociateEvent.Class2 = Class2;
  124. var ObjectManager = function(controller) {
  125. ObjectManagerBase.call(this, controller);
  126. };
  127. ObjectManager.prototype = new Object();
  128. (function() {
  129. var proto = new ObjectManagerBase();
  130. for (prop in proto) {
  131. ObjectManager.prototype[prop] = proto[prop];
  132. }
  133. })();
  134. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  135. if (class_name === "Class1") {
  136. var instance = new Class1(this.controller);
  137. instance.associations = new Object();
  138. instance.associations["test2_association"] = new Association("Class2", 0, -1);
  139. instance.associations["test3_association"] = new Association("Class2", 0, -1);
  140. } else if (class_name === "Class2") {
  141. var instance = new Class2(this.controller);
  142. instance.associations = new Object();
  143. } else {
  144. throw new Error("Cannot instantiate class " + class_name);
  145. }
  146. return instance;
  147. };
  148. // add symbol 'ObjectManager' to package 'TestAssociateEvent'
  149. TestAssociateEvent.ObjectManager = ObjectManager;
  150. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  151. if (finished_callback === undefined) finished_callback = null;
  152. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  153. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  154. this.addInputPort("test_input");
  155. this.addOutputPort("test_output");
  156. this.object_manager.createInstance("Class1", new Array());
  157. };
  158. Controller.prototype = new Object();
  159. (function() {
  160. var proto = new EventLoopControllerBase();
  161. for (prop in proto) {
  162. Controller.prototype[prop] = proto[prop];
  163. }
  164. })();
  165. // add symbol 'Controller' to package 'TestAssociateEvent'
  166. TestAssociateEvent.Controller = Controller;
  167. var InputEvent = function(name, port, parameters, time_offset) {
  168. this.name = name;
  169. this.port = port;
  170. this.parameters = parameters;
  171. this.time_offset = time_offset;
  172. };
  173. // add symbol 'InputEvent' to package 'TestAssociateEvent'
  174. TestAssociateEvent.InputEvent = InputEvent;
  175. var Test = function() {
  176. };
  177. Test.prototype.input_events = [new InputEvent("create", "test_input", new Array(), 0.0)];
  178. 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())]];
  179. // add symbol 'Test' to package 'TestAssociateEvent'
  180. TestAssociateEvent.Test = Test;
  181. })();