Apollo 10.0
自动驾驶开放平台
apollo::cyber::service_discovery::ChannelManager类 参考

Topology Manager of Service related 更多...

#include <channel_manager.h>

类 apollo::cyber::service_discovery::ChannelManager 继承关系图:
apollo::cyber::service_discovery::ChannelManager 的协作图:

Public 类型

using RoleAttrVec = std::vector< proto::RoleAttributes >
 
using WriterWarehouse = MultiValueWarehouse
 
using ReaderWarehouse = MultiValueWarehouse
 
using ExemptedMessageTypes = std::unordered_set< std::string >
 
- Public 类型 继承自 apollo::cyber::service_discovery::Manager
using ChangeSignal = base::Signal< const ChangeMsg & >
 
using ChangeFunc = std::function< void(const ChangeMsg &)>
 
using ChangeConnection = base::Connection< const ChangeMsg & >
 
using ParticipantPtr = std::shared_ptr< transport::Participant >
 
using PublisherPtr = std::shared_ptr< transport::Publisher >
 
using SubscriberPtr = std::shared_ptr< transport::Subscriber >
 

Public 成员函数

 ChannelManager ()
 Construct a new Channel Manager object
 
virtual ~ChannelManager ()
 Destroy the Channel Manager object
 
void GetChannelNames (std::vector< std::string > *channels)
 Get all channel names in the topology
 
void GetProtoDesc (const std::string &channel_name, std::string *proto_desc)
 Get the Protocol Desc of channel_name
 
void GetMsgType (const std::string &channel_name, std::string *msg_type)
 Get the Msg Type of channel_name
 
bool HasWriter (const std::string &channel_name)
 Inquire if there is at least one Writer that publishes channel_name
 
void GetWriters (RoleAttrVec *writers)
 Get All Writers object
 
void GetWritersOfNode (const std::string &node_name, RoleAttrVec *writers)
 Get the Writers Of Node object
 
void GetWritersOfChannel (const std::string &channel_name, RoleAttrVec *writers)
 Get the Writers Of Channel object
 
bool HasReader (const std::string &channel_name)
 Inquire if there is at least one Reader that publishes channel_name
 
void GetReaders (RoleAttrVec *readers)
 Get All Readers object
 
void GetReadersOfNode (const std::string &node_name, RoleAttrVec *readers)
 Get the Readers Of Node object
 
void GetReadersOfChannel (const std::string &channel_name, RoleAttrVec *readers)
 Get the Readers Of Channel object
 
void GetUpstreamOfNode (const std::string &node_name, RoleAttrVec *upstream_nodes)
 Get the Upstream Of Node object.
 
void GetDownstreamOfNode (const std::string &node_name, RoleAttrVec *downstream_nodes)
 Get the Downstream Of Node object.
 
FlowDirection GetFlowDirection (const std::string &lhs_node_name, const std::string &rhs_node_name)
 Get the Flow Direction from lhs_node_node to rhs_node_name You can see FlowDirection's description for more information
 
bool IsMessageTypeMatching (const std::string &lhs, const std::string &rhs)
 Is lhs and rhs have same MessageType
 
- Public 成员函数 继承自 apollo::cyber::service_discovery::Manager
 Manager ()
 Construct a new Manager object
 
virtual ~Manager ()
 Destroy the Manager object
 
bool StartDiscovery (const ParticipantPtr &participant)
 Startup topology discovery
 
void StopDiscovery ()
 Stop topology discovery
 
virtual void Shutdown ()
 Shutdown module
 
bool Join (const RoleAttributes &attr, RoleType role, bool need_publish=true)
 Join the topology
 
bool Leave (const RoleAttributes &attr, RoleType role)
 Leave the topology
 
ChangeConnection AddChangeListener (const ChangeFunc &func)
 Add topology change listener, when topology changed, func will be called.
 
void RemoveChangeListener (const ChangeConnection &conn)
 Remove our listener for topology change.
 

友元

class TopologyManager
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::cyber::service_discovery::Manager
bool CreatePublisher (const ParticipantPtr &participant)
 
bool CreateSubscriber (const ParticipantPtr &participant)
 
virtual bool NeedPublish (const ChangeMsg &msg) const
 
void Convert (const RoleAttributes &attr, RoleType role, OperateType opt, ChangeMsg *msg)
 
void Notify (const ChangeMsg &msg)
 
