Apollo  6.0
Open source self driving car software
topology_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_TOPOLOGY_MANAGER_H_
18 #define CYBER_SERVICE_DISCOVERY_TOPOLOGY_MANAGER_H_
19 
20 #include <atomic>
21 #include <functional>
22 #include <map>
23 #include <memory>
24 #include <mutex>
25 #include <string>
26 
27 #include "cyber/base/signal.h"
28 #include "cyber/common/macros.h"
34 
35 namespace apollo {
36 namespace cyber {
37 namespace service_discovery {
38 
39 class NodeManager;
40 using NodeManagerPtr = std::shared_ptr<NodeManager>;
41 
42 class ChannelManager;
43 using ChannelManagerPtr = std::shared_ptr<ChannelManager>;
44 
45 class ServiceManager;
46 using ServiceManagerPtr = std::shared_ptr<ServiceManager>;
47 
65  public:
67  using ChangeFunc = std::function<void(const ChangeMsg&)>;
69  using PartNameContainer =
70  std::map<eprosima::fastrtps::rtps::GUID_t, std::string>;
71  using PartInfo = eprosima::fastrtps::ParticipantDiscoveryInfo;
72 
73  virtual ~TopologyManager();
74 
78  void Shutdown();
79 
88 
92  void RemoveChangeListener(const ChangeConnection& conn);
93 
97  NodeManagerPtr& node_manager() { return node_manager_; }
98 
102  ChannelManagerPtr& channel_manager() { return channel_manager_; }
103 
107  ServiceManagerPtr& service_manager() { return service_manager_; }
108 
109  private:
110  bool Init();
111 
112  bool InitNodeManager();
113  bool InitChannelManager();
114  bool InitServiceManager();
115 
116  bool CreateParticipant();
117  void OnParticipantChange(const PartInfo& info);
118  bool Convert(const PartInfo& info, ChangeMsg* change_msg);
119  bool ParseParticipantName(const std::string& participant_name,
120  std::string* host_name, int* process_id);
121 
122  std::atomic<bool> init_;
123  NodeManagerPtr node_manager_;
124  ChannelManagerPtr channel_manager_;
125  ServiceManagerPtr service_manager_;
126  transport::ParticipantPtr participant_;
128  ParticipantListener* participant_listener_;
129  ChangeSignal change_signal_;
130  PartNameContainer participant_names_;
132 
134 };
135 
136 } // namespace service_discovery
137 } // namespace cyber
138 } // namespace apollo
139 
140 #endif // CYBER_SERVICE_DISCOVERY_TOPOLOGY_MANAGER_H_
void(* func)(void *)
Definition: routine_context.h:41
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::shared_ptr< ChannelManager > ChannelManagerPtr
Definition: topology_manager.h:43
elements in Cyber – Node, Channel, Service, Writer, Reader, Client and Server&#39;s relationship is pres...
Definition: topology_manager.h:64
void RemoveChangeListener(const ChangeConnection &conn)
Remove the observe function connect to change_signal_ by conn
ServiceManagerPtr & service_manager()
Get shared_ptr for ServiceManager.
Definition: topology_manager.h:107
void Shutdown()
Shutdown the TopologyManager.
Definition: participant_listener.h:31
std::shared_ptr< ServiceManager > ServiceManagerPtr
Definition: topology_manager.h:46
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
ChannelManagerPtr & channel_manager()
Get shared_ptr for ChannelManager.
Definition: topology_manager.h:102
std::function< void(const ChangeMsg &)> ChangeFunc
Definition: topology_manager.h:67
ChangeConnection AddChangeListener(const ChangeFunc &func)
To observe the topology change, you can register a ChangeFunc
eprosima::fastrtps::ParticipantDiscoveryInfo PartInfo
Definition: topology_manager.h:71
Topology Manager of Service related.
Definition: service_manager.h:39
Definition: signal.h:37
std::shared_ptr< Participant > ParticipantPtr
Definition: participant.h:37
NodeManagerPtr & node_manager()
Get shared_ptr for NodeManager.
Definition: topology_manager.h:97
std::map< eprosima::fastrtps::rtps::GUID_t, std::string > PartNameContainer
Definition: topology_manager.h:70
std::shared_ptr< NodeManager > NodeManagerPtr
Definition: topology_manager.h:40
Topology Manager of Service related.
Definition: channel_manager.h:42