Apollo 10.0
自动驾驶开放平台
topology_manager.h
浏览该文件的文档.
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
35namespace apollo {
36namespace cyber {
37namespace service_discovery {
38
39class NodeManager;
40using NodeManagerPtr = std::shared_ptr<NodeManager>;
41
42class ChannelManager;
43using ChannelManagerPtr = std::shared_ptr<ChannelManager>;
44
45class ServiceManager;
46using ServiceManagerPtr = std::shared_ptr<ServiceManager>;
47
65 public:
67 using ChangeFunc = std::function<void(const ChangeMsg&)>;
69 using ParticipantPtr = std::shared_ptr<transport::Participant>;
71 std::map<eprosima::fastrtps::rtps::GUID_t, std::string>;
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(
118 const eprosima::fastrtps::rtps::ParticipantDiscoveryInfo& info);
119 bool Convert(const eprosima::fastrtps::rtps::ParticipantDiscoveryInfo& info,
120 ChangeMsg* change_msg);
121 bool ParseParticipantName(const std::string& participant_name,
122 std::string* host_name, int* process_id);
123
124 std::atomic<bool> init_;
125 NodeManagerPtr node_manager_;
126 ChannelManagerPtr channel_manager_;
127 ServiceManagerPtr service_manager_;
128 ParticipantPtr participant_;
129 ChangeSignal change_signal_;
131 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_
Topology Manager of Service related
Topology Manager of Service related
elements in Cyber – Node, Channel, Service, Writer, Reader, Client and Server's relationship is prese...
void RemoveChangeListener(const ChangeConnection &conn)
Remove the observe function connect to change_signal_ by conn
ChangeConnection AddChangeListener(const ChangeFunc &func)
To observe the topology change, you can register a ChangeFunc
std::shared_ptr< transport::Participant > ParticipantPtr
std::function< void(const ChangeMsg &)> ChangeFunc
void Shutdown()
Shutdown the TopologyManager
base::Signal< const ChangeMsg & > ChangeSignal
ServiceManagerPtr & service_manager()
Get shared_ptr for ServiceManager
NodeManagerPtr & node_manager()
Get shared_ptr for NodeManager
std::map< eprosima::fastrtps::rtps::GUID_t, std::string > PartNameContainer
ChannelManagerPtr & channel_manager()
Get shared_ptr for ChannelManager
#define DECLARE_SINGLETON(classname)
Definition macros.h:52
std::shared_ptr< ChannelManager > ChannelManagerPtr
std::shared_ptr< NodeManager > NodeManagerPtr
std::shared_ptr< ServiceManager > ServiceManagerPtr
class register implement
Definition arena_queue.h:37