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 "fastrtps/rtps/common/InstanceHandle.h"
24 #include "fastrtps/attributes/ParticipantAttributes.h"
25 #include "fastrtps/participant/Participant.h"
26 #include "fastrtps/participant/ParticipantListener.h"
27 
29 #include "rcutils/logging_macros.h"
30 
32 #include "rmw/qos_profiles.h"
33 #include "rmw/rmw.h"
34 
35 #include "rmw_dds_common/context.hpp"
36 
40 
41 using rmw_dds_common::operator<<;
42 
44 
45 typedef struct CustomParticipantInfo
46 {
47  eprosima::fastrtps::Participant * participant;
49 
50  // Flag to establish if the QoS of the participant,
51  // its publishers and its subscribers are going
52  // to be configured only from an XML file or if
53  // their settings are going to be overwritten by code
54  // with the default configuration.
57 
58 class ParticipantListener : public eprosima::fastrtps::ParticipantListener
59 {
60 public:
62  const char * identifier,
63  rmw_dds_common::Context * context)
64  : context(context),
65  identifier_(identifier)
66  {}
67 
69  eprosima::fastrtps::Participant *,
70  eprosima::fastrtps::rtps::ParticipantDiscoveryInfo && info) override
71  {
72  switch (info.status) {
73  case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT:
74  {
75  auto map = rmw::impl::cpp::parse_key_value(info.info.m_userData);
76  auto name_found = map.find("enclave");
77 
78  if (name_found == map.end()) {
79  return;
80  }
81  auto enclave =
82  std::string(name_found->second.begin(), name_found->second.end());
83 
84  context->graph_cache.add_participant(
86  identifier_, info.info.m_guid),
87  enclave);
88  break;
89  }
90  case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT:
91  // fall through
92  case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT:
93  context->graph_cache.remove_participant(
95  identifier_, info.info.m_guid));
96  break;
97  default:
98  return;
99  }
100  }
101 
103  eprosima::fastrtps::Participant *,
104  eprosima::fastrtps::rtps::ReaderDiscoveryInfo && info) override
105  {
106  if (eprosima::fastrtps::rtps::ReaderDiscoveryInfo::CHANGED_QOS_READER != info.status) {
107  bool is_alive =
108  eprosima::fastrtps::rtps::ReaderDiscoveryInfo::DISCOVERED_READER == info.status;
109  process_discovery_info(info.info, is_alive, true);
110  }
111  }
112 
114  eprosima::fastrtps::Participant *,
115  eprosima::fastrtps::rtps::WriterDiscoveryInfo && info) override
116  {
117  if (eprosima::fastrtps::rtps::WriterDiscoveryInfo::CHANGED_QOS_WRITER != info.status) {
118  bool is_alive =
119  eprosima::fastrtps::rtps::WriterDiscoveryInfo::DISCOVERED_WRITER == info.status;
120  process_discovery_info(info.info, is_alive, false);
121  }
122  }
123 
124 private:
125  template<class T>
126  void
127  process_discovery_info(T & proxyData, bool is_alive, bool is_reader)
128  {
129  {
130  if (is_alive) {
131  rmw_qos_profile_t qos_profile = rmw_qos_profile_unknown;
132  dds_qos_to_rmw_qos(proxyData.m_qos, &qos_profile);
133 
134  context->graph_cache.add_entity(
136  identifier_,
137  proxyData.guid()),
138  proxyData.topicName().to_string(),
139  proxyData.typeName().to_string(),
141  identifier_,
142  iHandle2GUID(proxyData.RTPSParticipantKey())),
143  qos_profile,
144  is_reader);
145  } else {
146  context->graph_cache.remove_entity(
148  identifier_,
149  proxyData.guid()),
150  is_reader);
151  }
152  }
153  }
154 
155  rmw_dds_common::Context * context;
156  const char * const identifier_;
157 };
158 
159 #endif // RMW_FASTRTPS_SHARED_CPP__CUSTOM_PARTICIPANT_INFO_HPP_
std::string
ParticipantListener::onSubscriberDiscovery
void onSubscriberDiscovery(eprosima::fastrtps::Participant *, eprosima::fastrtps::rtps::ReaderDiscoveryInfo &&info) override
Definition: custom_participant_info.hpp:102
rmw.h
dds_qos_to_rmw_qos
void dds_qos_to_rmw_qos(const DDSQoSPolicyT &dds_qos, rmw_qos_profile_t *qos)
Definition: qos.hpp:64
key_value.hpp
logging_macros.h
qos.hpp
CustomParticipantInfo::participant
eprosima::fastrtps::Participant * participant
Definition: custom_participant_info.hpp:47
CustomParticipantInfo::listener
::ParticipantListener * listener
Definition: custom_participant_info.hpp:48
CustomParticipantInfo
Definition: custom_participant_info.hpp:45
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:55
thread_safety_annotations.hpp
CustomParticipantInfo
struct CustomParticipantInfo CustomParticipantInfo
ParticipantListener::onParticipantDiscovery
void onParticipantDiscovery(eprosima::fastrtps::Participant *, eprosima::fastrtps::rtps::ParticipantDiscoveryInfo &&info) override
Definition: custom_participant_info.hpp:68
rmw_qos_profile_t
ParticipantListener::ParticipantListener
ParticipantListener(const char *identifier, rmw_dds_common::Context *context)
Definition: custom_participant_info.hpp:61
ParticipantListener
Definition: custom_participant_info.hpp:58
ParticipantListener::onPublisherDiscovery
void onPublisherDiscovery(eprosima::fastrtps::Participant *, eprosima::fastrtps::rtps::WriterDiscoveryInfo &&info) override
Definition: custom_participant_info.hpp:113
rmw_common.hpp
create_rmw_gid.hpp
qos_profiles.h