Apollo 11.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 std::vector<std::string> *channels, const std::string &filter_message_type,
29 const std::string &filter_channel, bool reverse_filter_channel) {
30 auto channelManager =
31 apollo::cyber::service_discovery::TopologyManager::Instance()
32 ->channel_manager();
33 std::vector<apollo::cyber::proto::RoleAttributes> role_attr_vec;
34 channelManager->GetWriters(&role_attr_vec);
35 std::vector<std::string> records;
36 std::vector<std::string> other_record_node_name;
37 auto *record_player_factory = RecordPlayerFactory::Instance();
38 record_player_factory->GetAllRecords(&records);
39 const std::string current_record = record_player_factory->GetCurrentRecord();
40 for (auto iter = records.begin(); iter != records.end(); iter++) {
41 if (current_record.empty() || *iter != current_record) {
42 std::string other_node_name = "record_player_factory_" + *iter;
43 other_record_node_name.push_back(other_node_name);
44 }
45 }
46 std::vector<std::string> tmp_channels;
47 for (auto &role_attr : role_attr_vec) {
48 std::string messageType;
49 std::string node_name;
50 messageType = role_attr.message_type();
51 node_name = role_attr.node_name();
52 int index = 0;
53 if (!filter_message_type.empty()) {
54 index = messageType.rfind(filter_message_type);
55 }
56 int index_channel = 0;
57 bool select_current_channel = filter_channel.empty();
58 if (!filter_channel.empty()) {
59 index_channel = role_attr.channel_name().rfind(filter_channel);
60 select_current_channel = reverse_filter_channel ? (index_channel == -1)
61 : (index_channel != -1);
62 }
63 if (index != -1 && select_current_channel) {
64 if (current_record.empty() ||
65 std::find(other_record_node_name.begin(),
66 other_record_node_name.end(),
67 node_name) == other_record_node_name.end()) {
68 tmp_channels.push_back(role_attr.channel_name());
69 }
70 }
71 }
72 std::set<std::string> s(tmp_channels.begin(), tmp_channels.end());
73 channels->assign(tmp_channels.begin(), tmp_channels.end());
74 channels_.clear();
75 channels_.assign(s.begin(), s.end());
76}
77
78} // namespace dreamview
79} // namespace apollo
void GetChannelMsgWithFilter(std::vector< std::string > *channels, const std::string &filter_message_type, const std::string &filter_channel, bool reverse_filter_channel=false)
GetChannelMsgWithFilter:by msg type and channel filter field to filter channels for DataUpdater
class register implement
Definition arena_queue.h:37