-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFsm.h
55 lines (45 loc) · 1.01 KB
/
Fsm.h
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
49
50
51
52
53
54
55
#ifndef FSM_H
#define FSM_H
#include <memory>
#include <mutex>
#include <map>
#include <string>
#include <condition_variable>
#include <queue>
#include "Event.h"
#include "Noncopyable.h"
using std::shared_ptr;
using std::mutex;
using std::lock_guard;
using std::map;
using std::string;
using std::condition_variable;
using std::queue;
class State;
class FSM : public NonCopyableForAll
{
private:
FSM() : curState(nullptr) {}
public:
~FSM() = default;
public:
static shared_ptr<FSM> GentInstance();
public:
void BuildStateChart();
shared_ptr<State> FootPrint();
void UpdateFootPrint(shared_ptr<State> s);
shared_ptr<State> SearchState(const string name);
void Birth();
void Feed(const Event& msg);
void Consume(const Event& event);
private:
shared_ptr<State> curState;
mutex lock;
mutex eventLock;
map<string, shared_ptr<State> > states;
condition_variable cv;
mutex cvMutex;
queue<Event> messageQue;
static shared_ptr<FSM> instance;
};
#endif // FSM_H