01_source_child.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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:20 2016
  3. Model author: Herr Joeri Exelmans
  4. Model name: source_child
  5. Model description:
  6. 'Source Child' priority-semantics: If 2 transitions are enabled, and the source state of the first is an ancestor of the second, only the second is executed.*/
  7. // package "source_child"
  8. var source_child = {};
  9. (function() {
  10. var c = 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.SourceChild;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // call user defined constructor
  20. c.prototype.user_defined_constructor.call(this);
  21. };
  22. c.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. c.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. c.prototype.user_defined_constructor = function() {
  30. };
  31. c.prototype.user_defined_destructor = function() {
  32. };
  33. // builds Statechart structure
  34. c.prototype.build_statechart_structure = function() {
  35. // state <root>
  36. this.states[""] = new State(0, this);
  37. // state /parent
  38. this.states["/parent"] = new State(1, this);
  39. this.states["/parent"].setEnter(this._parent_enter);
  40. // state /parent/a
  41. this.states["/parent/a"] = new State(2, this);
  42. this.states["/parent/a"].setEnter(this._parent_a_enter);
  43. // state /parent/b
  44. this.states["/parent/b"] = new State(3, this);
  45. this.states["/parent/b"].setEnter(this._parent_b_enter);
  46. // state /c
  47. this.states["/c"] = new State(4, this);
  48. this.states["/c"].setEnter(this._c_enter);
  49. // add children
  50. this.states[""].addChild(this.states["/parent"]);
  51. this.states[""].addChild(this.states["/c"]);
  52. this.states["/parent"].addChild(this.states["/parent/a"]);
  53. this.states["/parent"].addChild(this.states["/parent/b"]);
  54. this.states[""].fixTree();
  55. this.states[""].default_state = this.states["/parent"];
  56. this.states["/parent"].default_state = this.states["/parent/a"];
  57. // transition /parent/a
  58. var _parent_a_0 = new Transition(this, this.states["/parent/a"], [this.states["/parent/b"]]);
  59. _parent_a_0.setTrigger(null);
  60. this.states["/parent/a"].addTransition(_parent_a_0);
  61. // transition /parent
  62. var _parent_0 = new Transition(this, this.states["/parent"], [this.states["/c"]]);
  63. _parent_0.setTrigger(null);
  64. this.states["/parent"].addTransition(_parent_0);
  65. };
  66. c.prototype._parent_enter = function() {
  67. this.big_step.outputEvent(new Event("entered_parent", "out", new Array()));
  68. };
  69. c.prototype._parent_a_enter = function() {
  70. this.big_step.outputEvent(new Event("entered_a", "out", new Array()));
  71. };
  72. c.prototype._parent_b_enter = function() {
  73. this.big_step.outputEvent(new Event("entered_b", "out", new Array()));
  74. };
  75. c.prototype._c_enter = function() {
  76. this.big_step.outputEvent(new Event("entered_c", "out", new Array()));
  77. };
  78. c.prototype.initializeStatechart = function() {
  79. // enter default state
  80. var states = this.states["/parent"].getEffectiveTargetStates();
  81. this.updateConfiguration(states);
  82. for (var state_idx in states) {
  83. if (!states.hasOwnProperty(state_idx)) continue;
  84. var state = states[state_idx]
  85. if (state.enter) {
  86. state.enter();
  87. }
  88. }
  89. };
  90. // add symbol 'c' to package 'source_child'
  91. source_child.c = c;
  92. var ObjectManager = function(controller) {
  93. ObjectManagerBase.call(this, controller);
  94. };
  95. ObjectManager.prototype = new Object();
  96. (function() {
  97. var proto = new ObjectManagerBase();
  98. for (prop in proto) {
  99. ObjectManager.prototype[prop] = proto[prop];
  100. }
  101. })();
  102. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  103. if (class_name === "c") {
  104. var instance = new c(this.controller);
  105. instance.associations = new Object();
  106. } else {
  107. throw new Error("Cannot instantiate class " + class_name);
  108. }
  109. return instance;
  110. };
  111. // add symbol 'ObjectManager' to package 'source_child'
  112. source_child.ObjectManager = ObjectManager;
  113. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  114. if (finished_callback === undefined) finished_callback = null;
  115. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  116. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  117. this.addInputPort("in");
  118. this.addOutputPort("out");
  119. this.object_manager.createInstance("c", new Array());
  120. };
  121. Controller.prototype = new Object();
  122. (function() {
  123. var proto = new EventLoopControllerBase();
  124. for (prop in proto) {
  125. Controller.prototype[prop] = proto[prop];
  126. }
  127. })();
  128. // add symbol 'Controller' to package 'source_child'
  129. source_child.Controller = Controller;
  130. var InputEvent = function(name, port, parameters, time_offset) {
  131. this.name = name;
  132. this.port = port;
  133. this.parameters = parameters;
  134. this.time_offset = time_offset;
  135. };
  136. // add symbol 'InputEvent' to package 'source_child'
  137. source_child.InputEvent = InputEvent;
  138. var Test = function() {
  139. };
  140. Test.prototype.input_events = new Array();
  141. Test.prototype.expected_events = [[new Event("entered_parent", "out", new Array()), new Event("entered_a", "out", new Array())], [new Event("entered_b", "out", new Array()), new Event("entered_c", "out", new Array())]];
  142. // add symbol 'Test' to package 'source_child'
  143. source_child.Test = Test;
  144. })();