Apollo 11.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 RtpsParticipant = eprosima::fastrtps::Participant
 
using RtpsPublisherAttr = eprosima::fastrtps::PublisherAttributes
 
using RtpsSubscriberAttr = eprosima::fastrtps::SubscriberAttributes
 

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 (RtpsParticipant *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 (RtpsParticipant *participant)
 
bool CreateSubscriber (RtpsParticipant *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::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_
 
eprosima::fastrtps::Publisher * publisher_
 
std::mutex lock_
 
eprosima::fastrtps::Subscriber * subscriber_
 
SubscriberListenerlistener_
 
ChangeSignal signal_
 

详细描述

Topology Manager of Service related

在文件 channel_manager.h42 行定义.

成员类型定义说明

◆ ExemptedMessageTypes

在文件 channel_manager.h49 行定义.

◆ ReaderWarehouse

◆ RoleAttrVec

◆ WriterWarehouse

构造及析构函数说明

◆ ChannelManager()

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

Construct a new Channel Manager object

在文件 channel_manager.cc35 行定义.

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

◆ ~ChannelManager()

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

Destroy the Channel Manager object

在文件 channel_manager.cc44 行定义.

44{}

成员函数说明

◆ GetChannelNames()

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

Get all channel names in the topology

参数
channelsresult vector

在文件 channel_manager.cc46 行定义.

46 {
47 RETURN_IF_NULL(channels);
48
49 std::unordered_set<std::string> local_channels;
50 std::vector<RolePtr> roles;
51 channel_writers_.GetAllRoles(&roles);
52 channel_readers_.GetAllRoles(&roles);
53 for (auto& role : roles) {
54 local_channels.emplace(role->attributes().channel_name());
55 }
56 std::move(local_channels.begin(), local_channels.end(),
57 std::back_inserter(*channels));
58}
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.cc171 行定义.

172 {
173 RETURN_IF_NULL(downstream_nodes);
174
175 RoleAttrVec writers;
176 GetWritersOfNode(node_name, &writers);
177 if (writers.empty()) {
178 return;
179 }
180 std::unordered_set<std::string> channels;
181 for (auto& writer : writers) {
182 channels.emplace(writer.channel_name());
183 }
184
185 RoleAttrVec readers;
186 for (auto& channel : channels) {
187 GetReadersOfChannel(channel, &readers);
188 }
189
190 std::unordered_map<std::string, proto::RoleAttributes> nodes;
191 for (auto& reader : readers) {
192 proto::RoleAttributes attr;
193 attr.set_host_name(reader.host_name());
194 attr.set_process_id(reader.process_id());
195 attr.set_node_name(reader.node_name());
196 attr.set_node_id(reader.node_id());
197 nodes[attr.node_name()] = attr;
198 }
199 for (auto& item : nodes) {
200 downstream_nodes->emplace_back(item.second);
201 }
202}
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.cc204 行定义.

205 {
206 Vertice lhs(lhs_node_name);
207 Vertice rhs(rhs_node_name);
208 return node_graph_.GetDirectionOf(lhs, rhs);
209}
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.cc74 行定义.

75 {
76 RETURN_IF_NULL(msg_type);
77 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
78 RolePtr writer = nullptr;
79 if (!channel_writers_.Search(key, &writer)) {
80 AERROR << "cannot find writer of channel: " << channel_name
81 << " key: " << key;
82 return;
83 }
84
85 if (writer->attributes().has_message_type()) {
86 *msg_type = writer->attributes().message_type();
87 }
88}
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.cc60 行定义.

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

◆ GetReaders()

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

Get All Readers object

参数
readersresult RoleAttr vector

在文件 channel_manager.cc119 行定义.

119 {
120 RETURN_IF_NULL(readers);
121 channel_readers_.GetAllRoles(readers);
122}

◆ 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.cc131 行定义.

132 {
133 RETURN_IF_NULL(readers);
134 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
135 channel_readers_.Search(key, readers);
136}

◆ 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.cc124 行定义.

125 {
126 RETURN_IF_NULL(readers);
127 uint64_t key = common::GlobalData::RegisterNode(node_name);
128 node_readers_.Search(key, readers);
129}
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.cc138 行定义.

139 {
140 RETURN_IF_NULL(upstream_nodes);
141
142 RoleAttrVec readers;
143 GetReadersOfNode(node_name, &readers);
144 if (readers.empty()) {
145 return;
146 }
147 std::unordered_set<std::string> channels;
148 for (auto& reader : readers) {
149 channels.emplace(reader.channel_name());
150 }
151
152 RoleAttrVec writers;
153 for (auto& channel : channels) {
154 GetWritersOfChannel(channel, &writers);
155 }
156
157 std::unordered_map<std::string, proto::RoleAttributes> nodes;
158 for (auto& writer : writers) {
159 proto::RoleAttributes attr;
160 attr.set_host_name(writer.host_name());
161 attr.set_process_id(writer.process_id());
162 attr.set_node_name(writer.node_name());
163 attr.set_node_id(writer.node_id());
164 nodes[attr.node_name()] = attr;
165 }
166 for (auto& item : nodes) {
167 upstream_nodes->emplace_back(item.second);
168 }
169}
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.cc95 行定义.

95 {
96 RETURN_IF_NULL(writers);
97 channel_writers_.GetAllRoles(writers);
98}

◆ 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.cc107 行定义.

108 {
109 RETURN_IF_NULL(writers);
110 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
111 channel_writers_.Search(key, writers);
112}

◆ 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.cc100 行定义.

101 {
102 RETURN_IF_NULL(writers);
103 uint64_t key = common::GlobalData::RegisterNode(node_name);
104 node_writers_.Search(key, writers);
105}

◆ 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.cc114 行定义.

114 {
115 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
116 return channel_readers_.Search(key);
117}

◆ 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.cc90 行定义.

90 {
91 uint64_t key = common::GlobalData::RegisterChannel(channel_name);
92 return channel_writers_.Search(key);
93}

◆ 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.cc211 行定义.

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

友元及相关函数文档

◆ TopologyManager

friend class TopologyManager
friend

在文件 channel_manager.h43 行定义.


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