DDS_Bridge
一个基于Fast DDS的DDS桥接库
载入中...
搜索中...
未找到
node.hpp
浏览该文件的文档.
1
10#pragma once
11#include <memory>
12#include <string>
13#include <fastdds/dds/domain/DomainParticipant.hpp>
14#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
15
17namespace zclcpp
18{
19 template <typename MsgPubSubType>
20 class Subscription;
21
22 template <typename MsgPubSubType>
23 class Publisher;
24
30 class Node : public std::enable_shared_from_this<Node>
31 {
32 public:
33 explicit Node(const std::string& name, eprosima::fastdds::dds::DomainId_t domain_id = 0)
34 {
35 eprosima::fastdds::dds::DomainParticipantQos pqos;
36 pqos.name(name);
37 participant_ =
38 eprosima::fastdds::dds::DomainParticipantFactory::get_instance()
39 ->create_participant(domain_id, pqos);
40 }
41
42 ~Node()
43 {
44 if (participant_)
45 eprosima::fastdds::dds::DomainParticipantFactory::get_instance()
46 ->delete_participant(participant_);
47 }
48
49
55 eprosima::fastdds::dds::DomainParticipant* participant() const
56 {
57 return participant_;
58 }
59
68 template <typename PubSubT>
69 auto create_publisher(const std::string& topic_name, int qos_depth = 10)
70 {
71 return std::make_shared<Publisher<PubSubT>>(
72 shared_from_this(), topic_name, qos_depth);
73 }
74
84 template <typename PubSubT>
85 auto create_subscription(const std::string& topic_name,
86 int qos_depth,
88 {
89 return std::make_shared<Subscription<PubSubT>>(
90 shared_from_this(), topic_name, qos_depth, std::move(cb));
91 }
92
93
94 private:
95 eprosima::fastdds::dds::DomainParticipant* participant_{ nullptr };
96 };
97}
98
auto create_subscription(const std::string &topic_name, int qos_depth, typename Subscription< PubSubT >::Callback cb)
Create a subscription object
定义 node.hpp:85
auto create_publisher(const std::string &topic_name, int qos_depth=10)
Create a publisher object
定义 node.hpp:69
eprosima::fastdds::dds::DomainParticipant * participant() const
Get the DDS DomainParticipant.
定义 node.hpp:55
Represents a DDS publisher.
定义 publisher.hpp:28
Represents a DDS subscription.
定义 subscriber.hpp:28
std::function< void(const typename MsgPubSubType::type &)> Callback
Callback type for message reception.
定义 subscriber.hpp:37
Namespace for zzs communication library.
定义 node.hpp:18