after.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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: TestAfter
  5. Model description:
  6. Used for testing the AFTER event.*/
  7. // package "TestAfter"
  8. var TestAfter = {};
  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
  38. this.states["/composite"] = new State(1, this);
  39. // state /composite/state_1
  40. this.states["/composite/state_1"] = new State(2, this);
  41. this.states["/composite/state_1"].setEnter(this._composite_state_1_enter);
  42. this.states["/composite/state_1"].setExit(this._composite_state_1_exit);
  43. // state /composite/state_2
  44. this.states["/composite/state_2"] = new State(3, this);
  45. this.states["/composite/state_2"].setEnter(this._composite_state_2_enter);
  46. // state /composite/state_3
  47. this.states["/composite/state_3"] = new State(4, this);
  48. this.states["/composite/state_3"].setEnter(this._composite_state_3_enter);
  49. // add children
  50. this.states[""].addChild(this.states["/composite"]);
  51. this.states["/composite"].addChild(this.states["/composite/state_1"]);
  52. this.states["/composite"].addChild(this.states["/composite/state_2"]);
  53. this.states["/composite"].addChild(this.states["/composite/state_3"]);
  54. this.states[""].fixTree();
  55. this.states[""].default_state = this.states["/composite"];
  56. this.states["/composite"].default_state = this.states["/composite/state_1"];
  57. // transition /composite/state_1
  58. var _composite_state_1_0 = new Transition(this, this.states["/composite/state_1"], [this.states["/composite/state_2"]]);
  59. _composite_state_1_0.setTrigger(new Event("_0after"));
  60. this.states["/composite/state_1"].addTransition(_composite_state_1_0);
  61. var _composite_state_1_1 = new Transition(this, this.states["/composite/state_1"], [this.states["/composite/state_3"]]);
  62. _composite_state_1_1.setTrigger(new Event("_1after"));
  63. this.states["/composite/state_1"].addTransition(_composite_state_1_1);
  64. };
  65. Class1.prototype._composite_state_1_enter = function() {
  66. this.addTimer(0, 0.1);
  67. this.addTimer(1, 0.2);
  68. };
  69. Class1.prototype._composite_state_1_exit = function() {
  70. this.removeTimer(0);
  71. this.removeTimer(1);
  72. };
  73. Class1.prototype._composite_state_2_enter = function() {
  74. this.big_step.outputEvent(new Event("in_state_2", "test_output", new Array()));
  75. };
  76. Class1.prototype._composite_state_3_enter = function() {
  77. this.big_step.outputEvent(new Event("in_state_3", "test_output", new Array()));
  78. };
  79. Class1.prototype.initializeStatechart = function() {
  80. // enter default state
  81. this.default_targets = this.states["/composite"].getEffectiveTargetStates();
  82. RuntimeClassBase.prototype.initializeStatechart.call(this);
  83. };
  84. // add symbol 'Class1' to package 'TestAfter'
  85. TestAfter.Class1 = Class1;
  86. var ObjectManager = function(controller) {
  87. ObjectManagerBase.call(this, controller);
  88. };
  89. ObjectManager.prototype = new Object();
  90. (function() {
  91. var proto = new ObjectManagerBase();
  92. for (prop in proto) {
  93. ObjectManager.prototype[prop] = proto[prop];
  94. }
  95. })();
  96. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  97. if (class_name === "Class1") {
  98. var instance = new Class1(this.controller);
  99. instance.associations = new Object();
  100. } else {
  101. throw new Error("Cannot instantiate class " + class_name);
  102. }
  103. return instance;
  104. };
  105. // add symbol 'ObjectManager' to package 'TestAfter'
  106. TestAfter.ObjectManager = ObjectManager;
  107. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  108. if (finished_callback === undefined) finished_callback = null;
  109. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  110. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  111. this.addInputPort("test_input");
  112. this.addOutputPort("test_output");
  113. this.object_manager.createInstance("Class1", new Array());
  114. };
  115. Controller.prototype = new Object();
  116. (function() {
  117. var proto = new EventLoopControllerBase();
  118. for (prop in proto) {
  119. Controller.prototype[prop] = proto[prop];
  120. }
  121. })();
  122. // add symbol 'Controller' to package 'TestAfter'
  123. TestAfter.Controller = Controller;
  124. var InputEvent = function(name, port, parameters, time_offset) {
  125. this.name = name;
  126. this.port = port;
  127. this.parameters = parameters;
  128. this.time_offset = time_offset;
  129. };
  130. // add symbol 'InputEvent' to package 'TestAfter'
  131. TestAfter.InputEvent = InputEvent;
  132. var Test = function() {
  133. };
  134. Test.prototype.input_events = new Array();
  135. Test.prototype.expected_events = [[new Event("in_state_2", "test_output", new Array())]];
  136. // add symbol 'Test' to package 'TestAfter'
  137. TestAfter.Test = Test;
  138. })();