/src/Fast-DDS/src/cpp/fastdds/utils/QosConverters.cpp
Line | Count | Source |
1 | | // Copyright 2022 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 | | /* |
16 | | * QosConverters.cpp |
17 | | * |
18 | | */ |
19 | | |
20 | | #include <string> |
21 | | |
22 | | #include <fastdds/rtps/common/Property.hpp> |
23 | | #include <fastdds/utils/QosConverters.hpp> |
24 | | |
25 | | namespace eprosima { |
26 | | namespace fastdds { |
27 | | namespace dds { |
28 | | namespace utils { |
29 | | |
30 | | using rtps::Property; |
31 | | using std::string; |
32 | | |
33 | | void set_qos_from_attributes( |
34 | | DataWriterQos& qos, |
35 | | const xmlparser::PublisherAttributes& attr) |
36 | 0 | { |
37 | 0 | qos.writer_resource_limits().matched_subscriber_allocation = attr.matched_subscriber_allocation; |
38 | 0 | qos.properties() = attr.properties; |
39 | 0 | qos.endpoint().unicast_locator_list = attr.unicastLocatorList; |
40 | 0 | qos.endpoint().multicast_locator_list = attr.multicastLocatorList; |
41 | 0 | qos.endpoint().remote_locator_list = attr.remoteLocatorList; |
42 | 0 | qos.endpoint().external_unicast_locators = attr.external_unicast_locators; |
43 | 0 | qos.endpoint().ignore_non_matching_locators = attr.ignore_non_matching_locators; |
44 | 0 | qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; |
45 | 0 | qos.endpoint().user_defined_id = attr.getUserDefinedID(); |
46 | 0 | qos.endpoint().entity_id = attr.getEntityID(); |
47 | 0 | qos.reliable_writer_qos().times = attr.times; |
48 | 0 | qos.reliable_writer_qos().disable_positive_acks = attr.qos.m_disablePositiveACKs; |
49 | 0 | qos.durability() = attr.qos.m_durability; |
50 | 0 | qos.durability_service() = attr.qos.m_durabilityService; |
51 | 0 | qos.deadline() = attr.qos.m_deadline; |
52 | 0 | qos.latency_budget() = attr.qos.m_latencyBudget; |
53 | 0 | qos.liveliness() = attr.qos.m_liveliness; |
54 | 0 | qos.reliability() = attr.qos.m_reliability; |
55 | 0 | qos.lifespan() = attr.qos.m_lifespan; |
56 | 0 | qos.user_data().setValue(attr.qos.m_userData); |
57 | 0 | qos.ownership() = attr.qos.m_ownership; |
58 | 0 | qos.ownership_strength() = attr.qos.m_ownershipStrength; |
59 | 0 | qos.destination_order() = attr.qos.m_destinationOrder; |
60 | 0 | qos.representation() = attr.qos.representation; |
61 | 0 | qos.publish_mode() = attr.qos.m_publishMode; |
62 | 0 | qos.history() = attr.topic.historyQos; |
63 | 0 | qos.resource_limits() = attr.topic.resourceLimitsQos; |
64 | 0 | qos.data_sharing() = attr.qos.data_sharing; |
65 | 0 | qos.reliable_writer_qos().disable_heartbeat_piggyback = attr.qos.disable_heartbeat_piggyback; |
66 | 0 | qos.transport_priority().value = attr.qos.transport_priority.value; |
67 | |
|
68 | 0 | if (attr.qos.m_partition.size() > 0 ) |
69 | 0 | { |
70 | 0 | Property property; |
71 | 0 | property.name("partitions"); |
72 | 0 | string partitions; |
73 | 0 | bool is_first_partition = true; |
74 | |
|
75 | 0 | for (auto partition : attr.qos.m_partition.names()) |
76 | 0 | { |
77 | 0 | partitions += (is_first_partition ? "" : ";") + partition; |
78 | 0 | is_first_partition = false; |
79 | 0 | } |
80 | |
|
81 | 0 | property.value(std::move(partitions)); |
82 | 0 | qos.properties().properties().push_back(std::move(property)); |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | | void set_qos_from_attributes( |
87 | | DataReaderQos& qos, |
88 | | const xmlparser::SubscriberAttributes& attr) |
89 | 0 | { |
90 | 0 | qos.reader_resource_limits().matched_publisher_allocation = attr.matched_publisher_allocation; |
91 | 0 | qos.properties() = attr.properties; |
92 | 0 | qos.expects_inline_qos(attr.expects_inline_qos); |
93 | 0 | qos.endpoint().unicast_locator_list = attr.unicastLocatorList; |
94 | 0 | qos.endpoint().multicast_locator_list = attr.multicastLocatorList; |
95 | 0 | qos.endpoint().remote_locator_list = attr.remoteLocatorList; |
96 | 0 | qos.endpoint().external_unicast_locators = attr.external_unicast_locators; |
97 | 0 | qos.endpoint().ignore_non_matching_locators = attr.ignore_non_matching_locators; |
98 | 0 | qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; |
99 | 0 | qos.endpoint().user_defined_id = attr.getUserDefinedID(); |
100 | 0 | qos.endpoint().entity_id = attr.getEntityID(); |
101 | 0 | qos.reliable_reader_qos().times = attr.times; |
102 | 0 | qos.reliable_reader_qos().disable_positive_acks = attr.qos.m_disablePositiveACKs; |
103 | 0 | qos.durability() = attr.qos.m_durability; |
104 | 0 | qos.durability_service() = attr.qos.m_durabilityService; |
105 | 0 | qos.deadline() = attr.qos.m_deadline; |
106 | 0 | qos.latency_budget() = attr.qos.m_latencyBudget; |
107 | 0 | qos.liveliness() = attr.qos.m_liveliness; |
108 | 0 | qos.reliability() = attr.qos.m_reliability; |
109 | 0 | qos.lifespan() = attr.qos.m_lifespan; |
110 | 0 | qos.user_data().setValue(attr.qos.m_userData); |
111 | 0 | qos.ownership() = attr.qos.m_ownership; |
112 | 0 | qos.destination_order() = attr.qos.m_destinationOrder; |
113 | 0 | qos.type_consistency() = attr.qos.type_consistency; |
114 | 0 | qos.representation() = attr.qos.representation; |
115 | 0 | qos.time_based_filter() = attr.qos.m_timeBasedFilter; |
116 | 0 | qos.history() = attr.topic.historyQos; |
117 | 0 | qos.resource_limits() = attr.topic.resourceLimitsQos; |
118 | 0 | qos.data_sharing() = attr.qos.data_sharing; |
119 | |
|
120 | 0 | if (attr.qos.m_partition.size() > 0 ) |
121 | 0 | { |
122 | 0 | Property property; |
123 | 0 | property.name("partitions"); |
124 | 0 | string partitions; |
125 | 0 | bool is_first_partition = true; |
126 | |
|
127 | 0 | for (auto partition : attr.qos.m_partition.names()) |
128 | 0 | { |
129 | 0 | partitions += (is_first_partition ? "" : ";") + partition; |
130 | 0 | is_first_partition = false; |
131 | 0 | } |
132 | |
|
133 | 0 | property.value(std::move(partitions)); |
134 | 0 | qos.properties().properties().push_back(std::move(property)); |
135 | 0 | } |
136 | 0 | } |
137 | | |
138 | | void set_qos_from_attributes( |
139 | | DomainParticipantQos& qos, |
140 | | const eprosima::fastdds::rtps::RTPSParticipantAttributes& attr) |
141 | 0 | { |
142 | 0 | qos.user_data().setValue(attr.userData); |
143 | 0 | qos.allocation() = attr.allocation; |
144 | 0 | qos.wire_protocol().prefix = attr.prefix; |
145 | 0 | qos.wire_protocol().participant_id = attr.participantID; |
146 | 0 | qos.wire_protocol().builtin = attr.builtin; |
147 | 0 | qos.wire_protocol().port = attr.port; |
148 | 0 | qos.wire_protocol().default_unicast_locator_list = attr.defaultUnicastLocatorList; |
149 | 0 | qos.wire_protocol().default_multicast_locator_list = attr.defaultMulticastLocatorList; |
150 | 0 | qos.wire_protocol().default_external_unicast_locators = attr.default_external_unicast_locators; |
151 | 0 | qos.wire_protocol().ignore_non_matching_locators = attr.ignore_non_matching_locators; |
152 | 0 | qos.wire_protocol().easy_mode(attr.easy_mode_ip); |
153 | 0 | qos.transport().user_transports = attr.userTransports; |
154 | 0 | qos.transport().use_builtin_transports = attr.useBuiltinTransports; |
155 | 0 | qos.transport().send_socket_buffer_size = attr.sendSocketBufferSize; |
156 | 0 | qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize; |
157 | 0 | qos.transport().max_msg_size_no_frag = attr.max_msg_size_no_frag; |
158 | 0 | qos.transport().netmask_filter = attr.netmaskFilter; |
159 | 0 | qos.name() = attr.getName(); |
160 | 0 | qos.flow_controllers() = attr.flow_controllers; |
161 | 0 | qos.builtin_controllers_sender_thread() = attr.builtin_controllers_sender_thread; |
162 | 0 | qos.timed_events_thread() = attr.timed_events_thread; |
163 | 0 | qos.discovery_server_thread() = attr.discovery_server_thread; |
164 | 0 | qos.typelookup_service_thread() = attr.typelookup_service_thread; |
165 | | #if HAVE_SECURITY |
166 | | qos.security_log_thread() = attr.security_log_thread; |
167 | | #endif // if HAVE_SECURITY |
168 | | |
169 | | // Merge attributes and qos properties |
170 | 0 | for (auto property : attr.properties.properties()) |
171 | 0 | { |
172 | 0 | string* property_value = fastdds::rtps::PropertyPolicyHelper::find_property( |
173 | 0 | qos.properties(), property.name()); |
174 | 0 | if (nullptr == property_value) |
175 | 0 | { |
176 | 0 | qos.properties().properties().emplace_back(property); |
177 | 0 | } |
178 | 0 | else |
179 | 0 | { |
180 | 0 | *property_value = property.value(); |
181 | 0 | } |
182 | 0 | } |
183 | 0 | qos.properties().binary_properties() = attr.properties.binary_properties(); |
184 | 0 | } |
185 | | |
186 | | void set_extended_qos_from_attributes( |
187 | | DomainParticipantExtendedQos& extended_qos, |
188 | | const eprosima::fastdds::xmlparser::ParticipantAttributes& attr) |
189 | 0 | { |
190 | 0 | extended_qos.domainId() = attr.domainId; |
191 | 0 | set_qos_from_attributes(extended_qos, attr.rtps); |
192 | 0 | } |
193 | | |
194 | | void set_attributes_from_qos( |
195 | | fastdds::rtps::RTPSParticipantAttributes& attr, |
196 | | const DomainParticipantQos& qos) |
197 | 0 | { |
198 | 0 | attr.allocation = qos.allocation(); |
199 | 0 | attr.properties = qos.properties(); |
200 | 0 | attr.setName(qos.name()); |
201 | 0 | attr.prefix = qos.wire_protocol().prefix; |
202 | 0 | attr.participantID = qos.wire_protocol().participant_id; |
203 | 0 | attr.easy_mode_ip = qos.wire_protocol().easy_mode(); |
204 | 0 | attr.builtin = qos.wire_protocol().builtin; |
205 | 0 | attr.port = qos.wire_protocol().port; |
206 | 0 | attr.defaultUnicastLocatorList = qos.wire_protocol().default_unicast_locator_list; |
207 | 0 | attr.defaultMulticastLocatorList = qos.wire_protocol().default_multicast_locator_list; |
208 | 0 | attr.default_external_unicast_locators = qos.wire_protocol().default_external_unicast_locators; |
209 | 0 | attr.ignore_non_matching_locators = qos.wire_protocol().ignore_non_matching_locators; |
210 | 0 | attr.userTransports = qos.transport().user_transports; |
211 | 0 | attr.useBuiltinTransports = qos.transport().use_builtin_transports; |
212 | 0 | attr.sendSocketBufferSize = qos.transport().send_socket_buffer_size; |
213 | 0 | attr.listenSocketBufferSize = qos.transport().listen_socket_buffer_size; |
214 | 0 | attr.max_msg_size_no_frag = qos.transport().max_msg_size_no_frag; |
215 | 0 | attr.netmaskFilter = qos.transport().netmask_filter; |
216 | 0 | attr.userData = qos.user_data().data_vec(); |
217 | 0 | attr.flow_controllers = qos.flow_controllers(); |
218 | 0 | attr.builtin_controllers_sender_thread = qos.builtin_controllers_sender_thread(); |
219 | 0 | attr.timed_events_thread = qos.timed_events_thread(); |
220 | 0 | attr.discovery_server_thread = qos.discovery_server_thread(); |
221 | 0 | attr.typelookup_service_thread = qos.typelookup_service_thread(); |
222 | | #if HAVE_SECURITY |
223 | | attr.security_log_thread = qos.security_log_thread(); |
224 | | #endif // if HAVE_SECURITY |
225 | 0 | } |
226 | | |
227 | | void set_attributes_from_extended_qos( |
228 | | eprosima::fastdds::xmlparser::ParticipantAttributes& attr, |
229 | | const DomainParticipantExtendedQos& extended_qos) |
230 | 0 | { |
231 | 0 | attr.domainId = extended_qos.domainId(); |
232 | 0 | set_attributes_from_qos(attr.rtps, extended_qos); |
233 | 0 | } |
234 | | |
235 | | void set_qos_from_attributes( |
236 | | TopicQos& qos, |
237 | | const xmlparser::TopicAttributes& attr) |
238 | 0 | { |
239 | 0 | qos.history() = attr.historyQos; |
240 | 0 | qos.resource_limits() = attr.resourceLimitsQos; |
241 | 0 | } |
242 | | |
243 | | void set_qos_from_attributes( |
244 | | SubscriberQos& qos, |
245 | | const xmlparser::SubscriberAttributes& attr) |
246 | 0 | { |
247 | 0 | qos.group_data().setValue(attr.qos.m_groupData); |
248 | 0 | qos.partition() = attr.qos.m_partition; |
249 | 0 | qos.presentation() = attr.qos.m_presentation; |
250 | 0 | } |
251 | | |
252 | | void set_qos_from_attributes( |
253 | | PublisherQos& qos, |
254 | | const xmlparser::PublisherAttributes& attr) |
255 | 0 | { |
256 | 0 | qos.group_data().setValue(attr.qos.m_groupData); |
257 | 0 | qos.partition() = attr.qos.m_partition; |
258 | 0 | qos.presentation() = attr.qos.m_presentation; |
259 | 0 | } |
260 | | |
261 | | void set_qos_from_attributes( |
262 | | ReplierQos& qos, |
263 | | const xmlparser::ReplierAttributes& attr) |
264 | 0 | { |
265 | 0 | qos.service_name = attr.service_name; |
266 | 0 | qos.request_type = attr.request_type; |
267 | 0 | qos.reply_type = attr.reply_type; |
268 | 0 | qos.request_topic_name = attr.request_topic_name; |
269 | 0 | qos.reply_topic_name = attr.reply_topic_name; |
270 | 0 | set_qos_from_attributes(qos.writer_qos, attr.publisher); |
271 | 0 | set_qos_from_attributes(qos.reader_qos, attr.subscriber); |
272 | 0 | } |
273 | | |
274 | | void set_qos_from_attributes( |
275 | | RequesterQos& qos, |
276 | | const xmlparser::RequesterAttributes& attr) |
277 | 0 | { |
278 | 0 | qos.service_name = attr.service_name; |
279 | 0 | qos.request_type = attr.request_type; |
280 | 0 | qos.reply_type = attr.reply_type; |
281 | 0 | qos.request_topic_name = attr.request_topic_name; |
282 | 0 | qos.reply_topic_name = attr.reply_topic_name; |
283 | 0 | set_qos_from_attributes(qos.writer_qos, attr.publisher); |
284 | 0 | set_qos_from_attributes(qos.reader_qos, attr.subscriber); |
285 | 0 | } |
286 | | |
287 | | } /* namespace utils */ |
288 | | } /* namespace dds */ |
289 | | } /* namespace fastdds */ |
290 | | } /* namespace eprosima */ |