history.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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: TestHistory
  5. Model description:
  6. Testing the History state.*/
  7. // package "TestHistory"
  8. var TestHistory = {};
  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 /composite_1
  38. this.states["/composite_1"] = new State(1, this);
  39. // state /composite_1/state_1
  40. this.states["/composite_1/state_1"] = new State(2, this);
  41. this.states["/composite_1/state_1"].setEnter(this._composite_1_state_1_enter);
  42. // state /composite_1/state_2
  43. this.states["/composite_1/state_2"] = new State(3, this);
  44. this.states["/composite_1/state_2"].setEnter(this._composite_1_state_2_enter);
  45. // state /composite_1/composite_history
  46. this.states["/composite_1/composite_history"] = new ShallowHistoryState(4, this);
  47. // state /state_3
  48. this.states["/state_3"] = new State(5, this);
  49. this.states["/state_3"].setEnter(this._state_3_enter);
  50. // add children
  51. this.states[""].addChild(this.states["/composite_1"]);
  52. this.states[""].addChild(this.states["/state_3"]);
  53. this.states["/composite_1"].addChild(this.states["/composite_1/state_1"]);
  54. this.states["/composite_1"].addChild(this.states["/composite_1/state_2"]);
  55. this.states["/composite_1"].addChild(this.states["/composite_1/composite_history"]);
  56. this.states[""].fixTree();
  57. this.states[""].default_state = this.states["/composite_1"];
  58. this.states["/composite_1"].default_state = this.states["/composite_1/state_1"];
  59. // transition /composite_1/state_1
  60. var _composite_1_state_1_0 = new Transition(this, this.states["/composite_1/state_1"], [this.states["/composite_1/state_2"]]);
  61. _composite_1_state_1_0.setTrigger(new Event("to_state_2", "test_input"));
  62. this.states["/composite_1/state_1"].addTransition(_composite_1_state_1_0);
  63. // transition /state_3
  64. var _state_3_0 = new Transition(this, this.states["/state_3"], [this.states["/composite_1/composite_history"]]);
  65. _state_3_0.setTrigger(null);
  66. this.states["/state_3"].addTransition(_state_3_0);
  67. // transition /composite_1
  68. var _composite_1_0 = new Transition(this, this.states["/composite_1"], [this.states["/state_3"]]);
  69. _composite_1_0.setTrigger(new Event("to_state_3", "test_input"));
  70. this.states["/composite_1"].addTransition(_composite_1_0);
  71. };
  72. Class1.prototype._composite_1_state_1_enter = function() {
  73. this.big_step.outputEvent(new Event("in_state_1", "test_output", new Array()));
  74. };
  75. Class1.prototype._composite_1_state_2_enter = function() {
  76. this.big_step.outputEvent(new Event("in_state_2", "test_output", new Array()));
  77. };
  78. Class1.prototype._state_3_enter = function() {
  79. this.big_step.outputEvent(new Event("in_state_3", "test_output", new Array()));
  80. };
  81. Class1.prototype.initializeStatechart = function() {
  82. // enter default state
  83. var states = this.states["/composite_1"].getEffectiveTargetStates();
  84. this.updateConfiguration(states);
  85. for (var state_idx in states) {
  86. if (!states.hasOwnProperty(state_idx)) continue;
  87. var state = states[state_idx]
  88. if (state.enter) {
  89. state.enter();
  90. }
  91. }
  92. };
  93. // add symbol 'Class1' to package 'TestHistory'
  94. TestHistory.Class1 = Class1;
  95. var ObjectManager = function(controller) {
  96. ObjectManagerBase.call(this, controller);
  97. };
  98. ObjectManager.prototype = new Object();
  99. (function() {
  100. var proto = new ObjectManagerBase();
  101. for (prop in proto) {
  102. ObjectManager.prototype[prop] = proto[prop];
  103. }
  104. })();
  105. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  106. if (class_name === "Class1") {
  107. var instance = new Class1(this.controller);
  108. instance.associations = new Object();
  109. } else {
  110. throw new Error("Cannot instantiate class " + class_name);
  111. }
  112. return instance;
  113. };
  114. // add symbol 'ObjectManager' to package 'TestHistory'
  115. TestHistory.ObjectManager = ObjectManager;
  116. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  117. if (finished_callback === undefined) finished_callback = null;
  118. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  119. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  120. this.addInputPort("test_input");
  121. this.addOutputPort("test_output");
  122. this.object_manager.createInstance("Class1", new Array());
  123. };
  124. Controller.prototype = new Object();
  125. (function() {
  126. var proto = new EventLoopControllerBase();
  127. for (prop in proto) {
  128. Controller.prototype[prop] = proto[prop];
  129. }
  130. })();
  131. // add symbol 'Controller' to package 'TestHistory'
  132. TestHistory.Controller = Controller;
  133. var InputEvent = function(name, port, parameters, time_offset) {
  134. this.name = name;
  135. this.port = port;
  136. this.parameters = parameters;
  137. this.time_offset = time_offset;
  138. };
  139. // add symbol 'InputEvent' to package 'TestHistory'
  140. TestHistory.InputEvent = InputEvent;
  141. var Test = function() {
  142. };
  143. Test.prototype.input_events = [new InputEvent("to_state_2", "test_input", new Array(), 0.0), new InputEvent("to_state_3", "test_input", new Array(), 0.0)];
  144. Test.prototype.expected_events = [[new Event("in_state_1", "test_output", new Array())], [new Event("in_state_2", "test_output", new Array())], [new Event("in_state_3", "test_output", new Array())], [new Event("in_state_2", "test_output", new Array())]];
  145. // add symbol 'Test' to package 'TestHistory'
  146. TestHistory.Test = Test;
  147. })();