bool Publish (const ChangeMsg &msg)
 
void OnRemoteChange (const std::shared_ptr< std::string > &msg_str)
 
bool IsFromSameProcess (const ChangeMsg &msg)
 
- Protected 属性 继承自 apollo::cyber::service_discovery::Manager
std::atomic< bool > is_shutdown_
 
std::atomic< bool > is_discovery_started_
 
int allowed_role_
 
ChangeType change_type_
 
std::string host_name_
 
int process_id_
 
std::string channel_name_
 
PublisherPtr publisher_
 
SubscriberPtr subscriber_
 
ParticipantPtr participant_
 
std::mutex lock_
 
ChangeSignal signal_
 

详细描述

Topology Manager of Service related

在文件 channel_manager.h43 行定义.

成员类型定义说明

◆ ExemptedMessageTypes

在文件 channel_manager.h50 行定义.

◆ ReaderWarehouse

◆ RoleAttrVec

◆ WriterWarehouse

构造及析构函数说明

◆ ChannelManager()

apollo::cyber::service_discovery::ChannelManager::ChannelManager ( )

Construct a new Channel Manager object

在文件 channel_manager.cc32 行定义.

32 {
33 allowed_role_ |= 1 << RoleType::ROLE_WRITER;
34 allowed_role_ |= 1 << RoleType::ROLE_READER;
35 change_type_ = ChangeType::CHANGE_CHANNEL;
36 channel_name_ = "channel_change_broadcast";
37 exempted_msg_types_.emplace(message::MessageType<message::RawMessage>());
38 exempted_msg_types_.emplace(message::MessageType<message::PyMessageWrap>());
39}

◆ ~ChannelManager()

apollo::cyber::service_discovery::ChannelManager::~ChannelManager ( )
virtual

Destroy the Channel Manager object

在文件 channel_manager.cc41 行定义.

41{}

成员函数说明

◆ GetChannelNames()

void apollo::cyber::service_discovery::ChannelManager::GetChannelNames ( std::vector< std::string > *  channels)

Get all channel names in the topology

参数
channelsresult vector

在文件 channel_manager.cc43 行定义.

43 {
44 RETURN_IF_NULL(channels);
45
46 std::unordered_set<std::string> local_channels;
47 std::vector<RolePtr> roles;
48 channel_writers_.GetAllRoles(&roles);
49 channel_readers_.GetAllRoles(&roles);
50 for (auto& role : roles) {
51 local_channels.emplace(role->attributes().channel_name());
52 }
53 std::move(local_channels.begin(), local_channels.end(),
54 std::back_inserter(*channels));
55}
void GetAllRoles(std::vector< RolePtr > *roles) override
#define RETURN_IF_NULL(ptr)
Definition log.h:90

◆ GetDownstreamOfNode()

void apollo::cyber::service_discovery::ChannelManager::GetDownstreamOfNode ( const std::string &  node_name,
RoleAttrVec downstream_nodes 
)

Get the Downstream Of Node object.

If Node A has writer that publishes channel-1, and Node B has reader that subscribes channel-1 then A is B's Upstream node, and B is A's Downstream node

参数
node_namenode's name we want to inquire
downstream_nodesresult RoleAttribute vector

在文件 channel_manager.cc168 行定义.

169 {
170 RETURN_IF_NULL(downstream_nodes);
171
172 RoleAttrVec writers;
173 GetWritersOfNode(node_name, &writers);
174 if (writers.empty()) {
175 return;
176 }
177 std::unordered_set<std::string> channels;
178 for (auto& writer : writers) {
179 channels.emplace(writer.channel_name());
180 }
181
182 RoleAttrVec readers;
183 for (auto& channel : channels) {
184 GetReadersOfChannel(channel, &readers);
185 }
186
187 std::unordered_map<std::string, proto::RoleAttributes> nodes;
188 for (auto& reader : readers) {
189 proto::RoleAttributes attr;
190 attr.set_host_name(reader.host_name());
191 attr.set_process_id(reader.process_id());
192 attr.set_node_name(reader.node_name());
193 attr.set_node_id(reader.node_id());
194 nodes[attr.node_name()] = attr;
195 }
196 for (auto& item : nodes) {
197 downstream_nodes->emplace_back(item.second);
198 }
199}
std::vector< proto::RoleAttributes > RoleAttrVec
void GetWritersOfNode(const std::string &node_name, RoleAttrVec *writers)
Get the Writers Of Node object
void GetReadersOfChannel(const std::string &channel_name, RoleAttrVec *readers)
Get the Readers Of Channel object

