Apollo 10.0
自动驾驶开放平台
global_data.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_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#include "cyber/proto/transport_conf.pb.h"
25
28#include "cyber/common/log.h"
29#include "cyber/common/macros.h"
30#include "cyber/common/util.h"
31
32namespace apollo {
33namespace cyber {
34namespace common {
35
36using ::apollo::cyber::base::AtomicHashMap;
37using ::apollo::cyber::proto::ClockMode;
38using ::apollo::cyber::proto::CyberConfig;
39using ::apollo::cyber::proto::RunMode;
40
42 public:
44
45 int ProcessId() const;
46
47 void SetProcessGroup(const std::string& process_group);
48 const std::string& ProcessGroup() const;
49
50 void SetComponentNums(const int component_nums);
51 int ComponentNums() const;
52
53 void SetSchedName(const std::string& sched_name);
54 const std::string& SchedName() const;
55
56 const std::string& HostIp() const;
57
58 const std::string& HostName() const;
59
60 const CyberConfig& Config() const;
61
64
65 bool IsRealityMode() const;
66 bool IsMockTimeMode() const;
67
68 bool IsChannelEnableArenaShm(std::string channel_name) const;
69 bool IsChannelEnableArenaShm(uint64_t channel_id) const;
71 std::string channel_name) const&;
73 uint64_t channel_id) const&;
74
75 static uint64_t GenerateHashId(const std::string& name) {
76 return common::Hash(name);
77 }
78
79 static uint64_t RegisterNode(const std::string& node_name);
80 static std::string GetNodeById(uint64_t id);
81
82 static uint64_t RegisterChannel(const std::string& channel);
83 static std::string GetChannelById(uint64_t id);
84
85 static uint64_t RegisterService(const std::string& service);
86 static std::string GetServiceById(uint64_t id);
87
88 static uint64_t RegisterTaskName(const std::string& task_name);
89 static std::string GetTaskNameById(uint64_t id);
90
91 private:
92 void InitHostInfo();
93 bool InitConfig();
94
95 // global config
96 CyberConfig config_;
97
98 // host info
99 std::string host_ip_;
100 std::string host_name_;
101
102 // process info
103 int process_id_;
104 std::string process_group_;
105
106 int component_nums_ = 0;
107
108 // sched policy info
109 std::string sched_name_ = "CYBER_DEFAULT";
110
111 // run mode
112 RunMode run_mode_;
113 ClockMode clock_mode_;
114
115 static AtomicHashMap<uint64_t, std::string, 512> node_id_map_;
116 static AtomicHashMap<uint64_t, std::string, 256> channel_id_map_;
117 static AtomicHashMap<uint64_t, std::string, 256> service_id_map_;
118 static AtomicHashMap<uint64_t, std::string, 256> task_id_map_;
119
121};
122
123} // namespace common
124} // namespace cyber
125} // namespace apollo
126
127#endif // CYBER_COMMON_GLOBAL_DATA_H_
const std::string & HostIp() const
const std::string & SchedName() const
bool IsChannelEnableArenaShm(std::string channel_name) const
void SetSchedName(const std::string &sched_name)
static std::string GetServiceById(uint64_t id)
void SetProcessGroup(const std::string &process_group)
const std::string & HostName() const
const std::string & ProcessGroup() const
static std::string GetChannelById(uint64_t id)
static uint64_t RegisterNode(const std::string &node_name)
static std::string GetTaskNameById(uint64_t id)
apollo::cyber::proto::ArenaChannelConf GetChannelArenaConf(std::string channel_name) const &
static uint64_t RegisterService(const std::string &service)
static std::string GetNodeById(uint64_t id)
static uint64_t RegisterChannel(const std::string &channel)
void SetComponentNums(const int component_nums)
const CyberConfig & Config() const
static uint64_t RegisterTaskName(const std::string &task_name)
static uint64_t GenerateHashId(const std::string &name)
Definition global_data.h:75
#define DECLARE_SINGLETON(classname)
Definition macros.h:52
std::size_t Hash(const std::string &key)
Definition util.h:27
class register implement
Definition arena_queue.h:37