qpcpp/doxygen/snippets/qf_state.cpp

40 lines
1.0 KiB
C++
Raw Normal View History

2013-10-10 20:01:51 -04:00
namespace DPP {
. . .
QP::QState Philo::eating(Philo * const me, QP::QEvt const * const e) {
QP::QState status;
2012-08-14 18:00:48 -04:00
switch (e->sig) {
case Q_ENTRY_SIG: {
2013-10-10 20:01:51 -04:00
me->m_timeEvt.postIn(me, eat_time());
status = Q_HANDLED();
break;
}
case Q_EXIT_SIG: {
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
pe->philoNum = PHILO_ID(me);
QP::QF::PUBLISH(pe, me);
(void)me->m_timeEvt.disarm();
status = Q_HANDLED();
break;
2012-08-14 18:00:48 -04:00
}
case TIMEOUT_SIG: {
2013-10-10 20:01:51 -04:00
status = Q_TRAN(&Philo::thinking);
break;
2012-08-14 18:00:48 -04:00
}
2013-10-10 20:01:51 -04:00
case EAT_SIG: // intentionally fall through
case DONE_SIG: {
// EAT or DONE must be for other Philos than this one
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
status = Q_HANDLED();
break;
}
default: {
status = Q_SUPER(&QHsm::top);
break;
2012-08-14 18:00:48 -04:00
}
}
2013-10-10 20:01:51 -04:00
return status;
2012-08-14 18:00:48 -04:00
}
2013-10-10 20:01:51 -04:00
} // namespace DPP