6 #ifndef STATE_MACHINE_SM_EVENT_H
7 #define STATE_MACHINE_SM_EVENT_H
12 namespace mcx::state_machine {
15 HIGH_PRIORITY_EVENT = 0,
16 LOW_PRIORITY_EVENT = 1,
25 EVENT_REPEAT_NO_TERMINATE = 4
43 template <
class STATE>
45 typedef EventStatus (STATE::*Signature)();
48 Event() : onceExecutedFlag_(
false), timeoutSec_(0), termFunc_(
nullptr) {}
50 virtual ~
Event() =
default;
52 virtual EventStatus dispatchEvent(STATE* state) = 0;
54 void setTerminateFunc(Signature term_func) { termFunc_ = term_func; }
56 const Signature& getTerminateFunc() {
return termFunc_; }
58 void setExecutedOnceFlag(
bool once_executed_flag) { onceExecutedFlag_ = once_executed_flag; }
60 bool getExecutedOnceFlag() {
return onceExecutedFlag_; }
62 void setTimeoutSec(
double timeout_sec) { timeoutSec_ = timeout_sec; }
64 double getTimeoutSec() {
return timeoutSec_; }
66 virtual bool compare(
const Event* cmp) {
return false; }
69 bool onceExecutedFlag_;
74 template <
class STATE>
76 typedef EventStatus (STATE::*Signature)();
79 _Event0(Signature event_func) : eventFunc_(event_func) {}
83 EventStatus dispatchEvent(STATE* state) {
return (state->*eventFunc_)(); }
91 template <
class STATE,
class P1>
93 typedef EventStatus (STATE::*Signature)(P1);
96 _Event1(Signature event_func,
const typename DR<P1>::T& param1) : eventFunc_(event_func), param1_(param1) {}
98 EventStatus dispatchEvent(STATE* state) {
return (state->*eventFunc_)(param1_); }
105 Signature eventFunc_;
109 template <
class STATE,
class P1,
class P2>
111 typedef EventStatus (STATE::*Signature)(P1, P2);
115 : eventFunc_(event_func), param1_(param1), param2_(param2) {}
117 EventStatus dispatchEvent(STATE* state) {
return (state->*eventFunc_)(param1_, param2_); }
124 Signature eventFunc_;
129 template <
class STATE,
class P1,
class P2,
class P3>
131 typedef EventStatus (STATE::*Signature)(P1, P2, P3);
136 : eventFunc_(event_func), param1_(param1), param2_(param2), param3_(param3) {}
138 EventStatus dispatchEvent(STATE* state) {
return (state->*eventFunc_)(param1_, param2_, param3_); }
145 Signature eventFunc_;
151 template <
class STATE>
162 template <
class STATE>
168 template <
class STATE>
172 Event1(EventStatus (STATE::*event)(P1),
const typename DR<P1>::T& p1 = {}) {
177 template <
class STATE>
180 template <
class P1,
class P2>
186 template <
class STATE>
189 template <
class P1,
class P2,
class P3>
190 Event3(EventStatus (STATE::*event)(P1, P2, P3),
const typename DR<P1>::T& p1 = {},
const typename DR<P2>::T& p2 = {},
198 #endif // STATE_MACHINE_SM_EVENT_H