/src/Fast-DDS/src/cpp/rtps/builtin/data/WriterProxyData.hpp
Line | Count | Source |
1 | | // Copyright 2016 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 | | * @file WriterProxyData.hpp |
17 | | */ |
18 | | |
19 | | #ifndef FASTDDS_RTPS_BUILTIN_DATA__WRITERPROXYDATA_HPP |
20 | | #define FASTDDS_RTPS_BUILTIN_DATA__WRITERPROXYDATA_HPP |
21 | | |
22 | | #include <fastcdr/cdr/fixed_size_string.hpp> |
23 | | |
24 | | #include <fastdds/dds/publisher/qos/WriterQos.hpp> |
25 | | #include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp> |
26 | | #include <fastdds/rtps/builtin/data/PublicationBuiltinTopicData.hpp> |
27 | | #include <fastdds/rtps/common/LocatorList.hpp> |
28 | | #include <fastdds/rtps/common/RemoteLocators.hpp> |
29 | | #include <fastdds/rtps/common/VendorId_t.hpp> |
30 | | #if HAVE_SECURITY |
31 | | #include <fastdds/rtps/attributes/EndpointSecurityAttributes.hpp> |
32 | | #endif // if HAVE_SECURITY |
33 | | |
34 | | |
35 | | namespace eprosima { |
36 | | namespace fastdds { |
37 | | namespace rtps { |
38 | | |
39 | | struct CDRMessage_t; |
40 | | class NetworkFactory; |
41 | | class ParticipantProxyData; |
42 | | |
43 | | /** |
44 | | **@ingroup BUILTIN_MODULE |
45 | | */ |
46 | | class WriterProxyData : public PublicationBuiltinTopicData |
47 | | { |
48 | | public: |
49 | | |
50 | | WriterProxyData( |
51 | | const size_t max_unicast_locators, |
52 | | const size_t max_multicast_locators); |
53 | | |
54 | | WriterProxyData( |
55 | | const size_t max_unicast_locators, |
56 | | const size_t max_multicast_locators, |
57 | | const VariableLengthDataLimits& data_limits); |
58 | | |
59 | | WriterProxyData( |
60 | | const VariableLengthDataLimits& data_limits, |
61 | | const PublicationBuiltinTopicData& publication_data); |
62 | | |
63 | | virtual ~WriterProxyData(); |
64 | | |
65 | | WriterProxyData( |
66 | | const WriterProxyData& writerInfo); |
67 | | |
68 | | WriterProxyData& operator =( |
69 | | const WriterProxyData& writerInfo); |
70 | | |
71 | | void networkConfiguration( |
72 | | const NetworkConfigSet_t& network_configuration) |
73 | 0 | { |
74 | 0 | m_network_configuration = network_configuration; |
75 | 0 | } |
76 | | |
77 | | void networkConfiguration( |
78 | | NetworkConfigSet_t&& network_configuration) |
79 | 0 | { |
80 | 0 | m_network_configuration = std::move(network_configuration); |
81 | 0 | } |
82 | | |
83 | | const NetworkConfigSet_t& networkConfiguration() const |
84 | 0 | { |
85 | 0 | return m_network_configuration; |
86 | 0 | } |
87 | | |
88 | | NetworkConfigSet_t& networkConfiguration() |
89 | 0 | { |
90 | 0 | return m_network_configuration; |
91 | 0 | } |
92 | | |
93 | | void set_persistence_entity_id( |
94 | | const EntityId_t& nid) |
95 | 0 | { |
96 | 0 | persistence_guid.entityId = persistence_guid.guidPrefix != c_GuidPrefix_Unknown ? nid : c_EntityId_Unknown; |
97 | 0 | } |
98 | | |
99 | | bool has_locators() const |
100 | 0 | { |
101 | 0 | return !remote_locators.unicast.empty() || !remote_locators.multicast.empty(); |
102 | 0 | } |
103 | | |
104 | | void add_unicast_locator( |
105 | | const Locator_t& locator); |
106 | | |
107 | | void set_announced_unicast_locators( |
108 | | const LocatorList_t& locators); |
109 | | |
110 | | /** |
111 | | * Set the remote unicast locators from @param locators. |
112 | | * @param locators List of locators to be used |
113 | | * @param network NetworkFactory to check if the locators are allowed |
114 | | * @param from_this_host Whether the server is from this host or not |
115 | | */ |
116 | | void set_remote_unicast_locators( |
117 | | const LocatorList_t& locators, |
118 | | const NetworkFactory& network, |
119 | | bool from_this_host); |
120 | | |
121 | | void add_multicast_locator( |
122 | | const Locator_t& locator); |
123 | | |
124 | | /** |
125 | | * Set the remote multicast locators from @param locators. |
126 | | * @param locators List of locators to be used |
127 | | * @param network NetworkFactory to check if the locators are allowed |
128 | | * @param from_this_host Whether the server is from this host or not |
129 | | */ |
130 | | void set_multicast_locators( |
131 | | const LocatorList_t& locators, |
132 | | const NetworkFactory& network, |
133 | | bool from_this_host); |
134 | | |
135 | | void set_locators( |
136 | | const RemoteLocatorList& locators); |
137 | | |
138 | | /** |
139 | | * Set the remote multicast and unicast locators from @param locators. |
140 | | * @param locators List of locators to be used |
141 | | * @param network NetworkFactory to check if the locators are allowed |
142 | | * @param use_multicast_locators Whether to set multicast locators or not |
143 | | * @param from_this_host Whether the server is from this host or not |
144 | | */ |
145 | | void set_remote_locators( |
146 | | const RemoteLocatorList& remote_locators, |
147 | | const NetworkFactory& network, |
148 | | bool use_multicast_locators, |
149 | | bool from_this_host); |
150 | | |
151 | | void key( |
152 | | const InstanceHandle_t& key) |
153 | 0 | { |
154 | 0 | m_key = key; |
155 | 0 | } |
156 | | |
157 | | void key( |
158 | | InstanceHandle_t&& key) |
159 | 0 | { |
160 | 0 | m_key = std::move(key); |
161 | 0 | } |
162 | | |
163 | | InstanceHandle_t key() const |
164 | 0 | { |
165 | 0 | return m_key; |
166 | 0 | } |
167 | | |
168 | | InstanceHandle_t& key() |
169 | 0 | { |
170 | 0 | return m_key; |
171 | 0 | } |
172 | | |
173 | | void rtps_participant_key( |
174 | | const InstanceHandle_t& rtps_participant_key) |
175 | 0 | { |
176 | 0 | m_rtps_participant_key = rtps_participant_key; |
177 | 0 | } |
178 | | |
179 | | void rtps_participant_key( |
180 | | InstanceHandle_t&& rtps_participant_key) |
181 | 0 | { |
182 | 0 | m_rtps_participant_key = std::move(rtps_participant_key); |
183 | 0 | } |
184 | | |
185 | | InstanceHandle_t rtps_participant_key() const |
186 | 0 | { |
187 | 0 | return m_rtps_participant_key; |
188 | 0 | } |
189 | | |
190 | | InstanceHandle_t& rtps_participant_key() |
191 | 0 | { |
192 | 0 | return m_rtps_participant_key; |
193 | 0 | } |
194 | | |
195 | | void user_defined_id( |
196 | | uint16_t user_defined_id) |
197 | 0 | { |
198 | 0 | m_user_defined_id = user_defined_id; |
199 | 0 | } |
200 | | |
201 | | uint16_t user_defined_id() const |
202 | 0 | { |
203 | 0 | return m_user_defined_id; |
204 | 0 | } |
205 | | |
206 | | uint16_t& user_defined_id() |
207 | 0 | { |
208 | 0 | return m_user_defined_id; |
209 | 0 | } |
210 | | |
211 | | void type_max_serialized( |
212 | | uint32_t type_max_serialized) |
213 | 0 | { |
214 | 0 | max_serialized_size = type_max_serialized; |
215 | 0 | } |
216 | | |
217 | | uint32_t type_max_serialized() const |
218 | 0 | { |
219 | 0 | return max_serialized_size; |
220 | 0 | } |
221 | | |
222 | | uint32_t& type_max_serialized() |
223 | 0 | { |
224 | 0 | return max_serialized_size; |
225 | 0 | } |
226 | | |
227 | | void type_id( |
228 | | const dds::TypeIdV1& other_type_id) |
229 | 0 | { |
230 | 0 | type_id() = other_type_id; |
231 | 0 | } |
232 | | |
233 | | const dds::TypeIdV1& type_id() const |
234 | 0 | { |
235 | 0 | assert(m_type_id != nullptr); |
236 | 0 | return *m_type_id; |
237 | 0 | } |
238 | | |
239 | | dds::TypeIdV1& type_id() |
240 | 0 | { |
241 | 0 | if (m_type_id == nullptr) |
242 | 0 | { |
243 | 0 | m_type_id = new dds::TypeIdV1(); |
244 | 0 | } |
245 | 0 | return *m_type_id; |
246 | 0 | } |
247 | | |
248 | | bool has_type_id() const |
249 | 0 | { |
250 | 0 | return m_type_id != nullptr; |
251 | 0 | } |
252 | | |
253 | | void type( |
254 | | const dds::TypeObjectV1& other_type) |
255 | 0 | { |
256 | 0 | type() = other_type; |
257 | 0 | } |
258 | | |
259 | | const dds::TypeObjectV1& type() const |
260 | 0 | { |
261 | 0 | assert(m_type != nullptr); |
262 | 0 | return *m_type; |
263 | 0 | } |
264 | | |
265 | | dds::TypeObjectV1& type() |
266 | 0 | { |
267 | 0 | if (m_type == nullptr) |
268 | 0 | { |
269 | 0 | m_type = new dds::TypeObjectV1(); |
270 | 0 | } |
271 | 0 | return *m_type; |
272 | 0 | } |
273 | | |
274 | | bool has_type() const |
275 | 0 | { |
276 | 0 | return m_type != nullptr; |
277 | 0 | } |
278 | | |
279 | | bool has_type_information() const |
280 | 0 | { |
281 | 0 | return type_information.assigned(); |
282 | 0 | } |
283 | | |
284 | | /** |
285 | | * Set participant client server sample identity |
286 | | * @param sid valid SampleIdentity |
287 | | */ |
288 | | void set_sample_identity( |
289 | | const SampleIdentity& sid) |
290 | 0 | { |
291 | 0 | fastdds::dds::set_proxy_property(sid, "PID_CLIENT_SERVER_KEY", properties); |
292 | 0 | } |
293 | | |
294 | | /** |
295 | | * Retrieve participant SampleIdentity |
296 | | * @return SampleIdentity |
297 | | */ |
298 | | SampleIdentity get_sample_identity() const |
299 | 0 | { |
300 | 0 | return fastdds::dds::get_proxy_property<SampleIdentity>("PID_CLIENT_SERVER_KEY", properties); |
301 | 0 | } |
302 | | |
303 | | #if HAVE_SECURITY |
304 | | //!EndpointSecurityInfo.endpoint_security_attributes |
305 | | security::EndpointSecurityAttributesMask security_attributes_; |
306 | | |
307 | | //!EndpointSecurityInfo.plugin_endpoint_security_attributes |
308 | | security::PluginEndpointSecurityAttributesMask plugin_security_attributes_; |
309 | | #endif // if HAVE_SECURITY |
310 | | |
311 | | //!Clear the information and return the object to the default state. |
312 | | void clear(); |
313 | | |
314 | | /** |
315 | | * Check if this object can be updated with the information on another object. |
316 | | * @param wdata WriterProxyData object to be checked. |
317 | | * @return true if this object can be updated with the information on wdata. |
318 | | */ |
319 | | bool is_update_allowed( |
320 | | const WriterProxyData& wdata) const; |
321 | | |
322 | | /** |
323 | | * Update certain parameters from another object. |
324 | | * @param wdata pointer to object with new information. |
325 | | */ |
326 | | void update( |
327 | | WriterProxyData* wdata); |
328 | | |
329 | | /** |
330 | | * Get the size in bytes of the CDR serialization of this object. |
331 | | * @param include_encapsulation Whether to include the size of the encapsulation info. |
332 | | * @param force_including_optional_qos Whether to force including the optional QoS in the size. |
333 | | * @return size in bytes of the CDR serialization. |
334 | | */ |
335 | | uint32_t get_serialized_size( |
336 | | bool include_encapsulation, |
337 | | bool force_including_optional_qos = false) const; |
338 | | |
339 | | /** |
340 | | * Write as a parameter list on a CDRMessage_t |
341 | | * @param msg Pointer to the CDRmessage. |
342 | | * @param write_encapsulation Whether to write the encapsulation info. |
343 | | * @param force_write_optional_qos Whether to write the optional QoS. |
344 | | * @return True on success |
345 | | */ |
346 | | bool write_to_cdr_message( |
347 | | CDRMessage_t* msg, |
348 | | bool write_encapsulation, |
349 | | bool force_write_optional_qos = false) const; |
350 | | |
351 | | /** |
352 | | * Read the information from a CDRMessage_t. The position of the message must be in the beginning on the |
353 | | * parameter list. |
354 | | * @param msg Pointer to the message. |
355 | | * @param source_vendor_id VendorId of the source participant from which the message was received |
356 | | * @return true on success |
357 | | */ |
358 | | bool read_from_cdr_message( |
359 | | CDRMessage_t* msg, |
360 | | fastdds::rtps::VendorId_t source_vendor_id = c_VendorId_eProsima); |
361 | | |
362 | | /** |
363 | | * Transform and set the remote locators from the remote_locators of another WriterProxyData. |
364 | | * If the received WriterProxyData has no locators, remote locators will be extracted from the |
365 | | * ParticipantProxyData. |
366 | | * @param wdata WriterProxyData to get the locators from |
367 | | * @param network NetworkFactory to transform locators |
368 | | * @param participant_data ParticipantProxyData to get the locators from |
369 | | */ |
370 | | void setup_locators( |
371 | | const WriterProxyData& wdata, |
372 | | NetworkFactory& network, |
373 | | const ParticipantProxyData& participant_data); |
374 | | |
375 | | /** |
376 | | * Set qos parameters |
377 | | * (only certain qos from PublicationBuiltinTopicData will be set). |
378 | | * |
379 | | * @param qos Const reference to the PublicationBuiltinTopicData object. |
380 | | * @param first_time Boolean indicating whether is the first time (true) or not (false). |
381 | | */ |
382 | | void set_qos( |
383 | | const PublicationBuiltinTopicData& qos, |
384 | | bool first_time); |
385 | | |
386 | | /** |
387 | | * Set qos parameters from a WriterQos structure. |
388 | | * (only certain qos from PublicationBuiltinTopicData will be set). |
389 | | * |
390 | | * @param qos Const reference to the WriterQos object. |
391 | | * @param first_time Boolean indicating whether is the first time (true) or not (false). |
392 | | */ |
393 | | void set_qos( |
394 | | const dds::WriterQos& qos, |
395 | | bool first_time); |
396 | | |
397 | | //! Getter for m_should_send_optional_qos. |
398 | | bool should_send_optional_qos() const |
399 | 0 | { |
400 | 0 | return m_should_send_optional_qos; |
401 | 0 | } |
402 | | |
403 | | /** |
404 | | * Set whether optional QoS should be serialized and added to Data(r). |
405 | | * @param should_send_optional_qos Boolean indicating whether optional QoS should be serialized |
406 | | * and added to Data(r). |
407 | | */ |
408 | | void should_send_optional_qos( |
409 | | bool should_send_optional_qos) |
410 | 0 | { |
411 | 0 | m_should_send_optional_qos = should_send_optional_qos; |
412 | 0 | } |
413 | | |
414 | | private: |
415 | | |
416 | | /** |
417 | | * Initialize the common attributes of the ReaderProxyData. |
418 | | */ |
419 | | void init( |
420 | | const VariableLengthDataLimits& data_limits); |
421 | | |
422 | | /** |
423 | | * Checks whether the QoS can be updated with the provided QoS. |
424 | | * |
425 | | * @param qos The QoS to check. |
426 | | * @return true if the QoS can be updated, false otherwise. |
427 | | */ |
428 | | bool can_qos_be_updated( |
429 | | const PublicationBuiltinTopicData& qos) const; |
430 | | |
431 | | //!Network configuration |
432 | | NetworkConfigSet_t m_network_configuration; |
433 | | |
434 | | //!GUID_t of the Writer converted to InstanceHandle_t |
435 | | InstanceHandle_t m_key; |
436 | | |
437 | | //!GUID_t of the participant converted to InstanceHandle |
438 | | InstanceHandle_t m_rtps_participant_key; |
439 | | |
440 | | //!User defined ID |
441 | | uint16_t m_user_defined_id; |
442 | | |
443 | | //!Type Identifier |
444 | | dds::TypeIdV1* m_type_id; |
445 | | |
446 | | //!Type Object |
447 | | dds::TypeObjectV1* m_type; |
448 | | |
449 | | //!Whether optional QoS should be serialized and added to Data(r) |
450 | | bool m_should_send_optional_qos{false}; |
451 | | }; |
452 | | |
453 | | } // namespace rtps |
454 | | } // namespace fastdds |
455 | | } // namespace eprosima |
456 | | |
457 | | #endif // FASTDDS_RTPS_BUILTIN_DATA__WRITERPROXYDATA_HPP |