02_take_one_queue.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Wed Aug 03 16:10:17 2016
  3. Model author: Herr Joeri Exelmans
  4. Model name: take_one_queue
  5. Model description:
  6. Internal event lifeline - Queue-semantics: Internal events are treated just like external events: They are added to the object's event queue and will be sensed in another big step. This way, a raised internal event will always be sensed at some point later in time, but it is possible that other (external) events in the object's event queue are treated first.*/
  7. // package "take_one_queue"
  8. var take_one_queue = {};
  9. (function() {
  10. var c = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeOne;
  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. 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 /a
  38. this.states["/a"] = new State(1, this);
  39. this.states["/a"].setEnter(this._a_enter);
  40. // state /b
  41. this.states["/b"] = new State(2, this);
  42. this.states["/b"].setEnter(this._b_enter);
  43. // state /c
  44. this.states["/c"] = new State(3, this);
  45. this.states["/c"].setEnter(this._c_enter);
  46. // add children
  47. this.states[""].addChild(this.states["/a"]);
  48. this.states[""].addChild(this.states["/b"]);
  49. this.states[""].addChild(this.states["/c"]);
  50. this.states[""].fixTree();
  51. this.states[""].default_state = this.states["/a"];
  52. // transition /a
  53. var _a_0 = new Transition(this, this.states["/a"], [this.states["/b"]]);
  54. _a_0.setAction(this._a_0_exec);
  55. _a_0.trigger = new Event("e", "in");
  56. this.states["/a"].addTransition(_a_0);
  57. // transition /b
  58. var _b_0 = new Transition(this, this.states["/b"], [this.states["/c"]]);
  59. _b_0.trigger = new Event("f", null);
  60. this.states["/b"].addTransition(_b_0);
  61. };
  62. c.prototype._a_enter = function() {
  63. this.big_step.outputEvent(new Event("entered_a", "out", new Array()));
  64. };
  65. c.prototype._b_enter = function() {
  66. this.big_step.outputEvent(new Event("entered_b", "out", new Array()));
  67. };
  68. c.prototype._c_enter = function() {
  69. this.big_step.outputEvent(new Event("entered_c", "out", new Array()));
  70. };
  71. c.prototype._a_0_exec = function(parameters) {
  72. this.raiseInternalEvent(new Event("f", null, new Array()));
  73. };
  74. c.prototype.initializeStatechart = function() {
  75. // enter default state
  76. var states = this.states["/a"].getEffectiveTargetStates();
  77. this.updateConfiguration(states);
  78. for (var state_idx in states) {
  79. if (!states.hasOwnProperty(state_idx)) continue;
  80. var state = states[state_idx]
  81. if (state.enter) {
  82. state.enter();
  83. }
  84. }
  85. };
  86. // add symbol 'c' to package 'take_one_queue'
  87. take_one_queue.c = c;
  88. var ObjectManager = function(controller) {
  89. ObjectManagerBase.call(this, controller);
  90. };
  91. ObjectManager.prototype = new Object();
  92. (function() {
  93. var proto = new ObjectManagerBase();
  94. for (prop in proto) {
  95. ObjectManager.prototype[prop] = proto[prop];
  96. }
  97. })();
  98. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  99. if (class_name === "c") {
  100. var instance = new c(this.controller);
  101. instance.associations = new Object();
  102. }
  103. return instance;
  104. };
  105. // add symbol 'ObjectManager' to package 'take_one_queue'
  106. take_one_queue.ObjectManager = ObjectManager;
  107. var Controller = function(event_loop_callbacks, finished_callback) {
  108. if (finished_callback === undefined) finished_callback = null;
  109. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback);
  110. this.addInputPort("in");
  111. this.addOutputPort("out");
  112. this.object_manager.createInstance("c", new Array());
  113. };
  114. Controller.prototype = new Object();
  115. (function() {
  116. var proto = new EventLoopControllerBase();
  117. for (prop in proto) {
  118. Controller.prototype[prop] = proto[prop];
  119. }
  120. })();
  121. // add symbol 'Controller' to package 'take_one_queue'
  122. take_one_queue.Controller = Controller;
  123. var InputEvent = function(name, port, parameters, time_offset) {
  124. this.name = name;
  125. this.port = port;
  126. this.parameters = parameters;
  127. this.time_offset = time_offset;
  128. };
  129. // add symbol 'InputEvent' to package 'take_one_queue'
  130. take_one_queue.InputEvent = InputEvent;
  131. var Test = function() {
  132. };
  133. Test.prototype.input_events = [new InputEvent("e", "in", new Array(), 0.0)];
  134. Test.prototype.expected_events = [[new Event("entered_a", "out", new Array())], [new Event("entered_b", "out", new Array())], [new Event("entered_c", "out", new Array())]];
  135. // add symbol 'Test' to package 'take_one_queue'
  136. take_one_queue.Test = Test;
  137. })();