Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/builtin/data/WriterProxyData.h
Line
Count
Source (jump to first uncovered line)
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.h
17
 *
18
 */
19
20
#ifndef _FASTDDS_RTPS_BUILTIN_DATA_WRITERPROXYDATA_H_
21
#define _FASTDDS_RTPS_BUILTIN_DATA_WRITERPROXYDATA_H_
22
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
23
24
#include <fastrtps/qos/WriterQos.h>
25
#include <fastrtps/attributes/TopicAttributes.h>
26
27
#include <fastrtps/utils/fixed_size_string.hpp>
28
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
29
30
#if HAVE_SECURITY
31
#include <fastdds/rtps/security/accesscontrol/EndpointSecurityAttributes.h>
32
#endif // if HAVE_SECURITY
33
34
#include <fastdds/rtps/common/RemoteLocators.hpp>
35
36
namespace eprosima {
37
namespace fastrtps {
38
namespace rtps {
39
40
struct CDRMessage_t;
41
class NetworkFactory;
42
class ParticipantProxyData;
43
44
/**
45
 **@ingroup BUILTIN_MODULE
46
 */
47
class WriterProxyData
48
{
49
public:
50
51
    RTPS_DllAPI WriterProxyData(
52
            const size_t max_unicast_locators,
53
            const size_t max_multicast_locators);
54
55
    RTPS_DllAPI WriterProxyData(
56
            const size_t max_unicast_locators,
57
            const size_t max_multicast_locators,
58
            const VariableLengthDataLimits& data_limits);
59
60
    virtual RTPS_DllAPI ~WriterProxyData();
61
62
    RTPS_DllAPI WriterProxyData(
63
            const WriterProxyData& writerInfo);
64
65
    RTPS_DllAPI WriterProxyData& operator =(
66
            const WriterProxyData& writerInfo);
67
68
    RTPS_DllAPI void guid(
69
            const GUID_t& guid)
70
0
    {
71
0
        m_guid = guid;
72
0
    }
73
74
    RTPS_DllAPI void guid(
75
            GUID_t&& guid)
76
0
    {
77
0
        m_guid = std::move(guid);
78
0
    }
79
80
    RTPS_DllAPI const GUID_t& guid() const
81
0
    {
82
0
        return m_guid;
83
0
    }
84
85
    RTPS_DllAPI GUID_t& guid()
86
0
    {
87
0
        return m_guid;
88
0
    }
89
90
    RTPS_DllAPI void persistence_guid(
91
            const GUID_t& guid)
92
0
    {
93
0
        persistence_guid_ = guid;
94
0
    }
95
96
    RTPS_DllAPI void persistence_guid(
97
            GUID_t&& guid)
98
0
    {
99
0
        persistence_guid_ = std::move(guid);
100
0
    }
101
102
    RTPS_DllAPI GUID_t persistence_guid() const
103
0
    {
104
0
        return persistence_guid_;
105
0
    }
106
107
    RTPS_DllAPI GUID_t& persistence_guid()
108
0
    {
109
0
        return persistence_guid_;
110
0
    }
111
112
    RTPS_DllAPI void set_persistence_entity_id(
113
            const EntityId_t& nid)
114
0
    {
115
0
        persistence_guid_.entityId = persistence_guid_.guidPrefix != c_GuidPrefix_Unknown ? nid : c_EntityId_Unknown;
116
0
    }
117
118
    RTPS_DllAPI bool has_locators() const
119
0
    {
120
0
        return !remote_locators_.unicast.empty() || !remote_locators_.multicast.empty();
121
0
    }
122
123
    RTPS_DllAPI const RemoteLocatorList& remote_locators() const
124
0
    {
125
0
        return remote_locators_;
126
0
    }
127
128
    RTPS_DllAPI void add_unicast_locator(
129
            const Locator_t& locator);
130
131
    void set_announced_unicast_locators(
132
            const LocatorList_t& locators);
133
134
    void set_remote_unicast_locators(
135
            const LocatorList_t& locators,
136
            const NetworkFactory& network);
137
138
    RTPS_DllAPI void add_multicast_locator(
139
            const Locator_t& locator);
140
141
    void set_multicast_locators(
142
            const LocatorList_t& locators,
143
            const NetworkFactory& network);
144
145
    void set_locators(
146
            const RemoteLocatorList& locators);
147
148
    void set_remote_locators(
149
            const RemoteLocatorList& remote_locators,
150
            const NetworkFactory& network,
151
            bool use_multicast_locators);
152
153
    RTPS_DllAPI void key(
154
            const InstanceHandle_t& key)
155
0
    {
156
0
        m_key = key;
157
0
    }
158
159
    RTPS_DllAPI void key(
160
            InstanceHandle_t&& key)
161
0
    {
162
0
        m_key = std::move(key);
163
0
    }
164
165
    RTPS_DllAPI InstanceHandle_t key() const
166
0
    {
167
0
        return m_key;
168
0
    }
169
170
    RTPS_DllAPI InstanceHandle_t& key()
171
0
    {
172
0
        return m_key;
173
0
    }
174
175
    RTPS_DllAPI void RTPSParticipantKey(
176
            const InstanceHandle_t& RTPSParticipantKey)
177
0
    {
178
0
        m_RTPSParticipantKey = RTPSParticipantKey;
179
0
    }
180
181
    RTPS_DllAPI void RTPSParticipantKey(
182
            InstanceHandle_t&& RTPSParticipantKey)
183
0
    {
184
0
        m_RTPSParticipantKey = std::move(RTPSParticipantKey);
185
0
    }
186
187
    RTPS_DllAPI InstanceHandle_t RTPSParticipantKey() const
188
0
    {
189
0
        return m_RTPSParticipantKey;
190
0
    }
191
192
    RTPS_DllAPI InstanceHandle_t& RTPSParticipantKey()
193
0
    {
194
0
        return m_RTPSParticipantKey;
195
0
    }
196
197
    RTPS_DllAPI void typeName(
198
            const string_255& typeName)
199
0
    {
200
0
        m_typeName = typeName;
201
0
    }
202
203
    RTPS_DllAPI void typeName(
204
            string_255&& typeName)
205
0
    {
206
0
        m_typeName = std::move(typeName);
207
0
    }
208
209
    RTPS_DllAPI const string_255& typeName() const
210
0
    {
211
0
        return m_typeName;
212
0
    }
213
214
    RTPS_DllAPI string_255& typeName()
215
0
    {
216
0
        return m_typeName;
217
0
    }
218
219
    RTPS_DllAPI void topicName(
220
            const string_255& topicName)
221
0
    {
222
0
        m_topicName = topicName;
223
0
    }
224
225
    RTPS_DllAPI void topicName(
226
            string_255&& topicName)
227
0
    {
228
0
        m_topicName = std::move(topicName);
229
0
    }
230
231
    RTPS_DllAPI const string_255& topicName() const
232
0
    {
233
0
        return m_topicName;
234
0
    }
235
236
    RTPS_DllAPI string_255& topicName()
237
0
    {
238
0
        return m_topicName;
239
0
    }
240
241
    RTPS_DllAPI void userDefinedId(
242
            uint16_t userDefinedId)
243
0
    {
244
0
        m_userDefinedId = userDefinedId;
245
0
    }
246
247
    RTPS_DllAPI uint16_t userDefinedId() const
248
0
    {
249
0
        return m_userDefinedId;
250
0
    }
251
252
    RTPS_DllAPI uint16_t& userDefinedId()
253
0
    {
254
0
        return m_userDefinedId;
255
0
    }
256
257
    RTPS_DllAPI void typeMaxSerialized(
258
            uint32_t typeMaxSerialized)
259
0
    {
260
0
        m_typeMaxSerialized = typeMaxSerialized;
261
0
    }
262
263
    RTPS_DllAPI uint32_t typeMaxSerialized() const
264
0
    {
265
0
        return m_typeMaxSerialized;
266
0
    }
267
268
    RTPS_DllAPI uint32_t& typeMaxSerialized()
269
0
    {
270
0
        return m_typeMaxSerialized;
271
0
    }
272
273
    RTPS_DllAPI void topicKind(
274
            TopicKind_t topicKind)
275
0
    {
276
0
        m_topicKind = topicKind;
277
0
    }
278
279
    RTPS_DllAPI TopicKind_t topicKind() const
280
0
    {
281
0
        return m_topicKind;
282
0
    }
283
284
    RTPS_DllAPI TopicKind_t& topicKind()
285
0
    {
286
0
        return m_topicKind;
287
0
    }
288
289
    RTPS_DllAPI void type_id(
290
            const TypeIdV1& other_type_id)
291
0
    {
292
0
        type_id() = other_type_id;
293
0
    }
294
295
    RTPS_DllAPI const TypeIdV1& type_id() const
296
0
    {
297
0
        assert(m_type_id != nullptr);
298
0
        return *m_type_id;
299
0
    }
300
301
    RTPS_DllAPI TypeIdV1& type_id()
302
0
    {
303
0
        if (m_type_id == nullptr)
304
0
        {
305
0
            m_type_id = new TypeIdV1();
306
0
        }
307
0
        return *m_type_id;
308
0
    }
309
310
    RTPS_DllAPI bool has_type_id() const
311
0
    {
312
0
        return m_type_id != nullptr;
313
0
    }
314
315
    RTPS_DllAPI void type(
316
            const TypeObjectV1& other_type)
317
0
    {
318
0
        type() = other_type;
319
0
    }
320
321
    RTPS_DllAPI const TypeObjectV1& type() const
322
0
    {
323
0
        assert(m_type != nullptr);
324
0
        return *m_type;
325
0
    }
326
327
    RTPS_DllAPI TypeObjectV1& type()
328
0
    {
329
0
        if (m_type == nullptr)
330
0
        {
331
0
            m_type = new TypeObjectV1();
332
0
        }
333
0
        return *m_type;
334
0
    }
335
336
    RTPS_DllAPI bool has_type() const
337
0
    {
338
0
        return m_type != nullptr;
339
0
    }
340
341
    RTPS_DllAPI void type_information(
342
            const xtypes::TypeInformation& other_type_information)
343
0
    {
344
0
        type_information() = other_type_information;
345
0
    }
346
347
    RTPS_DllAPI const xtypes::TypeInformation& type_information() const
348
0
    {
349
0
        assert(m_type_information != nullptr);
350
0
        return *m_type_information;
351
0
    }
352
353
    RTPS_DllAPI xtypes::TypeInformation& type_information()
354
0
    {
355
0
        if (m_type_information == nullptr)
356
0
        {
357
0
            m_type_information = new xtypes::TypeInformation();
358
0
        }
359
0
        return *m_type_information;
360
0
    }
361
362
    RTPS_DllAPI bool has_type_information() const
363
0
    {
364
0
        return m_type_information != nullptr;
365
0
    }
366
367
    //!WriterQOS
368
    WriterQos m_qos;
369
370
    /**
371
     * Set participant client server sample identity
372
     * @param sid valid SampleIdentity
373
     */
374
    void set_sample_identity(
375
            const SampleIdentity& sid)
376
0
    {
377
0
        fastdds::dds::set_proxy_property(sid, "PID_CLIENT_SERVER_KEY", m_properties);
378
0
    }
379
380
    /**
381
     * Retrieve participant SampleIdentity
382
     * @return SampleIdentity
383
     */
384
    SampleIdentity get_sample_identity() const
385
0
    {
386
0
        return fastdds::dds::get_proxy_property<SampleIdentity>("PID_CLIENT_SERVER_KEY", m_properties);
387
0
    }
388
389
#if HAVE_SECURITY
390
    //!EndpointSecurityInfo.endpoint_security_attributes
391
    security::EndpointSecurityAttributesMask security_attributes_;
392
393
    //!EndpointSecurityInfo.plugin_endpoint_security_attributes
394
    security::PluginEndpointSecurityAttributesMask plugin_security_attributes_;
395
#endif // if HAVE_SECURITY
396
397
    //!Clear the information and return the object to the default state.
398
    void clear();
399
400
    /**
401
     * Check if this object can be updated with the information on another object.
402
     * @param wdata WriterProxyData object to be checked.
403
     * @return true if this object can be updated with the information on wdata.
404
     */
405
    bool is_update_allowed(
406
            const WriterProxyData& wdata) const;
407
408
    /**
409
     * Update certain parameters from another object.
410
     * @param wdata pointer to object with new information.
411
     */
412
    void update(
413
            WriterProxyData* wdata);
414
415
    //!Copy all information from another object.
416
    void copy(
417
            WriterProxyData* wdata);
418
419
    /**
420
     * Get the size in bytes of the CDR serialization of this object.
421
     * @param include_encapsulation Whether to include the size of the encapsulation info.
422
     * @return size in bytes of the CDR serialization.
423
     */
424
    uint32_t get_serialized_size(
425
            bool include_encapsulation) const;
426
427
    //!Write as a parameter list on a CDRMessage_t
428
    bool writeToCDRMessage(
429
            CDRMessage_t* msg,
430
            bool write_encapsulation) const;
431
432
    //!Read a parameter list from a CDRMessage_t.
433
    RTPS_DllAPI bool readFromCDRMessage(
434
            CDRMessage_t* msg,
435
            const NetworkFactory& network,
436
            bool is_shm_transport_possible);
437
438
private:
439
440
    //!GUID
441
    GUID_t m_guid;
442
443
    //!Holds locator information
444
    RemoteLocatorList remote_locators_;
445
446
    //!GUID_t of the Writer converted to InstanceHandle_t
447
    InstanceHandle_t m_key;
448
449
    //!GUID_t of the participant converted to InstanceHandle
450
    InstanceHandle_t m_RTPSParticipantKey;
451
452
    //!Type name
453
    string_255 m_typeName;
454
455
    //!Topic name
456
    string_255 m_topicName;
457
458
    //!User defined ID
459
    uint16_t m_userDefinedId;
460
461
    //!Maximum size of the type associated with this Wrtiter, serialized.
462
    uint32_t m_typeMaxSerialized;
463
464
    //!Topic kind
465
    TopicKind_t m_topicKind;
466
467
    //!Persistence GUID
468
    GUID_t persistence_guid_;
469
470
    //!Type Identifier
471
    TypeIdV1* m_type_id;
472
473
    //!Type Object
474
    TypeObjectV1* m_type;
475
476
    //!Type Information
477
    xtypes::TypeInformation* m_type_information;
478
479
    //!
480
    ParameterPropertyList_t m_properties;
481
};
482
483
} /* namespace rtps */
484
} /* namespace fastrtps */
485
} /* namespace eprosima */
486
487
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
488
#endif // _FASTDDS_RTPS_BUILTIN_DATA_WRITERPROXYDATA_H_