Apollo 10.0
自动驾驶开放平台
participant.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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_TRANSPORT_RTPS_PARTICIPANT_H_
18#define CYBER_TRANSPORT_RTPS_PARTICIPANT_H_
19
20#include <arpa/inet.h>
21#include <ifaddrs.h>
22
23#include <atomic>
24#include <memory>
25#include <mutex>
26#include <string>
27#include <unordered_map>
28
29#include "fastdds/dds/domain/DomainParticipantFactory.hpp"
30#include "fastdds/dds/domain/DomainParticipantListener.hpp"
31#include "fastdds/rtps/transport/TCPv4TransportDescriptor.h"
32#include "fastdds/rtps/transport/UDPv4TransportDescriptor.h"
33#include "fastrtps/utils/IPLocator.h"
34
35#include "cyber/base/macros.h"
36
37#include "cyber/proto/qos_profile.pb.h"
38#include "cyber/proto/transport_conf.pb.h"
39
41#include "cyber/common/log.h"
45
46namespace apollo {
47namespace cyber {
48namespace transport {
49
51 public:
53 const std::string& name, int send_port,
54 eprosima::fastdds::dds::DomainParticipantListener* listener = nullptr);
55 virtual ~Participant();
56
57 void Shutdown();
58 bool Init();
59 auto CreatePublisher(const std::string& channel_name,
60 const proto::QosProfile& qos)
61 -> std::shared_ptr<transport::Publisher>;
62
63 auto CreateSubscriber(const std::string& channel_name,
64 const proto::QosProfile& qos,
65 const rtps::subsciber_callback& callback = nullptr)
66 -> std::shared_ptr<Subscriber>;
67
68 bool is_shutdown() const { return shutdown_.load(); }
69
70 private:
71 Participant(const Participant&) = delete;
72 Participant& operator=(const Participant&) = delete;
73 bool CreateParticipant(
74 const std::string& name, int send_port,
75 eprosima::fastdds::dds::DomainParticipantListener* listener);
76
77 bool CheckIPVaild(std::string ip_env);
78 std::atomic<bool> shutdown_;
79 std::string name_;
80 int send_port_;
81
82 using PublisherPtrMap =
83 std::unordered_multimap<std::string, std::shared_ptr<Publisher>>;
84 using SubscriberPtrMap =
85 std::unordered_multimap<std::string, std::shared_ptr<Subscriber>>;
86
87 std::mutex publisher_mutex_;
88 PublisherPtrMap publisher_map_;
89 std::mutex subscriber_mutex_;
90 SubscriberPtrMap subscriber_map_;
91
92 eprosima::fastdds::dds::DomainParticipantListener* listener_;
93 eprosima::fastdds::dds::TypeSupport type_support_;
94 eprosima::fastdds::dds::DomainParticipant* participant_;
95 std::mutex mutex_;
96};
97
98} // namespace transport
99} // namespace cyber
100} // namespace apollo
101
102#endif // CYBER_TRANSPORT_RTPS_PARTICIPANT_H_
auto CreateSubscriber(const std::string &channel_name, const proto::QosProfile &qos, const rtps::subsciber_callback &callback=nullptr) -> std::shared_ptr< Subscriber >
auto CreatePublisher(const std::string &channel_name, const proto::QosProfile &qos) -> std::shared_ptr< transport::Publisher >
std::function< void(const std::shared_ptr< std::string > &msg_str, uint64_t channel_id, const MessageInfo &msg_info)> subsciber_callback
Definition common_type.h:30
class register implement
Definition arena_queue.h:37