Apollo 10.0
自动驾驶开放平台
updater_with_channels_base.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
19#include <set>
20
21#include "cyber/cyber.h"
23
24namespace apollo {
25
26namespace dreamview {
28 const std::vector<std::string> &filter_message_types,
29 const std::vector<std::string> &filter_channels)
30 : filter_message_types_(filter_message_types),
31 filter_channels_(filter_channels) {}
32
34 const std::string &message_type, const std::string &channel_name) {
35 if (filter_message_types_.size() == 0 && filter_channels_.size() == 0) {
36 return true;
37 }
38 for (size_t i = 0; i < filter_message_types_.size(); ++i) {
39 if (message_type.rfind(filter_message_types_[i]) != std::string::npos &&
40 channel_name.rfind(filter_channels_[i]) != std::string::npos) {
41 return true;
42 }
43 }
44 return false;
45}
46
48 std::vector<std::string> *channels) {
49 auto channelManager =
50 apollo::cyber::service_discovery::TopologyManager::Instance()
51 ->channel_manager();
52 std::vector<apollo::cyber::proto::RoleAttributes> role_attr_vec;
53 channelManager->GetWriters(&role_attr_vec);
54 std::vector<std::string> records;
55 std::vector<std::string> other_record_node_name;
56 auto *record_player_factory = RecordPlayerFactory::Instance();
57 record_player_factory->GetAllRecords(&records);
58 const std::string current_record = record_player_factory->GetCurrentRecord();
59 for (auto iter = records.begin(); iter != records.end(); iter++) {
60 if (current_record.empty() || *iter != current_record) {
61 std::string other_node_name = "record_player_factory_" + *iter;
62 other_record_node_name.push_back(other_node_name);
63 }
64 }
65 std::vector<std::string> tmp_channels;
66 for (auto &role_attr : role_attr_vec) {
67 std::string messageType;
68 std::string node_name;
69 messageType = role_attr.message_type();
70 node_name = role_attr.node_name();
71 if (IsChannelInUpdater(messageType, role_attr.channel_name())) {
72 if (current_record.empty() ||
73 std::find(other_record_node_name.begin(),
74 other_record_node_name.end(),
75 node_name) == other_record_node_name.end()) {
76 tmp_channels.push_back(role_attr.channel_name());
77 }
78 }
79 }
80 std::set<std::string> s(tmp_channels.begin(), tmp_channels.end());
81 channels->assign(tmp_channels.begin(), tmp_channels.end());
82 channels_.clear();
83 channels_.assign(s.begin(), s.end());
84}
85
86} // namespace dreamview
87} // namespace apollo
bool IsChannelInUpdater(const std::string &message_type, const std::string &channel_name)
Check if the channel belongs to current updater.
UpdaterWithChannelsBase(const std::vector< std::string > &filter_message_types, const std::vector< std::string > &filter_channels)
void GetChannelMsgWithFilter(std::vector< std::string > *channels)
class register implement
Definition arena_queue.h:37