◆ GetFlowDirection()

FlowDirection apollo::cyber::service_discovery::ChannelManager::GetFlowDirection ( const std::string &  lhs_node_name,
const std::string &  rhs_node_name 
)

Get the Flow Direction from lhs_node_node to rhs_node_name You can see FlowDirection's description for more information

返回
FlowDirection result direction

在文件 channel_manager.cc201 行定义.

202 {
203 Vertice lhs(lhs_node_name);
204 Vertice rhs(rhs_node_name);
205 return node_graph_.GetDirectionOf(lhs, rhs);
206}
FlowDirection GetDirectionOf(const Vertice &lhs, const Vertice &rhs)
Definition graph.cc:145

◆ GetMsgType()

void apollo::cyber::service_discovery::ChannelManager::GetMsgType ( const std::string &  channel_name,
std::string *  msg_type 
)

Get the Msg Type of channel_name

参数
channel_namechannel name we want to inquire
msg_typeresult string, empty if inquire failed

在文件 channel_manager.cc71 行定义.

72 {
73 RETURN_IF_NULL(msg_type);
74 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
75 RolePtr writer = nullptr;
76 if (!channel_writers_.Search(key, &writer)) {
77 AERROR << "cannot find writer of channel: " << channel_name
78 << " key: " << key;
79 return;
80 }
81
82 if (writer->attributes().has_message_type()) {
83 *msg_type = writer->attributes().message_type();
84 }
85}
static uint64_t RegisterChannel(const std::string &channel)
#define AERROR
Definition log.h:44
std::shared_ptr< RoleBase > RolePtr
Definition role.h:31

◆ GetProtoDesc()

void apollo::cyber::service_discovery::ChannelManager::GetProtoDesc ( const std::string &  channel_name,
std::string *  proto_desc 
)

Get the Protocol Desc of channel_name

参数
channel_namechannel name we want to inquire
proto_descresult string, empty if inquire failed

在文件 channel_manager.cc57 行定义.

58 {
59 RETURN_IF_NULL(proto_desc);
60 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
61 RolePtr writer = nullptr;
62 if (!channel_writers_.Search(key, &writer)) {
63 return;
64 }
65
66 if (writer->attributes().has_proto_desc()) {
67 *proto_desc = writer->attributes().proto_desc();
68 }
69}

◆ GetReaders()

void apollo::cyber::service_discovery::ChannelManager::GetReaders ( RoleAttrVec readers)

Get All Readers object

参数
readersresult RoleAttr vector

在文件 channel_manager.cc116 行定义.

116 {
117 RETURN_IF_NULL(readers);
118 channel_readers_.GetAllRoles(readers);
119}

◆ GetReadersOfChannel()

void apollo::cyber::service_discovery::ChannelManager::GetReadersOfChannel ( const std::string &  channel_name,
RoleAttrVec readers 
)

Get the Readers Of Channel object

参数
channel_namechannel's name we want to inquire
readersresult RoleAttribute vector

在文件 channel_manager.cc128 行定义.

129 {
130 RETURN_IF_NULL(readers);
131 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
132 channel_readers_.Search(key, readers);
133}

◆ GetReadersOfNode()

void apollo::cyber::service_discovery::ChannelManager::GetReadersOfNode ( const std::string &  node_name,
RoleAttrVec readers 
)

Get the Readers Of Node object

参数
node_namenode's name we want to inquire
readersresult RoleAttribute vector

在文件 channel_manager.cc121 行定义.

122 {
123 RETURN_IF_NULL(readers);
124 uint64_t key = common::GlobalData::RegisterNode(node_name);
125 node_readers_.Search(key, readers);
126}
static uint64_t RegisterNode(const std::string &node_name)

◆ GetUpstreamOfNode()

void apollo::cyber::service_discovery::ChannelManager::GetUpstreamOfNode ( const std::string &  node_name,
RoleAttrVec upstream_nodes 
)

Get the Upstream Of Node object.

If Node A has writer that publishes channel-1, and Node B has reader that subscribes channel-1 then A is B's Upstream node, and B is A's Downstream node

