Apollo 11.0
自动驾驶开放平台
scene_manager.cc
浏览该文件的文档.
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 *****************************************************************************/
17
18#include "cyber/common/file.h"
19#include "modules/perception/common/lidar/scene_manager/proto/scene_manager_config.pb.h"
21#include "modules/perception/common/proto/perception_config_schema.pb.h"
22
23namespace apollo {
24namespace perception {
25namespace lidar {
26
28
30 if (initialized_) {
31 return true;
32 }
33
34 std::string config_file = FLAGS_scene_manager_file;
35 if (!options.config_file.empty()) {
36 config_file = options.config_file;
37 }
38 config_file = GetCommonConfigFile(config_file);
39 SceneManagerConfig config;
40 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
41 services_.clear();
42 for (int i = 0; i < config.service_name_size(); ++i) {
43 const auto& name = config.service_name(i);
44 SceneServicePtr service(SceneServiceRegisterer::GetInstanceByName(name));
45 if (service == nullptr) {
46 AINFO << "Failed to find scene service: " << name << ", skipped";
47 continue;
48 }
49 if (!service->Init()) {
50 AINFO << "Failed to init scene service: " << name << ", skipped";
51 continue;
52 }
53 services_.emplace(name, service);
54 AINFO << "Scene manager add service: " << name;
55 }
56 initialized_ = true;
57 return true;
58}
59
61 std::lock_guard<std::mutex> lock(mutex_);
62 bool status = InitInternal();
63 return status;
64}
65
67 std::lock_guard<std::mutex> lock(mutex_);
68 initialized_ = false;
69 bool status = InitInternal(options);
70 return status;
71}
72
73SceneServicePtr SceneManager::Service(const std::string& name) {
74 auto iter = services_.find(name);
75 if (iter == services_.end()) {
76 return nullptr;
77 }
78 return iter->second;
79}
80
81} // namespace lidar
82} // namespace perception
83} // namespace apollo
SceneServicePtr Service(const std::string &name)
bool InitInternal(const SceneManagerInitOptions &options=SceneManagerInitOptions())
std::map< std::string, SceneServicePtr > services_
bool Reset(const SceneManagerInitOptions &options=SceneManagerInitOptions())
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
std::string GetAbsolutePath(const std::string &prefix, const std::string &relative_path)
Get absolute path by concatenating prefix and relative_path.
Definition file.cc:179
std::shared_ptr< SceneService > SceneServicePtr
std::string GetCommonConfigFile(const std::string &config_file)
Get the perception common config path
Definition util.cc:28
class register implement
Definition arena_queue.h:37