Apollo 10.0
自动驾驶开放平台
updater_manager.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
19namespace apollo {
20
21namespace dreamview {
22
23bool UpdaterManager::Start(const std::string& path_name,
24 const double& time_interval_ms,
25 const std::string& channel_name,
26 nlohmann::json* subscribe_param) {
27 auto iter = updater_map_.find(path_name);
28 if (iter == updater_map_.end()) {
29 AERROR << "Related data updater for " << path_name
30 << " is not exists, failed to start!";
31 return false;
32 }
33 UpdaterBase* updater = iter->second;
34 updater->StartStream(time_interval_ms, channel_name, subscribe_param);
35 return true;
36}
37
38bool UpdaterManager::Stop(const std::string& path_name,
39 const std::string& channel_name) {
40 auto iter = updater_map_.find(path_name);
41 if (iter == updater_map_.end()) {
42 AERROR << "Related data updater for " << path_name
43 << " is not exists,failed to stop!";
44 return false;
45 }
46 UpdaterBase* updater = iter->second;
47 updater->StopStream(channel_name);
48 return true;
49}
50
51void UpdaterManager::RegisterUpdater(std::string path_name,
52 UpdaterBase* updater) {
53 updater_map_[path_name] = updater;
54}
55
56UpdaterBase* UpdaterManager::GetUpdater(const std::string& path_name) {
57 if (updater_map_.find(path_name) == updater_map_.end()) {
58 return nullptr;
59 }
60 return updater_map_[path_name];
61}
62
63bool UpdaterManager::IsChannelInUpdater(const std::string& path_name,
64 const std::string& message_type,
65 const std::string& channel_name) {
66 UpdaterBase* updater = GetUpdater(path_name);
67 UpdaterWithChannelsBase* updater_with_channels =
68 dynamic_cast<UpdaterWithChannelsBase*>(updater);
69 if (updater_with_channels == nullptr) {
70 return false;
71 }
72
73 return updater_with_channels->IsChannelInUpdater(message_type, channel_name);
74}
75
76} // namespace dreamview
77} // namespace apollo
Base Class for all data updater.
virtual void StopStream(const std::string &channel_name="")=0
Stop data flow.
virtual void StartStream(const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr)=0
Start data flow.
void RegisterUpdater(std::string path_name, UpdaterBase *updater)
Register data updater by websocket path name.
bool Start(const std::string &path_name, const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr)
Start a updater implemetnent.
UpdaterBase * GetUpdater(const std::string &path_name)
Get registered updater
bool Stop(const std::string &path_name, const std::string &channel_name)
Stop updater publish data.
bool IsChannelInUpdater(const std::string &path_name, const std::string &message_type, const std::string &channel_name)
Check if the channel belongs to an updater.
Base Class for data updater with multiply channels.
bool IsChannelInUpdater(const std::string &message_type, const std::string &channel_name)
Check if the channel belongs to current updater.
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37
UpdaterManager to manage all data updater.