bool StateMachine::triggerEvent(const std::string &event) { bool ret = false; std::string current = getCurrentStateName(); std::vector<Rule::ptr>::iterator iter; for (iter = rules_.begin(); iter < rules_.end(); ++iter) { Rule *rule = (*iter).get(); if (rule->getEventName() == event) { if (rule->getStateFrom() == getCurrentStateName()) { std::string stateTo = rule->getStateTo(); if (hasStateName(stateTo)) { setCurrentStateName(stateTo); on_state_changed_signal_(stateTo); ret = true; break; } } } } return ret; }
void FSM::translateToStateNextUpdateNoRepeat(int stateName) { if (getCurrentStateName() != stateName) { this->translateToStateNextUpdate(stateName); } }
void ofxStateMachine<T>::setError(string msg, float retryAgainInSeconds, int maxRetries_){ error = true; errorMsg = msg; numRetries++; waitTime = retryAgainInSeconds; maxRetries = maxRetries_; ofLogError("ofxStateMachine") << "Error '" << msg << "' while in state '" << getCurrentStateName() << "' " << "(" << numRetries<< "/" << maxRetries << ")"; ErrorStateEventArgs errArgs = {state, msg, numRetries}; ofNotifyEvent(eventStateError, errArgs, this); };
bool StateMachine::setCurrentStateName(const std::string &name) { if (! hasStateName(name)) { std::cout << "StateMachine::" << __FUNCTION__ << ": No such state " << name << std::endl; return false; } if (current_state_ != "") { getState(getCurrentStateName())->on_leaved_signal_(); } current_state_ = name; getState(name)->on_entered_signal_(); return true; }
void FSM::translateToStateNoRepeat(int stateName) { if (!_currentState || getCurrentStateName() != stateName) { translateToState(stateName); } }