Apollo  6.0
Open source self driving car software
global_data.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_COMMON_GLOBAL_DATA_H_
18 #define CYBER_COMMON_GLOBAL_DATA_H_
19 
20 #include <string>
21 #include <unordered_map>
22 
23 #include "cyber/proto/cyber_conf.pb.h"
24 
27 #include "cyber/common/log.h"
28 #include "cyber/common/macros.h"
29 #include "cyber/common/util.h"
30 
31 namespace apollo {
32 namespace cyber {
33 namespace common {
34 
35 using ::apollo::cyber::base::AtomicHashMap;
36 using ::apollo::cyber::proto::ClockMode;
37 using ::apollo::cyber::proto::CyberConfig;
38 using ::apollo::cyber::proto::RunMode;
39 
40 class GlobalData {
41  public:
42  ~GlobalData();
43 
44  int ProcessId() const;
45 
46  void SetProcessGroup(const std::string& process_group);
47  const std::string& ProcessGroup() const;
48 
49  void SetComponentNums(const int component_nums);
50  int ComponentNums() const;
51 
52  void SetSchedName(const std::string& sched_name);
53  const std::string& SchedName() const;
54 
55  const std::string& HostIp() const;
56 
57  const std::string& HostName() const;
58 
59  const CyberConfig& Config() const;
60 
61  void EnableSimulationMode();
62  void DisableSimulationMode();
63 
64  bool IsRealityMode() const;
65  bool IsMockTimeMode() const;
66 
67  static uint64_t GenerateHashId(const std::string& name) {
68  return common::Hash(name);
69  }
70 
71  static uint64_t RegisterNode(const std::string& node_name);
72  static std::string GetNodeById(uint64_t id);
73 
74  static uint64_t RegisterChannel(const std::string& channel);
75  static std::string GetChannelById(uint64_t id);
76 
77  static uint64_t RegisterService(const std::string& service);
78  static std::string GetServiceById(uint64_t id);
79 
80  static uint64_t RegisterTaskName(const std::string& task_name);
81  static std::string GetTaskNameById(uint64_t id);
82 
83  private:
84  void InitHostInfo();
85  bool InitConfig();
86 
87  // global config
88  CyberConfig config_;
89 
90  // host info
91  std::string host_ip_;
92  std::string host_name_;
93 
94  // process info
95  int process_id_;
96  std::string process_group_;
97 
98  int component_nums_ = 0;
99 
100  // sched policy info
101  std::string sched_name_ = "CYBER_DEFAULT";
102 
103  // run mode
104  RunMode run_mode_;
105  ClockMode clock_mode_;
106 
107  static AtomicHashMap<uint64_t, std::string, 512> node_id_map_;
108  static AtomicHashMap<uint64_t, std::string, 256> channel_id_map_;
109  static AtomicHashMap<uint64_t, std::string, 256> service_id_map_;
110  static AtomicHashMap<uint64_t, std::string, 256> task_id_map_;
111 
113 };
114 
115 } // namespace common
116 } // namespace cyber
117 } // namespace apollo
118 
119 #endif // CYBER_COMMON_GLOBAL_DATA_H_
void SetProcessGroup(const std::string &process_group)
static std::string GetNodeById(uint64_t id)
const std::string & SchedName() const
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
const std::string & ProcessGroup() const
static uint64_t GenerateHashId(const std::string &name)
Definition: global_data.h:67
static uint64_t RegisterNode(const std::string &node_name)
void SetComponentNums(const int component_nums)
static std::string GetChannelById(uint64_t id)
static uint64_t RegisterService(const std::string &service)
const CyberConfig & Config() const
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
static uint64_t RegisterChannel(const std::string &channel)
static uint64_t RegisterTaskName(const std::string &task_name)
std::size_t Hash(const std::string &key)
Definition: util.h:27
static std::string GetServiceById(uint64_t id)
const std::string & HostIp() const
Definition: global_data.h:40
const std::string & HostName() const
void SetSchedName(const std::string &sched_name)
static std::string GetTaskNameById(uint64_t id)