StatechartLocalReactions.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #include "StatechartLocalReactions.h"
  2. #include <string.h>
  3. /*! \file Implementation of the state machine 'StatechartLocalReactions'
  4. */
  5. StatechartLocalReactions::StatechartLocalReactions()
  6. {
  7. stateConfVectorPosition = 0;
  8. }
  9. StatechartLocalReactions::~StatechartLocalReactions()
  10. {
  11. }
  12. void StatechartLocalReactions::init()
  13. {
  14. for (int i = 0; i < maxOrthogonalStates; ++i)
  15. stateConfVector[i] = StatechartLocalReactions_last_state;
  16. stateConfVectorPosition = 0;
  17. clearInEvents();
  18. clearOutEvents();
  19. /* Default init sequence for statechart StatechartLocalReactions */
  20. iface.myInt = 0;
  21. }
  22. void StatechartLocalReactions::enter()
  23. {
  24. /* Default enter sequence for statechart StatechartLocalReactions */
  25. enseq_main_region_default();
  26. enseq_region2_default();
  27. }
  28. void StatechartLocalReactions::exit()
  29. {
  30. /* Default exit sequence for statechart StatechartLocalReactions */
  31. exseq_main_region();
  32. exseq_region2();
  33. }
  34. sc_boolean StatechartLocalReactions::isActive() const
  35. {
  36. return stateConfVector[0] != StatechartLocalReactions_last_state||stateConfVector[1] != StatechartLocalReactions_last_state;
  37. }
  38. /*
  39. * Always returns 'false' since this state machine can never become final.
  40. */
  41. sc_boolean StatechartLocalReactions::isFinal() const
  42. {
  43. return false;}
  44. void StatechartLocalReactions::runCycle()
  45. {
  46. clearOutEvents();
  47. for (stateConfVectorPosition = 0;
  48. stateConfVectorPosition < maxOrthogonalStates;
  49. stateConfVectorPosition++)
  50. {
  51. switch (stateConfVector[stateConfVectorPosition])
  52. {
  53. case main_region_S1 :
  54. {
  55. react_main_region_S1();
  56. break;
  57. }
  58. case main_region_S2 :
  59. {
  60. react_main_region_S2();
  61. break;
  62. }
  63. case region2_a :
  64. {
  65. react_region2_a();
  66. break;
  67. }
  68. default:
  69. break;
  70. }
  71. }
  72. clearInEvents();
  73. }
  74. void StatechartLocalReactions::clearInEvents()
  75. {
  76. }
  77. void StatechartLocalReactions::clearOutEvents()
  78. {
  79. }
  80. sc_boolean StatechartLocalReactions::isStateActive(StatechartLocalReactionsStates state) const
  81. {
  82. switch (state)
  83. {
  84. case main_region_S1 :
  85. return (sc_boolean) (stateConfVector[0] == main_region_S1
  86. );
  87. case main_region_S2 :
  88. return (sc_boolean) (stateConfVector[0] == main_region_S2
  89. );
  90. case region2_a :
  91. return (sc_boolean) (stateConfVector[1] == region2_a
  92. );
  93. default: return false;
  94. }
  95. }
  96. StatechartLocalReactions::DefaultSCI* StatechartLocalReactions::getDefaultSCI()
  97. {
  98. return &iface;
  99. }
  100. sc_integer StatechartLocalReactions::DefaultSCI::get_myInt() const
  101. {
  102. return myInt;
  103. }
  104. sc_integer StatechartLocalReactions::get_myInt() const
  105. {
  106. return iface.myInt;
  107. }
  108. void StatechartLocalReactions::DefaultSCI::set_myInt(sc_integer value)
  109. {
  110. myInt = value;
  111. }
  112. void StatechartLocalReactions::set_myInt(sc_integer value)
  113. {
  114. iface.myInt = value;
  115. }
  116. // implementations of all internal functions
  117. sc_boolean StatechartLocalReactions::check__lr0()
  118. {
  119. return true;
  120. }
  121. sc_boolean StatechartLocalReactions::check__lr1()
  122. {
  123. return iface.myInt == 100;
  124. }
  125. sc_boolean StatechartLocalReactions::check_main_region_S1_tr0_tr0()
  126. {
  127. return true;
  128. }
  129. sc_boolean StatechartLocalReactions::check_main_region_S2_tr0_tr0()
  130. {
  131. return true;
  132. }
  133. void StatechartLocalReactions::effect__lr0()
  134. {
  135. iface.myInt += 1;
  136. }
  137. void StatechartLocalReactions::effect__lr1()
  138. {
  139. iface.myInt = 0;
  140. }
  141. void StatechartLocalReactions::effect_main_region_S1_tr0()
  142. {
  143. exseq_main_region_S1();
  144. enseq_main_region_S2_default();
  145. }
  146. void StatechartLocalReactions::effect_main_region_S2_tr0()
  147. {
  148. exseq_main_region_S2();
  149. enseq_main_region_S1_default();
  150. }
  151. /* 'default' enter sequence for state S1 */
  152. void StatechartLocalReactions::enseq_main_region_S1_default()
  153. {
  154. /* 'default' enter sequence for state S1 */
  155. stateConfVector[0] = main_region_S1;
  156. stateConfVectorPosition = 0;
  157. }
  158. /* 'default' enter sequence for state S2 */
  159. void StatechartLocalReactions::enseq_main_region_S2_default()
  160. {
  161. /* 'default' enter sequence for state S2 */
  162. stateConfVector[0] = main_region_S2;
  163. stateConfVectorPosition = 0;
  164. }
  165. /* 'default' enter sequence for state a */
  166. void StatechartLocalReactions::enseq_region2_a_default()
  167. {
  168. /* 'default' enter sequence for state a */
  169. stateConfVector[1] = region2_a;
  170. stateConfVectorPosition = 1;
  171. }
  172. /* 'default' enter sequence for region main region */
  173. void StatechartLocalReactions::enseq_main_region_default()
  174. {
  175. /* 'default' enter sequence for region main region */
  176. react_main_region__entry_Default();
  177. }
  178. /* 'default' enter sequence for region region2 */
  179. void StatechartLocalReactions::enseq_region2_default()
  180. {
  181. /* 'default' enter sequence for region region2 */
  182. react_region2__entry_Default();
  183. }
  184. /* Default exit sequence for state S1 */
  185. void StatechartLocalReactions::exseq_main_region_S1()
  186. {
  187. /* Default exit sequence for state S1 */
  188. stateConfVector[0] = StatechartLocalReactions_last_state;
  189. stateConfVectorPosition = 0;
  190. }
  191. /* Default exit sequence for state S2 */
  192. void StatechartLocalReactions::exseq_main_region_S2()
  193. {
  194. /* Default exit sequence for state S2 */
  195. stateConfVector[0] = StatechartLocalReactions_last_state;
  196. stateConfVectorPosition = 0;
  197. }
  198. /* Default exit sequence for state a */
  199. void StatechartLocalReactions::exseq_region2_a()
  200. {
  201. /* Default exit sequence for state a */
  202. stateConfVector[1] = StatechartLocalReactions_last_state;
  203. stateConfVectorPosition = 1;
  204. }
  205. /* Default exit sequence for region main region */
  206. void StatechartLocalReactions::exseq_main_region()
  207. {
  208. /* Default exit sequence for region main region */
  209. /* Handle exit of all possible states (of StatechartLocalReactions.main_region) at position 0... */
  210. switch(stateConfVector[ 0 ])
  211. {
  212. case main_region_S1 :
  213. {
  214. exseq_main_region_S1();
  215. break;
  216. }
  217. case main_region_S2 :
  218. {
  219. exseq_main_region_S2();
  220. break;
  221. }
  222. default: break;
  223. }
  224. }
  225. /* Default exit sequence for region region2 */
  226. void StatechartLocalReactions::exseq_region2()
  227. {
  228. /* Default exit sequence for region region2 */
  229. /* Handle exit of all possible states (of StatechartLocalReactions.region2) at position 1... */
  230. switch(stateConfVector[ 1 ])
  231. {
  232. case region2_a :
  233. {
  234. exseq_region2_a();
  235. break;
  236. }
  237. default: break;
  238. }
  239. }
  240. /* The reactions of state S1. */
  241. void StatechartLocalReactions::react_main_region_S1()
  242. {
  243. /* The reactions of state S1. */
  244. effect__lr0();
  245. if (check__lr1())
  246. {
  247. effect__lr1();
  248. }
  249. effect_main_region_S1_tr0();
  250. }
  251. /* The reactions of state S2. */
  252. void StatechartLocalReactions::react_main_region_S2()
  253. {
  254. /* The reactions of state S2. */
  255. effect__lr0();
  256. if (check__lr1())
  257. {
  258. effect__lr1();
  259. }
  260. effect_main_region_S2_tr0();
  261. }
  262. /* The reactions of state a. */
  263. void StatechartLocalReactions::react_region2_a()
  264. {
  265. }
  266. /* Default react sequence for initial entry */
  267. void StatechartLocalReactions::react_main_region__entry_Default()
  268. {
  269. /* Default react sequence for initial entry */
  270. enseq_main_region_S1_default();
  271. }
  272. /* Default react sequence for initial entry */
  273. void StatechartLocalReactions::react_region2__entry_Default()
  274. {
  275. /* Default react sequence for initial entry */
  276. enseq_region2_a_default();
  277. }