Apollo 10.0
自动驾驶开放平台
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_SPECIFIC_MANAGER_MANAGER_H_
18#define CYBER_SERVICE_DISCOVERY_SPECIFIC_MANAGER_MANAGER_H_
19
20#include <atomic>
21#include <functional>
22#include <memory>
23#include <mutex>
24#include <string>
25
26#include "cyber/base/macros.h"
27
28#include "fastdds/dds/publisher/qos/PublisherQos.hpp"
29#include "fastdds/dds/subscriber/qos/SubscriberQos.hpp"
30
31#include "cyber/proto/topology_change.pb.h"
32
33#include "cyber/base/signal.h"
38
39namespace apollo {
40namespace cyber {
41namespace service_discovery {
42
43using proto::ChangeMsg;
46using proto::RoleAttributes;
47using proto::RoleType;
48
54class Manager {
55 public:
57 using ChangeFunc = std::function<void(const ChangeMsg&)>;
59 using ParticipantPtr = std::shared_ptr<transport::Participant>;
60 using PublisherPtr = std::shared_ptr<transport::Publisher>;
61 using SubscriberPtr = std::shared_ptr<transport::Subscriber>;
65 Manager();
66
70 virtual ~Manager();
71
79 bool StartDiscovery(const ParticipantPtr& participant);
80
84 void StopDiscovery();
85
89 virtual void Shutdown();
90
100 bool Join(const RoleAttributes& attr, RoleType role,
101 bool need_publish = true);
102
112 bool Leave(const RoleAttributes& attr, RoleType role);
113
122
128 void RemoveChangeListener(const ChangeConnection& conn);
129
136 virtual void OnTopoModuleLeave(const std::string& host_name,
137 int process_id) = 0;
138
139 protected:
140 bool CreatePublisher(const ParticipantPtr& participant);
141 bool CreateSubscriber(const ParticipantPtr& participant);
142
143 virtual bool Check(const RoleAttributes& attr) = 0;
144 virtual void Dispose(const ChangeMsg& msg) = 0;
145 virtual bool NeedPublish(const ChangeMsg& msg) const;
146
147 void Convert(const RoleAttributes& attr, RoleType role, OperateType opt,
148 ChangeMsg* msg);
149
150 void Notify(const ChangeMsg& msg);
151 bool Publish(const ChangeMsg& msg);
152 void OnRemoteChange(const std::shared_ptr<std::string>& msg_str);
153 bool IsFromSameProcess(const ChangeMsg& msg);
154
155 std::atomic<bool> is_shutdown_;
156 std::atomic<bool> is_discovery_started_;
158 ChangeType change_type_;
159 std::string host_name_;
161 std::string channel_name_;
165 std::mutex lock_;
166
168};
169
170} // namespace service_discovery
171} // namespace cyber
172} // namespace apollo
173
174#endif // CYBER_SERVICE_DISCOVERY_SPECIFIC_MANAGER_MANAGER_H_
Base class for management of Topology elements.
Definition manager.h:54
void Notify(const ChangeMsg &msg)
Definition manager.cc:153
void Convert(const RoleAttributes &attr, RoleType role, OperateType opt, ChangeMsg *msg)
Definition manager.cc:137
std::function< void(const ChangeMsg &)> ChangeFunc
Definition manager.h:57
std::shared_ptr< transport::Participant > ParticipantPtr
Definition manager.h:59
bool Join(const RoleAttributes &attr, RoleType role, bool need_publish=true)
Join the topology
Definition manager.cc:77
bool IsFromSameProcess(const ChangeMsg &msg)
Definition manager.cc:187
bool Publish(const ChangeMsg &msg)
Definition manager.cc:170
void RemoveChangeListener(const ChangeConnection &conn)
Remove our listener for topology change.
Definition manager.cc:114
bool StartDiscovery(const ParticipantPtr &participant)
Startup topology discovery
Definition manager.cc:46
std::shared_ptr< transport::Publisher > PublisherPtr
Definition manager.h:60
bool CreateSubscriber(const ParticipantPtr &participant)
Definition manager.cc:125
virtual ~Manager()
Destroy the Manager object
Definition manager.cc:44
virtual void Dispose(const ChangeMsg &msg)=0
void OnRemoteChange(const std::shared_ptr< std::string > &msg_str)
Definition manager.cc:155
std::atomic< bool > is_discovery_started_
Definition manager.h:156
Manager()
Construct a new Manager object
Definition manager.cc:32
virtual void OnTopoModuleLeave(const std::string &host_name, int process_id)=0
Called when a process' topology manager instance leave
ChangeConnection AddChangeListener(const ChangeFunc &func)
Add topology change listener, when topology changed, func will be called.
Definition manager.cc:110
std::shared_ptr< transport::Subscriber > SubscriberPtr
Definition manager.h:61
bool Leave(const RoleAttributes &attr, RoleType role)
Leave the topology
Definition manager.cc:94
virtual bool Check(const RoleAttributes &attr)=0
void StopDiscovery()
Stop topology discovery
Definition manager.cc:62
virtual bool NeedPublish(const ChangeMsg &msg) const
Definition manager.cc:132
virtual void Shutdown()
Shutdown module
Definition manager.cc:68
bool CreatePublisher(const ParticipantPtr &participant)
Definition manager.cc:119
class register implement
Definition arena_queue.h:37