Apollo
10.0
自动驾驶开放平台
state.h
浏览该文件的文档.
1
/******************************************************************************
2
* Copyright 2018 The Apollo Authors. All Rights Reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*****************************************************************************/
16
17
#ifndef CYBER_STATE_H_
18
#define CYBER_STATE_H_
19
20
#include <sys/types.h>
21
#include <unistd.h>
22
23
#include <cerrno>
24
#include <csignal>
25
#include <cstdint>
26
#include <cstring>
27
#include <thread>
28
29
#include "
cyber/common/log.h
"
30
31
namespace
apollo
{
32
namespace
cyber {
33
34
enum
State
: std::uint8_t {
35
STATE_UNINITIALIZED
= 0,
36
STATE_INITIALIZED
,
37
STATE_SHUTTING_DOWN
,
38
STATE_SHUTDOWN
,
39
};
40
41
State
GetState
();
42
void
SetState
(
const
State
& state);
43
44
inline
bool
OK
() {
return
GetState
() ==
STATE_INITIALIZED
; }
45
46
inline
bool
IsShutdown
() {
47
return
GetState
() ==
STATE_SHUTTING_DOWN
||
GetState
() ==
STATE_SHUTDOWN
;
48
}
49
50
inline
void
WaitForShutdown
() {
51
while
(!
IsShutdown
()) {
52
std::this_thread::sleep_for(std::chrono::milliseconds(200));
53
}
54
}
55
56
inline
void
AsyncShutdown
() {
57
pid_t pid = getpid();
58
if
(kill(pid, SIGINT) != 0) {
59
AERROR
<< strerror(errno);
60
}
61
}
62
63
}
// namespace cyber
64
}
// namespace apollo
65
66
#endif
// CYBER_STATE_H_
log.h
AERROR
#define AERROR
Definition
log.h:44
apollo::cyber::IsShutdown
bool IsShutdown()
Definition
state.h:46
apollo::cyber::SetState
void SetState(const State &state)
Definition
state.cc:30
apollo::cyber::WaitForShutdown
void WaitForShutdown()
Definition
state.h:50
apollo::cyber::State
State
Definition
state.h:34
apollo::cyber::STATE_INITIALIZED
@ STATE_INITIALIZED
Definition
state.h:36
apollo::cyber::STATE_SHUTDOWN
@ STATE_SHUTDOWN
Definition
state.h:38
apollo::cyber::STATE_SHUTTING_DOWN
@ STATE_SHUTTING_DOWN
Definition
state.h:37
apollo::cyber::STATE_UNINITIALIZED
@ STATE_UNINITIALIZED
Definition
state.h:35
apollo::cyber::OK
bool OK()
Definition
state.h:44
apollo::cyber::GetState
State GetState()
Definition
state.cc:28
apollo::cyber::AsyncShutdown
void AsyncShutdown()
Definition
state.h:56
apollo
class register implement
Definition
arena_queue.h:37
cyber
state.h