GuardedEntry.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "GuardedEntry.h"
  5. /*! \file Implementation of the state machine 'GuardedEntry'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean guardedEntry_check_main_region_A_tr0_tr0(const GuardedEntry* handle);
  9. static sc_boolean guardedEntry_check_main_region_B_tr0_tr0(const GuardedEntry* handle);
  10. static void guardedEntry_effect_main_region_A_tr0(GuardedEntry* handle);
  11. static void guardedEntry_effect_main_region_B_tr0(GuardedEntry* handle);
  12. static void guardedEntry_enact_main_region_A(GuardedEntry* handle);
  13. static void guardedEntry_enseq_main_region_A_default(GuardedEntry* handle);
  14. static void guardedEntry_enseq_main_region_B_default(GuardedEntry* handle);
  15. static void guardedEntry_enseq_main_region_default(GuardedEntry* handle);
  16. static void guardedEntry_exseq_main_region_A(GuardedEntry* handle);
  17. static void guardedEntry_exseq_main_region_B(GuardedEntry* handle);
  18. static void guardedEntry_exseq_main_region(GuardedEntry* handle);
  19. static void guardedEntry_react_main_region_A(GuardedEntry* handle);
  20. static void guardedEntry_react_main_region_B(GuardedEntry* handle);
  21. static void guardedEntry_react_main_region__entry_Default(GuardedEntry* handle);
  22. static void guardedEntry_clearInEvents(GuardedEntry* handle);
  23. static void guardedEntry_clearOutEvents(GuardedEntry* handle);
  24. void guardedEntry_init(GuardedEntry* handle)
  25. {
  26. sc_integer i;
  27. for (i = 0; i < GUARDEDENTRY_MAX_ORTHOGONAL_STATES; ++i)
  28. {
  29. handle->stateConfVector[i] = GuardedEntry_last_state;
  30. }
  31. handle->stateConfVectorPosition = 0;
  32. guardedEntry_clearInEvents(handle);
  33. guardedEntry_clearOutEvents(handle);
  34. /* Default init sequence for statechart GuardedEntry */
  35. handle->iface.guard = bool_false;
  36. handle->iface.done = bool_false;
  37. }
  38. void guardedEntry_enter(GuardedEntry* handle)
  39. {
  40. /* Default enter sequence for statechart GuardedEntry */
  41. guardedEntry_enseq_main_region_default(handle);
  42. }
  43. void guardedEntry_exit(GuardedEntry* handle)
  44. {
  45. /* Default exit sequence for statechart GuardedEntry */
  46. guardedEntry_exseq_main_region(handle);
  47. }
  48. sc_boolean guardedEntry_isActive(const GuardedEntry* handle)
  49. {
  50. sc_boolean result = bool_false;
  51. int i;
  52. for(i = 0; i < GUARDEDENTRY_MAX_ORTHOGONAL_STATES; i++)
  53. {
  54. result = result || handle->stateConfVector[i] != GuardedEntry_last_state;
  55. }
  56. return result;
  57. }
  58. /*
  59. * Always returns 'false' since this state machine can never become final.
  60. */
  61. sc_boolean guardedEntry_isFinal(const GuardedEntry* handle)
  62. {
  63. return bool_false;
  64. }
  65. static void guardedEntry_clearInEvents(GuardedEntry* handle)
  66. {
  67. handle->iface.e_raised = bool_false;
  68. }
  69. static void guardedEntry_clearOutEvents(GuardedEntry* handle)
  70. {
  71. }
  72. void guardedEntry_runCycle(GuardedEntry* handle)
  73. {
  74. guardedEntry_clearOutEvents(handle);
  75. for (handle->stateConfVectorPosition = 0;
  76. handle->stateConfVectorPosition < GUARDEDENTRY_MAX_ORTHOGONAL_STATES;
  77. handle->stateConfVectorPosition++)
  78. {
  79. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  80. {
  81. case GuardedEntry_main_region_A :
  82. {
  83. guardedEntry_react_main_region_A(handle);
  84. break;
  85. }
  86. case GuardedEntry_main_region_B :
  87. {
  88. guardedEntry_react_main_region_B(handle);
  89. break;
  90. }
  91. default:
  92. break;
  93. }
  94. }
  95. guardedEntry_clearInEvents(handle);
  96. }
  97. sc_boolean guardedEntry_isStateActive(const GuardedEntry* handle, GuardedEntryStates state)
  98. {
  99. sc_boolean result = bool_false;
  100. switch (state)
  101. {
  102. case GuardedEntry_main_region_A :
  103. result = (sc_boolean) (handle->stateConfVector[SCVI_GUARDEDENTRY_MAIN_REGION_A] == GuardedEntry_main_region_A
  104. );
  105. break;
  106. case GuardedEntry_main_region_B :
  107. result = (sc_boolean) (handle->stateConfVector[SCVI_GUARDEDENTRY_MAIN_REGION_B] == GuardedEntry_main_region_B
  108. );
  109. break;
  110. default:
  111. result = bool_false;
  112. break;
  113. }
  114. return result;
  115. }
  116. void guardedEntryIface_raise_e(GuardedEntry* handle)
  117. {
  118. handle->iface.e_raised = bool_true;
  119. }
  120. sc_boolean guardedEntryIface_get_guard(const GuardedEntry* handle)
  121. {
  122. return handle->iface.guard;
  123. }
  124. void guardedEntryIface_set_guard(GuardedEntry* handle, sc_boolean value)
  125. {
  126. handle->iface.guard = value;
  127. }
  128. sc_boolean guardedEntryIface_get_done(const GuardedEntry* handle)
  129. {
  130. return handle->iface.done;
  131. }
  132. void guardedEntryIface_set_done(GuardedEntry* handle, sc_boolean value)
  133. {
  134. handle->iface.done = value;
  135. }
  136. /* implementations of all internal functions */
  137. static sc_boolean guardedEntry_check_main_region_A_tr0_tr0(const GuardedEntry* handle)
  138. {
  139. return handle->iface.e_raised;
  140. }
  141. static sc_boolean guardedEntry_check_main_region_B_tr0_tr0(const GuardedEntry* handle)
  142. {
  143. return handle->iface.e_raised;
  144. }
  145. static void guardedEntry_effect_main_region_A_tr0(GuardedEntry* handle)
  146. {
  147. guardedEntry_exseq_main_region_A(handle);
  148. guardedEntry_enseq_main_region_B_default(handle);
  149. }
  150. static void guardedEntry_effect_main_region_B_tr0(GuardedEntry* handle)
  151. {
  152. guardedEntry_exseq_main_region_B(handle);
  153. guardedEntry_enseq_main_region_A_default(handle);
  154. }
  155. /* Entry action for state 'A'. */
  156. static void guardedEntry_enact_main_region_A(GuardedEntry* handle)
  157. {
  158. /* Entry action for state 'A'. */
  159. if (handle->iface.guard == bool_true)
  160. {
  161. handle->iface.done = bool_true;
  162. }
  163. }
  164. /* 'default' enter sequence for state A */
  165. static void guardedEntry_enseq_main_region_A_default(GuardedEntry* handle)
  166. {
  167. /* 'default' enter sequence for state A */
  168. guardedEntry_enact_main_region_A(handle);
  169. handle->stateConfVector[0] = GuardedEntry_main_region_A;
  170. handle->stateConfVectorPosition = 0;
  171. }
  172. /* 'default' enter sequence for state B */
  173. static void guardedEntry_enseq_main_region_B_default(GuardedEntry* handle)
  174. {
  175. /* 'default' enter sequence for state B */
  176. handle->stateConfVector[0] = GuardedEntry_main_region_B;
  177. handle->stateConfVectorPosition = 0;
  178. }
  179. /* 'default' enter sequence for region main region */
  180. static void guardedEntry_enseq_main_region_default(GuardedEntry* handle)
  181. {
  182. /* 'default' enter sequence for region main region */
  183. guardedEntry_react_main_region__entry_Default(handle);
  184. }
  185. /* Default exit sequence for state A */
  186. static void guardedEntry_exseq_main_region_A(GuardedEntry* handle)
  187. {
  188. /* Default exit sequence for state A */
  189. handle->stateConfVector[0] = GuardedEntry_last_state;
  190. handle->stateConfVectorPosition = 0;
  191. }
  192. /* Default exit sequence for state B */
  193. static void guardedEntry_exseq_main_region_B(GuardedEntry* handle)
  194. {
  195. /* Default exit sequence for state B */
  196. handle->stateConfVector[0] = GuardedEntry_last_state;
  197. handle->stateConfVectorPosition = 0;
  198. }
  199. /* Default exit sequence for region main region */
  200. static void guardedEntry_exseq_main_region(GuardedEntry* handle)
  201. {
  202. /* Default exit sequence for region main region */
  203. /* Handle exit of all possible states (of GuardedEntry.main_region) at position 0... */
  204. switch(handle->stateConfVector[ 0 ])
  205. {
  206. case GuardedEntry_main_region_A :
  207. {
  208. guardedEntry_exseq_main_region_A(handle);
  209. break;
  210. }
  211. case GuardedEntry_main_region_B :
  212. {
  213. guardedEntry_exseq_main_region_B(handle);
  214. break;
  215. }
  216. default: break;
  217. }
  218. }
  219. /* The reactions of state A. */
  220. static void guardedEntry_react_main_region_A(GuardedEntry* handle)
  221. {
  222. /* The reactions of state A. */
  223. if (guardedEntry_check_main_region_A_tr0_tr0(handle) == bool_true)
  224. {
  225. guardedEntry_effect_main_region_A_tr0(handle);
  226. }
  227. }
  228. /* The reactions of state B. */
  229. static void guardedEntry_react_main_region_B(GuardedEntry* handle)
  230. {
  231. /* The reactions of state B. */
  232. if (guardedEntry_check_main_region_B_tr0_tr0(handle) == bool_true)
  233. {
  234. guardedEntry_effect_main_region_B_tr0(handle);
  235. }
  236. }
  237. /* Default react sequence for initial entry */
  238. static void guardedEntry_react_main_region__entry_Default(GuardedEntry* handle)
  239. {
  240. /* Default react sequence for initial entry */
  241. guardedEntry_enseq_main_region_A_default(handle);
  242. }