19 #ifndef RTC_STATEMACHINE_H
20 #define RTC_STATEMACHINE_H
55 template <
class State>
259 template <
class State,
262 class Callback = void (
Listener::*)(
const States& states)
287 : m_num(num_of_state),
289 m_entry(m_num, (Callback)NULL),
290 m_predo(m_num, (Callback)NULL),
291 m_do(m_num, (Callback)NULL),
292 m_postdo(m_num, (Callback)NULL),
293 m_exit(m_num, (Callback)NULL),
303 : m_num(other.m_num),
304 m_listener(other.m_listener),
305 m_entry (other.m_entry),
306 m_predo (other.m_predo),
308 m_postdo(other.m_postdo),
309 m_exit (other.m_exit),
310 m_transit(other.m_transit),
311 m_states(other.m_states),
312 m_selftrans(other.m_selftrans)
325 std::swap(m_num, other.
m_num);
327 std::swap(m_entry, other.
m_entry);
328 std::swap(m_predo, other.
m_predo);
329 std::swap(m_do, other.
m_do);
330 std::swap(m_postdo, other.
m_postdo);
331 std::swap(m_exit, other.
m_exit);
333 std::swap(m_states, other.
m_states);
355 setNullFunc(m_entry, call_back);
356 setNullFunc(m_do, call_back);
357 setNullFunc(m_exit, call_back);
358 setNullFunc(m_predo, call_back);
359 setNullFunc(m_postdo, call_back);
360 m_transit = call_back;
382 assert(listener != NULL);
383 m_listener = listener;
414 m_entry.at(state) = call_back;
451 m_predo.at(state) = call_back;
488 m_do.at(state) = call_back;
525 m_postdo.at(state) = call_back;
562 m_exit.at(state) = call_back;
597 m_transit = call_back;
620 m_states.curr = states.curr;
621 m_states.prev = states.prev;
622 m_states.next = states.next;
647 Guard guard(m_mutex);
670 Guard guard(m_mutex);
671 return m_states.curr;
697 Guard guard(m_mutex);
698 return m_states.curr == state ? true :
false;
729 Guard guard(m_mutex);
730 m_states.next = state;
731 if (m_states.curr == state)
760 if (state.curr == state.next)
763 if (m_predo[state.curr] != NULL)
764 (m_listener->*m_predo [state.curr])(state);
766 if (need_trans())
return;
769 if (m_do[state.curr] != NULL)
770 (m_listener->*m_do [state.curr])(state);
772 if (need_trans())
return;
775 if (m_postdo[state.curr] != NULL)
776 (m_listener->*m_postdo[state.curr])(state);
780 if (m_exit[state.curr] != NULL)
781 (m_listener->*m_exit[state.curr])(state);
785 if (state.curr != state.next)
787 state.curr = state.next;
788 if(m_entry[state.curr] != NULL)
789 (m_listener->*m_entry[state.curr])(state);
790 update_curr(state.curr);
806 if (state.curr == state.next)
808 if (m_predo[state.curr] != NULL)
810 (m_listener->*m_predo[state.curr])(state);
816 if (m_exit[state.curr] != NULL)
818 (m_listener->*m_exit[state.curr])(state);
821 if (state.curr != state.next)
823 state.curr = state.next;
824 if(m_entry[state.curr] != NULL)
826 (m_listener->*m_entry[state.curr])(state);
828 update_curr(state.curr);
836 if (m_do[state.curr] != NULL)
838 (m_listener->*m_do[state.curr])(state);
846 if (m_postdo[state.curr] != NULL)
848 (m_listener->*m_postdo[state.curr])(state);
876 for (
size_t i(0); i < m_num; ++i)
878 s.push_back(nullfunc);
966 inline void sync(States& st)
968 Guard guard(m_mutex);
972 inline bool need_trans()
974 Guard guard(m_mutex);
975 return (m_states.curr != m_states.next);
978 inline void update_curr(
const State curr)
980 Guard guard(m_mutex);
981 m_states.curr = curr;
986 #endif // RTC_STATEMACHINE_H