rmw_fastrtps_shared_cpp  master
Code shared on static and dynamic type support of rmw_fastrtps_cpp.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
custom_participant_info.hpp
Go to the documentation of this file.
1 // Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RMW_FASTRTPS_SHARED_CPP__CUSTOM_PARTICIPANT_INFO_HPP_
16 #define RMW_FASTRTPS_SHARED_CPP__CUSTOM_PARTICIPANT_INFO_HPP_
17 
18 #include <map>
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "fastdds/dds/domain/DomainParticipant.hpp"
24 #include "fastdds/dds/domain/DomainParticipantListener.hpp"
25 #include "fastdds/dds/publisher/Publisher.hpp"
26 #include "fastdds/dds/subscriber/Subscriber.hpp"
27 
28 #include "fastdds/rtps/participant/ParticipantDiscoveryInfo.h"
29 #include "fastdds/rtps/reader/ReaderDiscoveryInfo.h"
30 #include "fastdds/rtps/writer/WriterDiscoveryInfo.h"
31 
33 #include "rcutils/logging_macros.h"
34 
36 #include "rmw/qos_profiles.h"
37 #include "rmw/rmw.h"
38 
39 #include "rmw_dds_common/context.hpp"
40 
44 
45 using rmw_dds_common::operator<<;
46 
48 
50 {
51  ASYNCHRONOUS, // Asynchronous publishing mode
52  SYNCHRONOUS, // Synchronous publishing mode
53  AUTO // Use publishing mode set in XML file or Fast DDS default
54 };
55 
56 typedef struct CustomParticipantInfo
57 {
58  eprosima::fastdds::dds::DomainParticipant * participant_{nullptr};
60 
61  eprosima::fastdds::dds::Publisher * publisher_{nullptr};
62  eprosima::fastdds::dds::Subscriber * subscriber_{nullptr};
63 
64  // Protects creation and destruction of topics, readers and writers
66 
67  // Flag to establish if the QoS of the DomainParticipant,
68  // its DataWriters, and its DataReaders are going
69  // to be configured only from an XML file or if
70  // their settings are going to be overwritten by code
71  // with the default configuration.
75 
76 class ParticipantListener : public eprosima::fastdds::dds::DomainParticipantListener
77 {
78 public:
80  const char * identifier,
81  rmw_dds_common::Context * context)
82  : context(context),
83  identifier_(identifier)
84  {}
85 
87  eprosima::fastdds::dds::DomainParticipant *,
88  eprosima::fastrtps::rtps::ParticipantDiscoveryInfo && info) override
89  {
90  switch (info.status) {
91  case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT:
92  {
93  auto map = rmw::impl::cpp::parse_key_value(info.info.m_userData);
94  auto name_found = map.find("enclave");
95 
96  if (name_found == map.end()) {
97  return;
98  }
99  auto enclave =
100  std::string(name_found->second.begin(), name_found->second.end());
101 
102  context->graph_cache.add_participant(
104  identifier_, info.info.m_guid),
105  enclave);
106  break;
107  }
108  case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT:
109  // fall through
110  case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT:
111  context->graph_cache.remove_participant(
113  identifier_, info.info.m_guid));
114  break;
115  default:
116  return;
117  }
118  }
119 
121  eprosima::fastdds::dds::DomainParticipant *,
122  eprosima::fastrtps::rtps::ReaderDiscoveryInfo && info) override
123  {
124  if (eprosima::fastrtps::rtps::ReaderDiscoveryInfo::CHANGED_QOS_READER != info.status) {
125  bool is_alive =
126  eprosima::fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERED_READER == info.status;
127  process_discovery_info(info.info, is_alive, true);
128  }
129  }
130 
132  eprosima::fastdds::dds::DomainParticipant *,
133  eprosima::fastrtps::rtps::WriterDiscoveryInfo && info) override
134  {
135  if (eprosima::fastrtps::rtps::WriterDiscoveryInfo::CHANGED_QOS_WRITER != info.status) {
136  bool is_alive =
137  eprosima::fastrtps::rtps::WriterDiscoveryInfo::DISCOVERED_WRITER == info.status;
138  process_discovery_info(info.info, is_alive, false);
139  }
140  }
141 
142 private:
143  template<class T>
144  void
145  process_discovery_info(T & proxyData, bool is_alive, bool is_reader)
146  {
147  {
148  if (is_alive) {
149  rmw_qos_profile_t qos_profile = rmw_qos_profile_unknown;
150  rtps_qos_to_rmw_qos(proxyData.m_qos, &qos_profile);
151 
152  context->graph_cache.add_entity(
154  identifier_,
155  proxyData.guid()),
156  proxyData.topicName().to_string(),
157  proxyData.typeName().to_string(),
159  identifier_,
160  iHandle2GUID(proxyData.RTPSParticipantKey())),
161  qos_profile,
162  is_reader);
163  } else {
164  context->graph_cache.remove_entity(
166  identifier_,
167  proxyData.guid()),
168  is_reader);
169  }
170  }
171  }
172 
173  rmw_dds_common::Context * context;
174  const char * const identifier_;
175 };
176 
177 #endif // RMW_FASTRTPS_SHARED_CPP__CUSTOM_PARTICIPANT_INFO_HPP_
std::string
rmw.h
publishing_mode_t
publishing_mode_t
Definition: custom_participant_info.hpp:49
CustomParticipantInfo::subscriber_
eprosima::fastdds::dds::Subscriber * subscriber_
Definition: custom_participant_info.hpp:62
publishing_mode_t::ASYNCHRONOUS
@ ASYNCHRONOUS
ParticipantListener::on_participant_discovery
void on_participant_discovery(eprosima::fastdds::dds::DomainParticipant *, eprosima::fastrtps::rtps::ParticipantDiscoveryInfo &&info) override
Definition: custom_participant_info.hpp:86
key_value.hpp
logging_macros.h
publishing_mode_t::SYNCHRONOUS
@ SYNCHRONOUS
qos.hpp
publishing_mode_t::AUTO
@ AUTO
CustomParticipantInfo
Definition: custom_participant_info.hpp:56
CustomParticipantInfo::entity_creation_mutex_
std::mutex entity_creation_mutex_
Definition: custom_participant_info.hpp:65
ParticipantListener::on_publisher_discovery
void on_publisher_discovery(eprosima::fastdds::dds::DomainParticipant *, eprosima::fastrtps::rtps::WriterDiscoveryInfo &&info) override
Definition: custom_participant_info.hpp:131
rmw_fastrtps_shared_cpp::create_rmw_gid
rmw_gid_t create_rmw_gid(const char *identifier, const eprosima::fastrtps::rtps::GUID_t &guid)
CustomParticipantInfo::leave_middleware_default_qos
bool leave_middleware_default_qos
Definition: custom_participant_info.hpp:72
thread_safety_annotations.hpp
CustomParticipantInfo
struct CustomParticipantInfo CustomParticipantInfo
rmw_qos_profile_t
CustomParticipantInfo::listener_
ParticipantListener * listener_
Definition: custom_participant_info.hpp:59
std::mutex
ParticipantListener::ParticipantListener
ParticipantListener(const char *identifier, rmw_dds_common::Context *context)
Definition: custom_participant_info.hpp:79
rtps_qos_to_rmw_qos
void rtps_qos_to_rmw_qos(const RTPSQoSPolicyT &rtps_qos, rmw_qos_profile_t *qos)
Definition: qos.hpp:133
ParticipantListener
Definition: custom_participant_info.hpp:76
ParticipantListener::on_subscriber_discovery
void on_subscriber_discovery(eprosima::fastdds::dds::DomainParticipant *, eprosima::fastrtps::rtps::ReaderDiscoveryInfo &&info) override
Definition: custom_participant_info.hpp:120
rmw_common.hpp
create_rmw_gid.hpp
CustomParticipantInfo::publisher_
eprosima::fastdds::dds::Publisher * publisher_
Definition: custom_participant_info.hpp:61
CustomParticipantInfo::participant_
eprosima::fastdds::dds::DomainParticipant * participant_
Definition: custom_participant_info.hpp:58
CustomParticipantInfo::publishing_mode
publishing_mode_t publishing_mode
Definition: custom_participant_info.hpp:73
qos_profiles.h