forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShellState.h
87 lines (65 loc) · 1.8 KB
/
ShellState.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef TOOLS_SHELL_SHELLSTATE
#define TOOLS_SHELL_SHELLSTATE
class ShellContext;
/*
* Currently, there are four types of state in total
* 1. start state: the first state the program enters
* 2. connecting state: the program try to connnect to a rocksdb server, whose
* previous states could be "start" or "connected" states
* 3. connected states: the program has already connected to a server, and is
* processing user commands
* 4. stop state: the last state the program enters, do some cleanning up things
*/
class ShellState {
public:
virtual void run(ShellContext *) = 0;
virtual ~ShellState() {}
};
class ShellStateStart : public ShellState {
public:
static ShellStateStart * getInstance(void) {
static ShellStateStart instance;
return &instance;
}
virtual void run(ShellContext *);
private:
ShellStateStart() {}
virtual ~ShellStateStart() {}
};
class ShellStateStop : public ShellState {
public:
static ShellStateStop * getInstance(void) {
static ShellStateStop instance;
return &instance;
}
virtual void run(ShellContext *);
private:
ShellStateStop() {}
virtual ~ShellStateStop() {}
};
class ShellStateConnecting : public ShellState {
public:
static ShellStateConnecting * getInstance(void) {
static ShellStateConnecting instance;
return &instance;
}
virtual void run(ShellContext *);
private:
ShellStateConnecting() {}
virtual ~ShellStateConnecting() {}
};
class ShellStateConnected : public ShellState {
public:
static ShellStateConnected * getInstance(void) {
static ShellStateConnected instance;
return &instance;
}
virtual void run(ShellContext *);
private:
ShellStateConnected() {}
virtual ~ShellStateConnected() {}
void unknownCmd();
void handleConError(ShellContext *);
void helpMsg();
};
#endif