qpcpp/doxygen/snippets/qf_state.cpp

40 lines
993 B
C++
Raw Normal View History

2013-10-10 20:01:51 -04:00
namespace DPP {
. . .
2019-03-28 11:59:31 -04:00
Q_STATE_DEF(Philo, eating) {
2013-10-10 20:01:51 -04:00
QP::QState status;
2012-08-14 18:00:48 -04:00
switch (e->sig) {
case Q_ENTRY_SIG: {
2019-03-28 11:59:31 -04:00
m_timeEvt.armX(eat_time());
status = Q_RET_HANDLED;
2013-10-10 20:01:51 -04:00
break;
}
case Q_EXIT_SIG: {
TableEvt *pe = Q_NEW(TableEvt, DONE_SIG);
2019-03-28 11:59:31 -04:00
pe->philoNum = PHILO_ID(this);
2013-10-10 20:01:51 -04:00
QP::QF::PUBLISH(pe, me);
2019-03-28 11:59:31 -04:00
m_timeEvt.disarm();
status = Q_RET_HANDLED);
2013-10-10 20:01:51 -04:00
break;
2012-08-14 18:00:48 -04:00
}
case TIMEOUT_SIG: {
2019-03-28 11:59:31 -04:00
status = tran(&thinking);
2013-10-10 20:01:51 -04:00
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
2019-03-28 11:59:31 -04:00
Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(this));
status = Q_RET_HANDLED;
2013-10-10 20:01:51 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status = super(&top);
2013-10-10 20:01:51 -04:00
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