参数
node_namenode's name we want to inquire
upstream_nodesresult RoleAttribute vector

在文件 channel_manager.cc135 行定义.

136 {
137 RETURN_IF_NULL(upstream_nodes);
138
139 RoleAttrVec readers;
140 GetReadersOfNode(node_name, &readers);
141 if (readers.empty()) {
142 return;
143 }
144 std::unordered_set<std::string> channels;
145 for (auto& reader : readers) {
146 channels.emplace(reader.channel_name());
147 }
148
149 RoleAttrVec writers;
150 for (auto& channel : channels) {
151 GetWritersOfChannel(channel, &writers);
152 }
153
154 std::unordered_map<std::string, proto::RoleAttributes> nodes;
155 for (auto& writer : writers) {
156 proto::RoleAttributes attr;
157 attr.set_host_name(writer.host_name());
158 attr.set_process_id(writer.process_id());
159 attr.set_node_name(writer.node_name());
160 attr.set_node_id(writer.node_id());
161 nodes[attr.node_name()] = attr;
162 }
163 for (auto& item : nodes) {
164 upstream_nodes->emplace_back(item.second);
165 }
166}
void GetReadersOfNode(const std::string &node_name, RoleAttrVec *readers)
Get the Readers Of Node object
void GetWritersOfChannel(const std::string &channel_name, RoleAttrVec *writers)
Get the Writers Of Channel object

◆ GetWriters()

void apollo::cyber::service_discovery::ChannelManager::GetWriters ( RoleAttrVec writers)

Get All Writers object

参数
writersresult RoleAttr vector

在文件 channel_manager.cc92 行定义.

92 {
93 RETURN_IF_NULL(writers);
94 channel_writers_.GetAllRoles(writers);
95}

◆ GetWritersOfChannel()

void apollo::cyber::service_discovery::ChannelManager::GetWritersOfChannel ( const std::string &  channel_name,
RoleAttrVec writers 
)

Get the Writers Of Channel object

参数
channel_namechannel's name we want to inquire
writersresult RoleAttribute vector

在文件 channel_manager.cc104 行定义.

105 {
106 RETURN_IF_NULL(writers);
107 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
108 channel_writers_.Search(key, writers);
109}

◆ GetWritersOfNode()

void apollo::cyber::service_discovery::ChannelManager::GetWritersOfNode ( const std::string &  node_name,
RoleAttrVec writers 
)

Get the Writers Of Node object

参数
node_namenode's name we want to inquire
writersresult RoleAttribute vector

在文件 channel_manager.cc97 行定义.

98 {
99 RETURN_IF_NULL(writers);
100 uint64_t key = common::GlobalData::RegisterNode(node_name);
101 node_writers_.Search(key, writers);
102}

◆ HasReader()

bool apollo::cyber::service_discovery::ChannelManager::HasReader ( const std::string &  channel_name)

Inquire if there is at least one Reader that publishes channel_name

参数
channel_namechannel name we want to inquire
返回
true if there is at least one Reader
false if there are no Reader

在文件 channel_manager.cc111 行定义.

111 {
112 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
113 return channel_readers_.Search(key);
114}

◆ HasWriter()

bool apollo::cyber::service_discovery::ChannelManager::HasWriter ( const std::string &  channel_name)

Inquire if there is at least one Writer that publishes channel_name

参数
channel_namechannel name we want to inquire
返回
true if there is at least one Writer
false if there are no Writers

在文件 channel_manager.cc87 行定义.

87 {
88 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
89 return channel_writers_.Search(key);
90}

◆ IsMessageTypeMatching()

bool apollo::cyber::service_discovery::ChannelManager::IsMessageTypeMatching ( const std::string &  lhs,
const std::string &  rhs 
)

Is lhs and rhs have same MessageType

参数
lhsthe left message type to compare
rhsthe right message type to compare
返回
true if type matches
false if type does not matches

在文件 channel_manager.cc208 行定义.

209 {
210 if (lhs == rhs) {
211 return true;
212 }
213 if (exempted_msg_types_.count(lhs) > 0) {
214 return true;
215 }
216 if (exempted_msg_types_.count(rhs) > 0) {
217 return true;
218 }
219 return false;
220}

友元及相关函数文档

◆ TopologyManager

friend class TopologyManager
friend

在文件 channel_manager.h44 行定义.


该类的文档由以下文件生成: