Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __INET_FSMA_H
00019 #define __INET_FSMA_H
00020
00021 #include "INETDefs.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #define FSMA_Switch(fsm) \
00100 bool ___is_event = true; \
00101 bool ___exit = false; \
00102 bool ___condition_seen = false; \
00103 int ___c = 0; \
00104 cFSM *___fsm = &fsm; \
00105 EV << "processing event in state machine " << (fsm).getName() << endl; \
00106 while (!___exit && (___c++ < FSM_MAXT || (opp_error(eINFLOOP, (fsm).getStateName()), 0)))
00107
00108 #define FSMA_Print(exiting) \
00109 (ev << "FSM " << ___fsm->getName() \
00110 << ((exiting) ? ": leaving state " : ": entering state ") \
00111 << ___fsm->getStateName() << endl)
00112
00113 #define FSMA_State(s) if (___condition_seen = false, ___exit = true, ___fsm->getState() == (s))
00114
00115 #define FSMA_Event_Transition(transition, condition, target, action) \
00116 ___condition_seen = true; if ((condition) && ___is_event) \
00117 { \
00118 ___is_event = false; \
00119 FSMA_Transition(transition, (condition), target, action)
00120
00121 #define FSMA_No_Event_Transition(transition, condition, target, action) \
00122 ___condition_seen = true; if ((condition) && !___is_event) \
00123 { \
00124 FSMA_Transition(transition, (condition), target, action)
00125
00126 #define FSMA_Transition(transition, condition, target, action) \
00127 FSMA_Print(true); \
00128 EV << "firing " << #transition << " transition for " << ___fsm->getName() << endl; \
00129 action; \
00130 ___fsm->setState(target, #target); \
00131 FSMA_Print(false); \
00132 ___exit = false; \
00133 continue; \
00134 }
00135
00136 #define FSMA_Enter(action) \
00137 if (!___is_event) \
00138 { \
00139 if (___condition_seen) \
00140 error("FSMA_Enter() must precede all FSMA_*_Transition()'s in the code"); \
00141 action; \
00142 }
00143
00144 #endif
00145