Apollo 10.0
自动驾驶开放平台
fuel_monitor_manager.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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
18
19#include <utility>
20
21#include "cyber/common/log.h"
22
23namespace apollo {
24namespace dreamview {
25
26FuelMonitorManager::FuelMonitorManager() {}
27
29 const std::string& mode, std::unique_ptr<FuelMonitor>&& fuel_monitor) {
30 const auto& class_name = fuel_monitor->GetClassName();
31 if (monitors_.find(mode) != monitors_.end() &&
32 monitors_[mode].find(class_name) != monitors_[mode].end()) {
33 AWARN << class_name << " for mode: " << mode << " has been exist!";
34 } else {
35 monitors_[mode].emplace(class_name, std::move(fuel_monitor));
36 AINFO << "Registered " << class_name << " for mode: " << mode;
37 }
38}
39
40void FuelMonitorManager::SetCurrentMode(const std::string& mode) {
41 current_mode_ = mode;
42 if (monitors_.find(mode) != monitors_.end()) {
43 FuelMonitorMap* new_monitors = &monitors_[mode];
44 if (current_monitors_ != nullptr && current_monitors_ != new_monitors) {
45 for (const auto& monitor : *current_monitors_) {
46 monitor.second->Stop();
47 }
48 }
49 {
50 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
51 current_monitors_ = new_monitors;
52 }
53 for (const auto& monitor : *current_monitors_) {
54 monitor.second->Start();
55 }
56 } else if (current_monitors_ != nullptr) {
57 for (const auto& monitor : *current_monitors_) {
58 monitor.second->Stop();
59 }
60 }
61}
62
64 boost::unique_lock<boost::shared_mutex> reader_lock(mutex_);
65 return current_monitors_;
66}
67
68} // namespace dreamview
69} // namespace apollo
void RegisterFuelMonitor(const std::string &mode, std::unique_ptr< FuelMonitor > &&fuel_monitor)
void SetCurrentMode(const std::string &mode)
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
std::unordered_map< std::string, std::unique_ptr< FuelMonitor > > FuelMonitorMap
class register implement
Definition arena_queue.h:37