-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstate_machine.cpp.old
More file actions
48 lines (37 loc) · 1.15 KB
/
state_machine.cpp.old
File metadata and controls
48 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/** ***************************************************************************
* \file state_machine.cpp
* \author Hugo Gimbert - Olivier Ly
* \date 2010-12
*
* \brief State machine infrastructure.
*****************************************************************************/
#include "state_machine.h"
#include <list>
using namespace std;
/*****************************************************************************/
int StateMachine::reset() {
init();
if (init_state == NULL) return 0;
active_state = init_state;
init_state->entry();
return 1;
}
int StateMachine::tic() {
// checks preconditions
if (active_state==NULL) return -1;
if (!(active_state->is_sleeping())) {
active_state->activity();
this->activity();
};
// check transition
State * new_state = active_state->transition();
if (new_state != NULL) { // there is a transition
active_state->quit();
active_state = new_state;
active_state->entry();
}
if (active_state->terminal()) return 0;
else return 1;
}
StateMachine::StateMachine() : init_state(NULL), active_state(NULL) {}
/*****************************************************************************/