Implement unscheduleTimeout & XFInitialState

This commit is contained in:
2023-11-27 17:07:15 +01:00
parent 0ccfd522ee
commit 2c5fa52b9f
8 changed files with 82 additions and 139 deletions

View File

@@ -14,9 +14,15 @@
XFState::XFState(XFBehavior* behavior)
: pBehavior(behavior) {
assert(behavior != nullptr);
cbState_ = nullptr;
cbEntry_ = nullptr;
cbExit_ = nullptr;
cbEvState_ = nullptr;
cbEvEntry_ = nullptr;
cbEvExit_ = nullptr;
}
void XFState::setNextState(const int evid, const int time, XFEvent::XFEventType type, XFState* state) {
void XFState::addTransition(XFEvent::XFEventType type, const int evid, const int time, XFState* state) {
assert(state != nullptr);
transition t;
t.evid = evid;
@@ -28,9 +34,6 @@ void XFState::setNextState(const int evid, const int time, XFEvent::XFEventType
XFEventStatus XFState::onState(const XFEvent* ev) {
assert(ev != nullptr);
assert(pBehavior != nullptr);
if(cbState_ != nullptr) {
(pBehavior->*cbState_)();
}
@@ -39,7 +42,6 @@ XFEventStatus XFState::onState(const XFEvent* ev) {
}
for(transition t : transitions_) {
assert(t.nextState != nullptr);
if(t.evType == XFEvent::XFEventType::Initial){
pBehavior->curentXFState_ = t.nextState;
@@ -68,12 +70,12 @@ void XFState::onEntry(const XFEvent* ev) {
if(cbEntry_ != nullptr) {
(pBehavior->*cbEntry_)();
}
if(cbEvEntry_ != nullptr) {
(pBehavior->*cbEvEntry_)(ev);
}
for(transition t : transitions_) {
assert(t.nextState != nullptr);
if(t.evType == XFEvent::XFEventType::Timeout) {
pBehavior->scheduleTimeout(XFEvent::Timeout, t.time);
@@ -85,7 +87,17 @@ void XFState::onExit(const XFEvent* ev) {
if(cbExit_ != nullptr) {
(pBehavior->*cbExit_)();
}
if(cbEvExit_ != nullptr) {
(pBehavior->*cbEvExit_)(ev);
}
for(transition t: transitions_) {
if(t.evType == XFEvent::XFEventType::Timeout) {
if(ev->getEventType() != XFEvent::XFEventType::Timeout) {
pBehavior->unscheduleTimeout(XFEvent::Timeout);
}
}
}
}