Ejemplo n.º 1
0
bool Automaton::step()
{
	//cout << this->name << " state: " << this->cur->id << " ";
	for (int i=0; i < cur->transitions.size(); i++) {
		Transition * t = cur->transitions[i];
		if (t->guard() && t->next->inv()) { // если выполнено условие
			if (t->needSync() ) {// если есть действия по синхронизации
				bool sync = t->synchronize();
				//cout << " channel " << t->channelParticipant->channel->id	<< " ";
				if (sync) {
					t->action(); //выполняем действия перехода
					cerr << "time = " << net->timeForInternalUse << " " << name << ": " << cur->name << " -> " << t->next->name << endl;
					cur = t->next; //изменяем текущее состояние
					//cout << this->cur->id << "\n";
					return true; //был совершен переход
				}
			}
			else { // синхронизации нет, условие выполнено
				t->action(); //выполняем действия перехода
				cerr << "time = " << net->timeForInternalUse << " " << name << ": " << cur->name << " -> " << t->next->name << endl;
				cur = t->next; //изменяем текущее состояние
				//cout << this->cur->id << "\n";
				return true; //был совершен переход
			}
		}
	}
	//cout << "no trans\n";
	return false; //перехода не было
}
Ejemplo n.º 2
0
void StateMachine::calculate(int event) {

	char buffer[50];

	sprintf(buffer, "Event: %d", event);
	SerialDebugger.debug(STATUSUPDATE, "StateMachine::calculate", buffer);

	Transition* ptrT = current->getTransition(event);

	if (ptrT != 0) {
		char name_current[20];
		char name_next[20];

		current->getName().toCharArray(name_current, 20, 0);
		ptrT->target->getName().toCharArray(name_next, 20, 0);

		sprintf(buffer, "Zustandsübergang: %s -> %s", name_current, name_next);

		SerialDebugger.debug(STATUSUPDATE, "StateMachine::calculate", buffer);

		current->stop();
		ptrT->action();
		current = ptrT->target;
		current->start();

	} else {
		SerialDebugger.debug(NOTIFICATION, "StateMachine::calculate",
				"keine Transition");
	}

}
Ejemplo n.º 3
0
 /*!
  * @brief Method used to perform transition action.
  *        Should be overriden in derived classes if change of the behaviour is desired.
  * @param[in] transition Information about the transition
  * @return True if action was successful
  * */
 virtual bool do_transition(const Transition& transition) {
     return transition.action(transition);
 }