DynamicChoice.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "DynamicChoice.h"
  5. /*! \file Implementation of the state machine 'DynamicChoice'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean dynamicChoice_check_main_region_Start_tr0_tr0(const DynamicChoice* handle);
  9. static sc_boolean dynamicChoice_check_main_region__choice_0_tr0_tr0(const DynamicChoice* handle);
  10. static sc_boolean dynamicChoice_check_main_region__choice_0_tr1(const DynamicChoice* handle);
  11. static void dynamicChoice_effect_main_region_Start_tr0(DynamicChoice* handle);
  12. static void dynamicChoice_effect_main_region__choice_0_tr0(DynamicChoice* handle);
  13. static void dynamicChoice_effect_main_region__choice_0_tr1(DynamicChoice* handle);
  14. static void dynamicChoice_enact_main_region_Start(DynamicChoice* handle);
  15. static void dynamicChoice_enseq_main_region_Start_default(DynamicChoice* handle);
  16. static void dynamicChoice_enseq_main_region_A_default(DynamicChoice* handle);
  17. static void dynamicChoice_enseq_main_region_B_default(DynamicChoice* handle);
  18. static void dynamicChoice_enseq_main_region_default(DynamicChoice* handle);
  19. static void dynamicChoice_exseq_main_region_Start(DynamicChoice* handle);
  20. static void dynamicChoice_exseq_main_region_A(DynamicChoice* handle);
  21. static void dynamicChoice_exseq_main_region_B(DynamicChoice* handle);
  22. static void dynamicChoice_exseq_main_region(DynamicChoice* handle);
  23. static void dynamicChoice_react_main_region_Start(DynamicChoice* handle);
  24. static void dynamicChoice_react_main_region_A(DynamicChoice* handle);
  25. static void dynamicChoice_react_main_region_B(DynamicChoice* handle);
  26. static void dynamicChoice_react_main_region__choice_0(DynamicChoice* handle);
  27. static void dynamicChoice_react_main_region__entry_Default(DynamicChoice* handle);
  28. static void dynamicChoice_clearInEvents(DynamicChoice* handle);
  29. static void dynamicChoice_clearOutEvents(DynamicChoice* handle);
  30. void dynamicChoice_init(DynamicChoice* handle)
  31. {
  32. sc_integer i;
  33. for (i = 0; i < DYNAMICCHOICE_MAX_ORTHOGONAL_STATES; ++i)
  34. {
  35. handle->stateConfVector[i] = DynamicChoice_last_state;
  36. }
  37. handle->stateConfVectorPosition = 0;
  38. dynamicChoice_clearInEvents(handle);
  39. dynamicChoice_clearOutEvents(handle);
  40. /* Default init sequence for statechart DynamicChoice */
  41. handle->iface.number = 0;
  42. }
  43. void dynamicChoice_enter(DynamicChoice* handle)
  44. {
  45. /* Default enter sequence for statechart DynamicChoice */
  46. dynamicChoice_enseq_main_region_default(handle);
  47. }
  48. void dynamicChoice_exit(DynamicChoice* handle)
  49. {
  50. /* Default exit sequence for statechart DynamicChoice */
  51. dynamicChoice_exseq_main_region(handle);
  52. }
  53. sc_boolean dynamicChoice_isActive(const DynamicChoice* handle)
  54. {
  55. sc_boolean result = bool_false;
  56. int i;
  57. for(i = 0; i < DYNAMICCHOICE_MAX_ORTHOGONAL_STATES; i++)
  58. {
  59. result = result || handle->stateConfVector[i] != DynamicChoice_last_state;
  60. }
  61. return result;
  62. }
  63. /*
  64. * Always returns 'false' since this state machine can never become final.
  65. */
  66. sc_boolean dynamicChoice_isFinal(const DynamicChoice* handle)
  67. {
  68. return bool_false;
  69. }
  70. static void dynamicChoice_clearInEvents(DynamicChoice* handle)
  71. {
  72. handle->iface.reset_raised = bool_false;
  73. }
  74. static void dynamicChoice_clearOutEvents(DynamicChoice* handle)
  75. {
  76. }
  77. void dynamicChoice_runCycle(DynamicChoice* handle)
  78. {
  79. dynamicChoice_clearOutEvents(handle);
  80. for (handle->stateConfVectorPosition = 0;
  81. handle->stateConfVectorPosition < DYNAMICCHOICE_MAX_ORTHOGONAL_STATES;
  82. handle->stateConfVectorPosition++)
  83. {
  84. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  85. {
  86. case DynamicChoice_main_region_Start :
  87. {
  88. dynamicChoice_react_main_region_Start(handle);
  89. break;
  90. }
  91. case DynamicChoice_main_region_A :
  92. {
  93. dynamicChoice_react_main_region_A(handle);
  94. break;
  95. }
  96. case DynamicChoice_main_region_B :
  97. {
  98. dynamicChoice_react_main_region_B(handle);
  99. break;
  100. }
  101. default:
  102. break;
  103. }
  104. }
  105. dynamicChoice_clearInEvents(handle);
  106. }
  107. sc_boolean dynamicChoice_isStateActive(const DynamicChoice* handle, DynamicChoiceStates state)
  108. {
  109. sc_boolean result = bool_false;
  110. switch (state)
  111. {
  112. case DynamicChoice_main_region_Start :
  113. result = (sc_boolean) (handle->stateConfVector[SCVI_DYNAMICCHOICE_MAIN_REGION_START] == DynamicChoice_main_region_Start
  114. );
  115. break;
  116. case DynamicChoice_main_region_A :
  117. result = (sc_boolean) (handle->stateConfVector[SCVI_DYNAMICCHOICE_MAIN_REGION_A] == DynamicChoice_main_region_A
  118. );
  119. break;
  120. case DynamicChoice_main_region_B :
  121. result = (sc_boolean) (handle->stateConfVector[SCVI_DYNAMICCHOICE_MAIN_REGION_B] == DynamicChoice_main_region_B
  122. );
  123. break;
  124. default:
  125. result = bool_false;
  126. break;
  127. }
  128. return result;
  129. }
  130. void dynamicChoiceIface_raise_reset(DynamicChoice* handle)
  131. {
  132. handle->iface.reset_raised = bool_true;
  133. }
  134. sc_integer dynamicChoiceIface_get_number(const DynamicChoice* handle)
  135. {
  136. return handle->iface.number;
  137. }
  138. void dynamicChoiceIface_set_number(DynamicChoice* handle, sc_integer value)
  139. {
  140. handle->iface.number = value;
  141. }
  142. /* implementations of all internal functions */
  143. static sc_boolean dynamicChoice_check_main_region_Start_tr0_tr0(const DynamicChoice* handle)
  144. {
  145. return bool_true;
  146. }
  147. static sc_boolean dynamicChoice_check_main_region__choice_0_tr0_tr0(const DynamicChoice* handle)
  148. {
  149. return (handle->iface.number == 2) ? bool_true : bool_false;
  150. }
  151. static sc_boolean dynamicChoice_check_main_region__choice_0_tr1(const DynamicChoice* handle)
  152. {
  153. return bool_true;
  154. }
  155. static void dynamicChoice_effect_main_region_Start_tr0(DynamicChoice* handle)
  156. {
  157. dynamicChoice_exseq_main_region_Start(handle);
  158. handle->iface.number += 1;
  159. dynamicChoice_react_main_region__choice_0(handle);
  160. }
  161. static void dynamicChoice_effect_main_region__choice_0_tr0(DynamicChoice* handle)
  162. {
  163. dynamicChoice_enseq_main_region_A_default(handle);
  164. }
  165. static void dynamicChoice_effect_main_region__choice_0_tr1(DynamicChoice* handle)
  166. {
  167. dynamicChoice_enseq_main_region_B_default(handle);
  168. }
  169. /* Entry action for state 'Start'. */
  170. static void dynamicChoice_enact_main_region_Start(DynamicChoice* handle)
  171. {
  172. /* Entry action for state 'Start'. */
  173. handle->iface.number = 1;
  174. }
  175. /* 'default' enter sequence for state Start */
  176. static void dynamicChoice_enseq_main_region_Start_default(DynamicChoice* handle)
  177. {
  178. /* 'default' enter sequence for state Start */
  179. dynamicChoice_enact_main_region_Start(handle);
  180. handle->stateConfVector[0] = DynamicChoice_main_region_Start;
  181. handle->stateConfVectorPosition = 0;
  182. }
  183. /* 'default' enter sequence for state A */
  184. static void dynamicChoice_enseq_main_region_A_default(DynamicChoice* handle)
  185. {
  186. /* 'default' enter sequence for state A */
  187. handle->stateConfVector[0] = DynamicChoice_main_region_A;
  188. handle->stateConfVectorPosition = 0;
  189. }
  190. /* 'default' enter sequence for state B */
  191. static void dynamicChoice_enseq_main_region_B_default(DynamicChoice* handle)
  192. {
  193. /* 'default' enter sequence for state B */
  194. handle->stateConfVector[0] = DynamicChoice_main_region_B;
  195. handle->stateConfVectorPosition = 0;
  196. }
  197. /* 'default' enter sequence for region main region */
  198. static void dynamicChoice_enseq_main_region_default(DynamicChoice* handle)
  199. {
  200. /* 'default' enter sequence for region main region */
  201. dynamicChoice_react_main_region__entry_Default(handle);
  202. }
  203. /* Default exit sequence for state Start */
  204. static void dynamicChoice_exseq_main_region_Start(DynamicChoice* handle)
  205. {
  206. /* Default exit sequence for state Start */
  207. handle->stateConfVector[0] = DynamicChoice_last_state;
  208. handle->stateConfVectorPosition = 0;
  209. }
  210. /* Default exit sequence for state A */
  211. static void dynamicChoice_exseq_main_region_A(DynamicChoice* handle)
  212. {
  213. /* Default exit sequence for state A */
  214. handle->stateConfVector[0] = DynamicChoice_last_state;
  215. handle->stateConfVectorPosition = 0;
  216. }
  217. /* Default exit sequence for state B */
  218. static void dynamicChoice_exseq_main_region_B(DynamicChoice* handle)
  219. {
  220. /* Default exit sequence for state B */
  221. handle->stateConfVector[0] = DynamicChoice_last_state;
  222. handle->stateConfVectorPosition = 0;
  223. }
  224. /* Default exit sequence for region main region */
  225. static void dynamicChoice_exseq_main_region(DynamicChoice* handle)
  226. {
  227. /* Default exit sequence for region main region */
  228. /* Handle exit of all possible states (of DynamicChoice.main_region) at position 0... */
  229. switch(handle->stateConfVector[ 0 ])
  230. {
  231. case DynamicChoice_main_region_Start :
  232. {
  233. dynamicChoice_exseq_main_region_Start(handle);
  234. break;
  235. }
  236. case DynamicChoice_main_region_A :
  237. {
  238. dynamicChoice_exseq_main_region_A(handle);
  239. break;
  240. }
  241. case DynamicChoice_main_region_B :
  242. {
  243. dynamicChoice_exseq_main_region_B(handle);
  244. break;
  245. }
  246. default: break;
  247. }
  248. }
  249. /* The reactions of state Start. */
  250. static void dynamicChoice_react_main_region_Start(DynamicChoice* handle)
  251. {
  252. /* The reactions of state Start. */
  253. dynamicChoice_effect_main_region_Start_tr0(handle);
  254. }
  255. /* The reactions of state A. */
  256. static void dynamicChoice_react_main_region_A(DynamicChoice* handle)
  257. {
  258. /* The reactions of state A. */
  259. }
  260. /* The reactions of state B. */
  261. static void dynamicChoice_react_main_region_B(DynamicChoice* handle)
  262. {
  263. /* The reactions of state B. */
  264. }
  265. /* The reactions of state null. */
  266. static void dynamicChoice_react_main_region__choice_0(DynamicChoice* handle)
  267. {
  268. /* The reactions of state null. */
  269. if (dynamicChoice_check_main_region__choice_0_tr0_tr0(handle) == bool_true)
  270. {
  271. dynamicChoice_effect_main_region__choice_0_tr0(handle);
  272. } else
  273. {
  274. dynamicChoice_effect_main_region__choice_0_tr1(handle);
  275. }
  276. }
  277. /* Default react sequence for initial entry */
  278. static void dynamicChoice_react_main_region__entry_Default(DynamicChoice* handle)
  279. {
  280. /* Default react sequence for initial entry */
  281. dynamicChoice_enseq_main_region_Start_default(handle);
  282. }