history.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Thu Aug 04 12:51:00 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.trigger = 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. this.states["/state_3"].addTransition(_state_3_0);
  66. // transition /composite_1
  67. var _composite_1_0 = new Transition(this, this.states["/composite_1"], [this.states["/state_3"]]);
  68. _composite_1_0.trigger = new Event("to_state_3", "test_input");
  69. this.states["/composite_1"].addTransition(_composite_1_0);
  70. };
  71. Class1.prototype._composite_1_state_1_enter = function() {
  72. this.big_step.outputEvent(new Event("in_state_1", "test_output", new Array()));
  73. };
  74. Class1.prototype._composite_1_state_2_enter = function() {
  75. this.big_step.outputEvent(new Event("in_state_2", "test_output", new Array()));
  76. };
  77. Class1.prototype._state_3_enter = function() {
  78. this.big_step.outputEvent(new Event("in_state_3", "test_output", new Array()));
  79. };
  80. Class1.prototype.initializeStatechart = function() {
  81. // enter default state
  82. var states = this.states["/composite_1"].getEffectiveTargetStates();
  83. this.updateConfiguration(states);
  84. for (var state_idx in states) {
  85. if (!states.hasOwnProperty(state_idx)) continue;
  86. var state = states[state_idx]
  87. if (state.enter) {
  88. state.enter();
  89. }
  90. }
  91. };
  92. // add symbol 'Class1' to package 'TestHistory'
  93. TestHistory.Class1 = Class1;
  94. var ObjectManager = function(controller) {
  95. ObjectManagerBase.call(this, controller);
  96. };
  97. ObjectManager.prototype = new Object();
  98. (function() {
  99. var proto = new ObjectManagerBase();
  100. for (prop in proto) {
  101. ObjectManager.prototype[prop] = proto[prop];
  102. }
  103. })();
  104. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  105. if (class_name === "Class1") {
  106. var instance = new Class1(this.controller);
  107. instance.associations = new Object();
  108. } else {
  109. throw new Error("Cannot instantiate class " + class_name);
  110. }
  111. return instance;
  112. };
  113. // add symbol 'ObjectManager' to package 'TestHistory'
  114. TestHistory.ObjectManager = ObjectManager;
  115. var Controller = function(event_loop_callbacks, finished_callback) {
  116. if (finished_callback === undefined) finished_callback = null;
  117. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback);
  118. this.addInputPort("test_input");
  119. this.addOutputPort("test_output");
  120. this.object_manager.createInstance("Class1", new Array());
  121. };
  122. Controller.prototype = new Object();
  123. (function() {
  124. var proto = new EventLoopControllerBase();
  125. for (prop in proto) {
  126. Controller.prototype[prop] = proto[prop];
  127. }
  128. })();
  129. // add symbol 'Controller' to package 'TestHistory'
  130. TestHistory.Controller = Controller;
  131. var InputEvent = function(name, port, parameters, time_offset) {
  132. this.name = name;
  133. this.port = port;
  134. this.parameters = parameters;
  135. this.time_offset = time_offset;
  136. };
  137. // add symbol 'InputEvent' to package 'TestHistory'
  138. TestHistory.InputEvent = InputEvent;
  139. var Test = function() {
  140. };
  141. 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)];
  142. 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())]];
  143. // add symbol 'Test' to package 'TestHistory'
  144. TestHistory.Test = Test;
  145. })();