object_manager.js 7.9 KB

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