Elma
An event loop manager for embedded systems
state.h
1 #ifndef _ELMA_STATE_H
2 #define _ELMA_STATE_H
3 
4 #include <string>
5 #include "elma.h"
6 
7 namespace elma {
8 
9  class StateMachine;
10 
12 
14  class State {
15 
16  friend class StateMachine;
17 
18  public:
19 
21  State() : _name("unnamed state"), _state_machine_ptr(NULL) {
22  _id = _id_counter++;
23  }
24 
26  State(std::string name) : _name(name), _state_machine_ptr(NULL) {
27  _id = _id_counter++;
28  }
29 
31  inline std::string name() { return _name; }
32 
34  inline int id() { return _id; }
35 
40  virtual void entry(const Event& e) = 0;
41 
44  virtual void during() = 0;
45 
50  virtual void exit(const Event& e) = 0;
51 
54  void emit(const Event& e);
55 
57  StateMachine& state_machine() { return *_state_machine_ptr; }
58 
59  private:
60  std::string _name;
61  int _id;
62  static int _id_counter;
63  StateMachine * _state_machine_ptr;
64 
65  };
66 
67 }
68 
69 #endif
int id()
Definition: state.h:34
virtual void entry(const Event &e)=0
State()
Construct an unnamed State.
Definition: state.h:21
Events that can be emitted, watched, and responded to with event handlers.
Definition: event.h:23
StateMachine & state_machine()
Definition: state.h:57
States for the StateMachine class.
Definition: state.h:14
virtual void exit(const Event &e)=0
std::string name()
Definition: state.h:31
State(std::string name)
Construct a state with the given name.
Definition: state.h:26
void emit(const Event &e)
Definition: state.cc:5
virtual void during()=0
A finite state machine class.
Definition: state_machine.h:13
Definition: channel.cc:5