Apollo  6.0
Open source self driving car software
channel_manager.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 
17 #ifndef CYBER_SERVICE_DISCOVERY_SPECIFIC_MANAGER_CHANNEL_MANAGER_H_
18 #define CYBER_SERVICE_DISCOVERY_SPECIFIC_MANAGER_CHANNEL_MANAGER_H_
19 
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 #include <unordered_set>
24 #include <vector>
25 
31 
32 namespace apollo {
33 namespace cyber {
34 namespace service_discovery {
35 
36 class TopologyManager;
37 
42 class ChannelManager : public Manager {
43  friend class TopologyManager;
44 
45  public:
46  using RoleAttrVec = std::vector<proto::RoleAttributes>;
49  using ExemptedMessageTypes = std::unordered_set<std::string>;
50 
55 
59  virtual ~ChannelManager();
60 
66  void GetChannelNames(std::vector<std::string>* channels);
67 
74  void GetProtoDesc(const std::string& channel_name, std::string* proto_desc);
75 
82  void GetMsgType(const std::string& channel_name, std::string* msg_type);
83 
92  bool HasWriter(const std::string& channel_name);
93 
99  void GetWriters(RoleAttrVec* writers);
100 
107  void GetWritersOfNode(const std::string& node_name, RoleAttrVec* writers);
108 
115  void GetWritersOfChannel(const std::string& channel_name,
116  RoleAttrVec* writers);
117 
126  bool HasReader(const std::string& channel_name);
127 
133  void GetReaders(RoleAttrVec* readers);
134 
141  void GetReadersOfNode(const std::string& node_name, RoleAttrVec* readers);
142 
149  void GetReadersOfChannel(const std::string& channel_name,
150  RoleAttrVec* readers);
151 
161  void GetUpstreamOfNode(const std::string& node_name,
162  RoleAttrVec* upstream_nodes);
163 
173  void GetDownstreamOfNode(const std::string& node_name,
174  RoleAttrVec* downstream_nodes);
175 
181  FlowDirection GetFlowDirection(const std::string& lhs_node_name,
182  const std::string& rhs_node_name);
183 
192  bool IsMessageTypeMatching(const std::string& lhs, const std::string& rhs);
193 
194  private:
195  bool Check(const RoleAttributes& attr) override;
196  void Dispose(const ChangeMsg& msg) override;
197  void OnTopoModuleLeave(const std::string& host_name, int process_id) override;
198 
199  void DisposeJoin(const ChangeMsg& msg);
200  void DisposeLeave(const ChangeMsg& msg);
201 
202  void ScanMessageType(const ChangeMsg& msg);
203 
204  ExemptedMessageTypes exempted_msg_types_;
205 
206  Graph node_graph_;
207  // key: node_id
208  WriterWarehouse node_writers_;
209  ReaderWarehouse node_readers_;
210 
211  // key: channel_id
212  WriterWarehouse channel_writers_;
213  ReaderWarehouse channel_readers_;
214 };
215 
216 } // namespace service_discovery
217 } // namespace cyber
218 } // namespace apollo
219 
220 #endif // CYBER_SERVICE_DISCOVERY_SPECIFIC_MANAGER_CHANNEL_MANAGER_H_
std::unordered_set< std::string > ExemptedMessageTypes
Definition: channel_manager.h:49
void GetWritersOfChannel(const std::string &channel_name, RoleAttrVec *writers)
Get the Writers Of Channel object.
ChannelManager()
Construct a new Channel Manager object.
bool IsMessageTypeMatching(const std::string &lhs, const std::string &rhs)
Is lhs and rhs have same MessageType.
bool HasWriter(const std::string &channel_name)
Inquire if there is at least one Writer that publishes channel_name
void 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 read...
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
elements in Cyber – Node, Channel, Service, Writer, Reader, Client and Server&#39;s relationship is pres...
Definition: topology_manager.h:64
Base class for management of Topology elements. Manager can Join/Leave the Topology, and Listen the topology change.
Definition: manager.h:51
FlowDirection
describe the flow direction between nodes As the DAG below A-—>B--—>C<--—D GetDirectionOf(A, B) is UPSTREAM GetDirectionOf(C, A) is DOWNSTREAM GetDirectionOf(D, A) is UNREACHABLE GetDirectionOf(A, D) is UNREACHABLE
Definition: graph.h:39
void 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...
virtual ~ChannelManager()
Destroy the Channel Manager object.
void GetWriters(RoleAttrVec *writers)
Get All Writers object.
void GetProtoDesc(const std::string &channel_name, std::string *proto_desc)
Get the Protocol Desc of channel_name
void GetReadersOfNode(const std::string &node_name, RoleAttrVec *readers)
Get the Readers Of Node object.
std::vector< proto::RoleAttributes > RoleAttrVec
Definition: channel_manager.h:46
void GetReaders(RoleAttrVec *readers)
Get All Readers object.
bool HasReader(const std::string &channel_name)
Inquire if there is at least one Reader that publishes channel_name
void GetWritersOfNode(const std::string &node_name, RoleAttrVec *writers)
Get the Writers Of Node object.
void GetMsgType(const std::string &channel_name, std::string *msg_type)
Get the Msg Type of channel_name
void GetChannelNames(std::vector< std::string > *channels)
Get all channel names in the topology.
Definition: multi_value_warehouse.h:31
void GetReadersOfChannel(const std::string &channel_name, RoleAttrVec *readers)
Get the Readers Of Channel object.
Topology Manager of Service related.
Definition: channel_manager.h:42
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&#39;s description fo...