ping.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. Date: Fri Jul 30 16:04:21 2021
  3. Model author: Joeri Exelmans
  4. Model name: Ping
  5. Model description:
  6. A class that logs to console 'ping' every 1s
  7. */
  8. // package Ping
  9. let Ping = {};
  10. (function() {
  11. let Main = function(controller) {
  12. RuntimeClassBase.call(this, controller);
  13. this.semantics.bigStepMaximality = StatechartSemantics.TakeMany;
  14. this.semantics.internalEventLifeline = StatechartSemantics.NextComboStep;
  15. this.semantics.inputEventLifeline = StatechartSemantics.FirstComboStep;
  16. this.semantics.priority = StatechartSemantics.SourceParent;
  17. this.semantics.concurrency = StatechartSemantics.Single;
  18. // build Statechart structure
  19. this.buildStatechartStructure();
  20. // call user defined constructor
  21. Main.prototype.userDefinedConstructor.call(this);
  22. };
  23. Main.prototype = new Object();
  24. (function() {
  25. var proto = new RuntimeClassBase();
  26. for (let prop in proto) {
  27. Main.prototype[prop] = proto[prop];
  28. }
  29. })();
  30. Main.prototype.userDefinedConstructor = function() {
  31. };
  32. Main.prototype.userDefinedDestructor = function() {
  33. };
  34. // builds Statechart structure
  35. Main.prototype.buildStatechartStructure = function() {
  36. // state <root>
  37. this.states[""] = new State(0, "", this);
  38. // state /p
  39. this.states["/p"] = new ParallelState(1, "/p", this);
  40. // state /p/r1
  41. this.states["/p/r1"] = new State(2, "/p/r1", this);
  42. // state /p/r1/A
  43. this.states["/p/r1/A"] = new State(3, "/p/r1/A", this);
  44. this.states["/p/r1/A"].setEnter(this.PR1AEnter);
  45. this.states["/p/r1/A"].setExit(this.PR1AExit);
  46. // state /p/r2
  47. this.states["/p/r2"] = new State(4, "/p/r2", this);
  48. // state /p/r2/B
  49. this.states["/p/r2/B"] = new State(5, "/p/r2/B", this);
  50. this.states["/p/r2/B"].setEnter(this.PR2BEnter);
  51. this.states["/p/r2/B"].setExit(this.PR2BExit);
  52. // add children
  53. this.states[""].addChild(this.states["/p"]);
  54. this.states["/p"].addChild(this.states["/p/r1"]);
  55. this.states["/p"].addChild(this.states["/p/r2"]);
  56. this.states["/p/r1"].addChild(this.states["/p/r1/A"]);
  57. this.states["/p/r2"].addChild(this.states["/p/r2/B"]);
  58. this.states[""].fixTree();
  59. this.states[""].defaultState = this.states["/p"];
  60. this.states["/p/r1"].defaultState = this.states["/p/r1/A"];
  61. this.states["/p/r2"].defaultState = this.states["/p/r2/B"];
  62. // transition /p/r1/A
  63. var PR1A_0 = new Transition(this, this.states["/p/r1/A"], [this.states["/p/r1/A"]]);
  64. PR1A_0.setAction(this.PR1A_0Exec);
  65. PR1A_0.setTrigger(new Event("event0After"));
  66. this.states["/p/r1/A"].addTransition(PR1A_0);
  67. // transition /p/r2/B
  68. var PR2B_0 = new Transition(this, this.states["/p/r2/B"], [this.states["/p/r2/B"]]);
  69. PR2B_0.setAction(this.PR2B_0Exec);
  70. PR2B_0.setTrigger(new Event("event1After"));
  71. this.states["/p/r2/B"].addTransition(PR2B_0);
  72. };
  73. Main.prototype.PR1AEnter = function() {
  74. this.addTimer(0, 1);
  75. };
  76. Main.prototype.PR1AExit = function() {
  77. this.removeTimer(0);
  78. };
  79. Main.prototype.PR2BEnter = function() {
  80. this.addTimer(1, 2);
  81. };
  82. Main.prototype.PR2BExit = function() {
  83. this.removeTimer(1);
  84. };
  85. Main.prototype.PR1A_0Exec = function(parameters) {
  86. console.log("A");
  87. };
  88. Main.prototype.PR2B_0Exec = function(parameters) {
  89. console.log("B");
  90. };
  91. Main.prototype.initializeStatechart = function() {
  92. // enter default state
  93. this.defaultTargets = this.states["/p"].getEffectiveTargetStates();
  94. RuntimeClassBase.prototype.initializeStatechart.call(this);
  95. };
  96. // Add symbol 'Main' to package 'Ping'
  97. Ping.Main = Main;
  98. let ObjectManager = function(controller) {
  99. ObjectManagerBase.call(this, controller);
  100. };
  101. ObjectManager.prototype = new Object();
  102. (function() {
  103. var proto = new ObjectManagerBase();
  104. for (let prop in proto) {
  105. ObjectManager.prototype[prop] = proto[prop];
  106. }
  107. })();
  108. ObjectManager.prototype.instantiate = function(className, constructParams) {
  109. if (className === "Main") {
  110. var instance = new Main(this.controller);
  111. instance.associations = new Object();
  112. } else {
  113. throw new Error("Cannot instantiate class " + className);
  114. }
  115. return instance;
  116. };
  117. // Add symbol 'ObjectManager' to package 'Ping'
  118. Ping.ObjectManager = ObjectManager;
  119. let Controller = function(eventLoopCallbacks, finishedCallback, behindScheduleCallback) {
  120. if (finishedCallback === undefined) finishedCallback = null;
  121. if (behindScheduleCallback === undefined) behindScheduleCallback = null;
  122. EventLoopControllerBase.call(this, new ObjectManager(this), eventLoopCallbacks, finishedCallback, behindScheduleCallback);
  123. this.objectManager.createInstance("Main", new Array());
  124. };
  125. Controller.prototype = new Object();
  126. (function() {
  127. var proto = new EventLoopControllerBase();
  128. for (let prop in proto) {
  129. Controller.prototype[prop] = proto[prop];
  130. }
  131. })();
  132. // Add symbol 'Controller' to package 'Ping'
  133. Ping.Controller = Controller;
  134. })();