hce-node application
1.4.3
HCE Hierarchical Cluster Engine node application
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
StatusHandler.h
Go to the documentation of this file.
1
#ifndef STATUSHANDLER_H
2
#define STATUSHANDLER_H
3
#include <time.h>
4
#include <new>
5
#include <
BaseHandler.h
>
6
#include <
AStorageHandler.h
>
7
class
StatusHandler
:
public
BaseHandler
8
{
9
public
:
10
enum
State
11
{
12
RUN
= 1,
SUSPEND
,
STOP
,
SHUTDOWN
,
RESTART
,
RECOVER
,
NOTLOADED
,
LISTEN
13
};
14
StatusHandler
(
AStorageHandler
*statistic,
State
state
=
RUN
):
BaseHandler
(100),current(
state
), changeDate(0), statisticHandler(statistic)
15
{
16
statisticHandler->
setValue
(
"ApplicationState"
, (
long
long
)
state
);
17
}
18
State
getState
(){
return
current;}
19
bool
recover
(){
return
current ==
RECOVER
;}
20
bool
shutdown
(){
return
current ==
SHUTDOWN
;}
21
bool
restart
(){
return
current ==
RESTART
;}
22
bool
stop
(){
return
current ==
STOP
;}
23
bool
suspend
(){
return
current ==
SUSPEND
;}
24
bool
run
(){
return
current ==
RUN
;}
25
void
setState
(
State
state
)
26
{
27
current =
state
;
28
changeDate =
time
(NULL);
29
statisticHandler->
setValue
(
"ApplicationState"
, (
long
long
)current);
30
}
31
void
*
handle
(
char
command
, ...)
32
{
33
setError
(0, NULL);
34
time_t *date = NULL;
35
switch
(command)
36
{
37
case
'a'
:
38
{
39
if
(current ==
RUN
)
40
{
41
setError
(1,
"Already run"
);
42
}
43
else
44
{
45
date =
new
(std::nothrow) time_t;
46
if
(!date)
47
{
48
setError
(E_MEMORY,
"Out of memory"
);
49
return
NULL;
50
}
51
changeDate = *date =
time
(NULL);
52
current =
RUN
;
53
statisticHandler->
setValue
(
"ApplicationState"
, 1ll);
54
}
55
break
;
56
}
57
case
'b'
:
58
{
59
if
(current !=
RUN
&& current !=
LISTEN
)
60
{
61
setError
(2,
"Not runing"
);
62
}
63
else
64
{
65
date =
new
(std::nothrow) time_t;
66
if
(!date)
67
{
68
setError
(E_MEMORY,
"Out of memory"
);
69
return
NULL;
70
}
71
changeDate = *date =
time
(NULL);
72
current =
SUSPEND
;
73
statisticHandler->
setValue
(
"ApplicationState"
, 2ll);
74
}
75
break
;
76
}
77
case
'c'
:
78
{
79
if
(current !=
RUN
|| current !=
SUSPEND
)
80
{
81
setError
(3,
"Not runing and not in suspend"
);
82
}
83
else
84
{
85
date =
new
(std::nothrow) time_t;
86
if
(!date)
87
{
88
setError
(E_MEMORY,
"Out of memory"
);
89
return
NULL;
90
}
91
changeDate = *date =
time
(NULL);
92
current =
STOP
;
93
statisticHandler->
setValue
(
"ApplicationState"
, 3ll);
94
}
95
break
;
96
}
97
case
'd'
:
98
{
99
if
(current ==
SHUTDOWN
)
100
{
101
setError
(4,
"Already shutdown"
);
102
}
103
else
104
{
105
date =
new
(std::nothrow) time_t;
106
if
(!date)
107
{
108
setError
(E_MEMORY,
"Out of memory"
);
109
return
NULL;
110
}
111
changeDate = *date =
time
(NULL);
112
current =
SHUTDOWN
;
113
statisticHandler->
setValue
(
"ApplicationState"
, 4ll);
114
}
115
break
;
116
}
117
case
'e'
:
118
{
119
if
(current ==
RESTART
)
120
{
121
setError
(5,
"Already in restart state"
);
122
}
123
else
124
{
125
date =
new
(std::nothrow) time_t;
126
if
(!date)
127
{
128
setError
(E_MEMORY,
"Out of Memory"
);
129
return
NULL;
130
}
131
changeDate = *date =
time
(NULL);
132
current =
RESTART
;
133
statisticHandler->
setValue
(
"ApplicationState"
, 5ll);
134
}
135
break
;
136
}
137
case
'f'
:
138
{
139
date =
new
(std::nothrow) time_t;
140
if
(!date)
141
{
142
setError
(E_MEMORY,
"Out of memory"
);
143
return
NULL;
144
}
145
changeDate = *date =
time
(NULL);
146
current =
RECOVER
;
147
break
;
148
}
149
default
:
150
{
151
setError
(1,
"Wrong command code"
);
152
break
;
153
}
154
}
155
return
date;
156
}
157
158
private
:
159
State
current;
160
time_t changeDate;
161
AStorageHandler
*statisticHandler;
162
};
163
164
#endif
sources
utils
applicationFramework
src
StatusHandler.h
Generated on Tue Jun 30 2015 19:42:10 for hce-node application by
1.8.1.2