Apollo  6.0
Open source self driving car software
state.h
Go to the documentation of this file.
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 {
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() {
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_
State
Definition: state.h:34
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void AsyncShutdown()
Definition: state.h:56
Definition: state.h:38
bool IsShutdown()
Definition: state.h:46
Definition: state.h:36
State GetState()
#define AERROR
Definition: log.h:44
bool OK()
Definition: state.h:44
void SetState(const State &state)
void WaitForShutdown()
Definition: state.h:50