02_take_one_queue.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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:51 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.setTrigger(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.setTrigger(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. this.default_targets = this.states["/a"].getEffectiveTargetStates();
  77. RuntimeClassBase.prototype.initializeStatechart.call(this);
  78. };
  79. // add symbol 'c' to package 'take_one_queue'
  80. take_one_queue.c = c;
  81. var ObjectManager = function(controller) {
  82. ObjectManagerBase.call(this, controller);
  83. };
  84. ObjectManager.prototype = new Object();
  85. (function() {
  86. var proto = new ObjectManagerBase();
  87. for (prop in proto) {
  88. ObjectManager.prototype[prop] = proto[prop];
  89. }
  90. })();
  91. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  92. if (class_name === "c") {
  93. var instance = new c(this.controller);
  94. instance.associations = new Object();
  95. } else {
  96. throw new Error("Cannot instantiate class " + class_name);
  97. }
  98. return instance;
  99. };
  100. // add symbol 'ObjectManager' to package 'take_one_queue'
  101. take_one_queue.ObjectManager = ObjectManager;
  102. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  103. if (finished_callback === undefined) finished_callback = null;
  104. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  105. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  106. this.addInputPort("in");
  107. this.addOutputPort("out");
  108. this.object_manager.createInstance("c", new Array());
  109. };
  110. Controller.prototype = new Object();
  111. (function() {
  112. var proto = new EventLoopControllerBase();
  113. for (prop in proto) {
  114. Controller.prototype[prop] = proto[prop];
  115. }
  116. })();
  117. // add symbol 'Controller' to package 'take_one_queue'
  118. take_one_queue.Controller = Controller;
  119. var InputEvent = function(name, port, parameters, time_offset) {
  120. this.name = name;
  121. this.port = port;
  122. this.parameters = parameters;
  123. this.time_offset = time_offset;
  124. };
  125. // add symbol 'InputEvent' to package 'take_one_queue'
  126. take_one_queue.InputEvent = InputEvent;
  127. var Test = function() {
  128. };
  129. Test.prototype.input_events = [new InputEvent("e", "in", new Array(), 0.0)];
  130. 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())]];
  131. // add symbol 'Test' to package 'take_one_queue'
  132. take_one_queue.Test = Test;
  133. })();