Coverage Report

Created: 2026-09-14 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Fast-DDS/src/cpp/fastdds/publisher/DataWriterImpl.hpp
Line
Count
Source
1
// Copyright 2019, 2020 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 DataWriterImpl.hpp
17
 */
18
19
#ifndef _FASTDDS_DATAWRITERIMPL_HPP_
20
#define _FASTDDS_DATAWRITERIMPL_HPP_
21
22
#include <memory>
23
#include <mutex>
24
25
#include <fastdds/dds/builtin/topic/PublicationBuiltinTopicData.hpp>
26
#include <fastdds/dds/core/ReturnCode.hpp>
27
#include <fastdds/dds/core/status/BaseStatus.hpp>
28
#include <fastdds/dds/core/status/DeadlineMissedStatus.hpp>
29
#include <fastdds/dds/core/status/IncompatibleQosStatus.hpp>
30
#include <fastdds/dds/publisher/DataWriter.hpp>
31
#include <fastdds/dds/publisher/DataWriterListener.hpp>
32
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
33
#include <fastdds/dds/topic/Topic.hpp>
34
#include <fastdds/dds/topic/TypeSupport.hpp>
35
#include <fastdds/rtps/attributes/WriterAttributes.hpp>
36
#include <fastdds/rtps/common/Guid.hpp>
37
#include <fastdds/rtps/common/LocatorList.hpp>
38
#include <fastdds/rtps/common/SerializedPayload.hpp>
39
#include <fastdds/rtps/common/WriteParams.hpp>
40
#include <fastdds/rtps/history/IChangePool.hpp>
41
#include <fastdds/rtps/history/IPayloadPool.hpp>
42
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
43
#include <fastdds/rtps/writer/WriterListener.hpp>
44
45
#include <fastdds/publisher/DataWriterHistory.hpp>
46
#include <fastdds/publisher/filtering/ReaderFilterCollection.hpp>
47
#include <rtps/DataSharing/DataSharingPayloadPool.hpp>
48
#include <rtps/history/ITopicPayloadPool.h>
49
#include <rtps/history/PoolConfig.h>
50
51
namespace eprosima {
52
namespace fastdds {
53
namespace rtps {
54
55
class BaseWriter;
56
class RTPSWriter;
57
class RTPSParticipant;
58
class TimedEvent;
59
60
} // namespace rtps
61
62
#ifdef FASTDDS_STATISTICS
63
namespace statistics {
64
namespace dds {
65
class DomainParticipantImpl;
66
} // namespace dds
67
} // namespace statistics
68
#endif // FASTDDS_STATISTICS
69
70
namespace dds {
71
72
class PublisherListener;
73
class PublisherImpl;
74
class Publisher;
75
76
/**
77
 * Class DataWriterImpl, contains the actual implementation of the behaviour of the DataWriter.
78
 * @ingroup FASTDDS_MODULE
79
 */
80
class DataWriterImpl : protected rtps::IReaderDataFilter
81
{
82
    using LoanInitializationKind = DataWriter::LoanInitializationKind;
83
    using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t;
84
    using CacheChange_t = eprosima::fastdds::rtps::CacheChange_t;
85
    class LoanCollection;
86
87
protected:
88
89
    friend class PublisherImpl;
90
91
#ifdef FASTDDS_STATISTICS
92
    friend class eprosima::fastdds::statistics::dds::DomainParticipantImpl;
93
#endif // FASTDDS_STATISTICS
94
95
    /**
96
     * Create a data writer, assigning its pointer to the associated writer.
97
     * Don't use directly, create Publisher using DomainRTPSParticipant static function.
98
     */
99
    DataWriterImpl(
100
            PublisherImpl* p,
101
            TypeSupport type,
102
            Topic* topic,
103
            const DataWriterQos& qos,
104
            DataWriterListener* listener = nullptr,
105
            std::shared_ptr<fastdds::rtps::IPayloadPool> payload_pool = nullptr);
106
107
    DataWriterImpl(
108
            PublisherImpl* p,
109
            TypeSupport type,
110
            Topic* topic,
111
            const DataWriterQos& qos,
112
            const fastdds::rtps::EntityId_t& entity_id,
113
            DataWriterListener* listener = nullptr);
114
115
public:
116
117
    virtual ~DataWriterImpl();
118
119
    /**
120
     * Enable this object.
121
     * The required lower layer entities will be created.
122
     *
123
     * @pre This method has not previously returned RETCODE_OK
124
     *
125
     * @return RETCODE_OK if all the lower layer entities have been correctly created.
126
     * @return Other standard return codes on error.
127
     */
128
    virtual ReturnCode_t enable();
129
130
    /**
131
     * Check if the preconditions to delete this object are met.
132
     *
133
     * @return RETCODE_PRECONDITION_NOT_MET if the preconditions to delete this object are not met.
134
     * @return RETCODE_OK if it is safe to delete this object.
135
     */
136
    ReturnCode_t check_delete_preconditions();
137
138
    /**
139
     * Get a pointer to the internal pool where the user could directly write.
140
     *
141
     * @param [out] sample          Pointer to the sample on the internal pool.
142
     * @param [in]  initialization  How to initialize the loaned sample.
143
     *
144
     * @return RETCODE_ILLEGAL_OPERATION when the type does not support loans.
145
     * @return RETCODE_OUT_OF_RESOURCES if the pool has been exhausted.
146
     * @return RETCODE_OK if a pointer to a sample is successfully obtained.
147
     */
148
    ReturnCode_t loan_sample(
149
            void*& sample,
150
            LoanInitializationKind initialization);
151
152
    /**
153
     * Discards a loaned sample pointer.
154
     *
155
     * @param [in,out] sample  Pointer to the previously loaned sample.
156
     *
157
     * @return RETCODE_ILLEGAL_OPERATION when the type does not support loans.
158
     * @return RETCODE_BAD_PARAMETER if the pointer does not correspond to a loaned sample.
159
     * @return RETCODE_OK if the loan is successfully discarded.
160
     */
161
    ReturnCode_t discard_loan(
162
            void*& sample);
163
164
    /**
165
     * Write data to the topic.
166
     *
167
     * @param data Pointer to the data.
168
     *
169
     * @return any of the standard return codes.
170
     */
171
    ReturnCode_t write(
172
            const void* const data);
173
174
    /**
175
     * Write data with params to the topic.
176
     *
177
     * @param data Pointer to the data.
178
     * @param params Extra write parameters.
179
     *
180
     * @return any of the standard return codes.
181
     */
182
    ReturnCode_t write(
183
            const void* const data,
184
            fastdds::rtps::WriteParams& params);
185
186
    /**
187
     * @brief Implementation of the DDS `write` operation.
188
     *
189
     * @param [in] data    Pointer to the data to publish.
190
     * @param [in] handle  Handle of the instance to update. The special value @c HANDLE_NIL can be used to indicate
191
     *                    that the instance should be automatically calculated.
192
     *
193
     * @return any of the standard return codes.
194
     */
195
    ReturnCode_t write(
196
            const void* const data,
197
            const InstanceHandle_t& handle);
198
199
    /**
200
     * @brief Implementation of the DDS `write_w_timestamp` operation.
201
     *
202
     * @param [in] data        Pointer to the data to publish.
203
     * @param [in] handle      Handle of the instance to update. The special value @c HANDLE_NIL can be used to indicate
204
     *                        that the instance should be automatically calculated.
205
     * @param [in] timestamp   Timestamp to associate to the sample info of the published data.
206
     *
207
     * @return any of the standard return codes.
208
     */
209
    ReturnCode_t write_w_timestamp(
210
            const void* const data,
211
            const InstanceHandle_t& handle,
212
            const fastdds::dds::Time_t& timestamp);
213
214
    /**
215
     * @brief Implementation of the DDS `register_instance` operation.
216
     * It deduces the instance's key and tries to get resources in the DataWriterHistory.
217
     *
218
     * @param [in] instance Sample used to get the instance's key.
219
     *
220
     * @return Handle containing the instance's key.
221
     * This handle could be used in successive `write` or `dispose` operations.
222
     * In case of error, HANDLE_NIL will be returned.
223
     */
224
    InstanceHandle_t register_instance(
225
            const void* const instance);
226
227
    /**
228
     * @brief Implementation of the DDS `register_instance_w_timestamp` operation.
229
     * It deduces the instance's key and tries to get resources in the DataWriterHistory.
230
     *
231
     * @param [in] instance Sample used to get the instance's key.
232
     * @param [in] timestamp Timestamp to set on the instance registration operation.
233
     *
234
     * @return Handle containing the instance's key.
235
     * This handle could be used in successive `write` or `dispose` operations.
236
     * In case of error, HANDLE_NIL will be returned.
237
     */
238
    InstanceHandle_t register_instance_w_timestamp(
239
            const void* const instance,
240
            const fastdds::dds::Time_t& timestamp);
241
242
    /**
243
     * @brief Implementation of the DDS `unregister_instance` and `dispose` operations.
244
     * It sends a CacheChange_t with a kind that depends on the `dispose` parameter and
245
     * `writer_data_lifecycle` QoS.
246
     *
247
     * @param [in] instance  Sample used to deduce instance's key in case of `handle` parameter is HANDLE_NIL.
248
     * @param [in] handle    Instance's key to be unregistered or disposed.
249
     * @param [in] dispose   If `dispose` is `false`, a CacheChange_t with kind set to NOT_ALIVE_UNREGISTERED is sent,
250
     *                      or if `writer_data_lifecycle.autodispose_unregistered_instances` is `true` then it is sent
251
     *                      with kind set to NOT_ALIVE_DISPOSED_UNREGISTERED.
252
     *                      If `dispose` is `true`, a CacheChange_t with kind set to NOT_ALIVE_DISPOSED is sent.
253
     *
254
     * @return Returns the operation's result.
255
     * If the operation finishes successfully, RETCODE_OK is returned.
256
     */
257
    ReturnCode_t unregister_instance(
258
            const void* const instance,
259
            const InstanceHandle_t& handle,
260
            bool dispose = false);
261
262
    /**
263
     * @brief Implementation of the DDS `unregister_instance_w_timestamp` and `dispose_w_timestamp` operations.
264
     * It sends a CacheChange_t with a kind that depends on the `dispose` parameter and
265
     * `writer_data_lifecycle` QoS.
266
     *
267
     * @param [in] instance  Sample used to deduce instance's key in case of `handle` parameter is HANDLE_NIL.
268
     * @param [in] handle    Instance's key to be unregistered or disposed.
269
     * @param [in] timestamp Source timestamp to set on the CacheChange_t being sent.
270
     * @param [in] dispose   If `dispose` is `false`, a CacheChange_t with kind set to NOT_ALIVE_UNREGISTERED is sent,
271
     *                      or if `writer_data_lifecycle.autodispose_unregistered_instances` is `true` then it is sent
272
     *                      with kind set to NOT_ALIVE_DISPOSED_UNREGISTERED.
273
     *                      If `dispose` is `true`, a CacheChange_t with kind set to NOT_ALIVE_DISPOSED is sent.
274
     *
275
     * @return Returns the operation's result.
276
     * If the operation finishes successfully, RETCODE_OK is returned.
277
     */
278
    ReturnCode_t unregister_instance_w_timestamp(
279
            const void* const instance,
280
            const InstanceHandle_t& handle,
281
            const fastdds::dds::Time_t& timestamp,
282
            bool dispose = false);
283
284
    /**
285
     *
286
     * @return
287
     */
288
    const fastdds::rtps::GUID_t& guid() const;
289
290
    InstanceHandle_t get_instance_handle() const;
291
292
    /**
293
     * Get topic data type
294
     * @return Topic data type
295
     */
296
    TypeSupport get_type() const
297
0
    {
298
0
        return type_;
299
0
    }
300
301
    ReturnCode_t wait_for_acknowledgments(
302
            const fastdds::dds::Duration_t& max_wait);
303
304
    ReturnCode_t wait_for_acknowledgments(
305
            const void* const instance,
306
            const InstanceHandle_t& handle,
307
            const fastdds::dds::Duration_t& max_wait);
308
309
    ReturnCode_t get_publication_matched_status(
310
            PublicationMatchedStatus& status);
311
312
    ReturnCode_t get_offered_deadline_missed_status(
313
            OfferedDeadlineMissedStatus& status);
314
315
    ReturnCode_t get_offered_incompatible_qos_status(
316
            OfferedIncompatibleQosStatus& status);
317
318
    ReturnCode_t set_qos(
319
            const DataWriterQos& qos);
320
321
    const DataWriterQos& get_qos() const;
322
323
    ReturnCode_t get_qos(
324
            DataWriterQos& qos) const;
325
326
    Topic* get_topic() const;
327
328
    const DataWriterListener* get_listener() const;
329
330
    ReturnCode_t set_listener(
331
            DataWriterListener* listener);
332
333
    /**
334
     * This operation can be used to retrieve the instance key that corresponds to an
335
     * @ref eprosima::fastdds::dds::Entity::instance_handle_ "instance_handle".
336
     * The operation will only fill the fields that form the key inside the key_holder instance.
337
     *
338
     * This operation may return BAD_PARAMETER if the InstanceHandle_t handle does not correspond to an existing
339
     * data-object known to the DataWriter. If the implementation is not able to check invalid handles then the result
340
     * in this situation is unspecified.
341
     *
342
     * @param [in,out] key_holder  Sample where the key fields will be returned.
343
     * @param [in] handle          Handle to the instance to retrieve the key values from.
344
     *
345
     * @return Any of the standard return codes.
346
     */
347
    ReturnCode_t get_key_value(
348
            void* key_holder,
349
            const InstanceHandle_t& handle);
350
351
    ReturnCode_t get_liveliness_lost_status(
352
            LivelinessLostStatus& status);
353
354
    const Publisher* get_publisher() const;
355
356
    ReturnCode_t assert_liveliness();
357
358
    //! Remove all listeners in the hierarchy to allow a quiet destruction
359
    virtual void disable();
360
361
    /**
362
     * Removes all changes from the History.
363
     * @param [out] removed Number of removed elements
364
     * @return RETCODE_OK if correct, RETCODE_ERROR if not.
365
     */
366
    ReturnCode_t clear_history(
367
            size_t* removed);
368
369
    /**
370
     * @brief Get the list of locators from which this DataWriter may send data.
371
     *
372
     * @param [out] locators  LocatorList where the list of locators will be stored.
373
     *
374
     * @return NOT_ENABLED if the reader has not been enabled.
375
     * @return OK if a list of locators is returned.
376
     */
377
    ReturnCode_t get_sending_locators(
378
            rtps::LocatorList& locators) const;
379
380
    /**
381
     * Called from the DomainParticipant when a filter factory is being unregistered.
382
     *
383
     * @param filter_class_name  The class name under which the factory was registered.
384
     */
385
    void filter_is_being_removed(
386
            const char* filter_class_name);
387
388
    /**
389
     * @brief Retrieves in a subscription associated with the @ref DataWriter
390
     *
391
     * @param[out] subscription_data subscription data struct
392
     * @param subscription_handle @ref InstanceHandle_t of the subscription
393
     * @return @ref RETCODE_BAD_PARAMETER if the DataWriter is not matched with
394
     * the given subscription handle, @ref RETCODE_OK otherwise.
395
     *
396
     */
397
    ReturnCode_t get_matched_subscription_data(
398
            SubscriptionBuiltinTopicData& subscription_data,
399
            const InstanceHandle_t& subscription_handle) const;
400
401
    /**
402
     * @brief Fills the given vector with the @ref InstanceHandle_t of matched DataReaders
403
     *
404
     * @param[out] subscription_handles Vector where the @ref InstanceHandle_t are returned
405
     * @return @ref RETCODE_OK if the operation succeeds.
406
     *
407
     * @note Returning an empty list is not an error, it returns @ref RETCODE_OK.
408
     *
409
     */
410
    ReturnCode_t get_matched_subscriptions(
411
            std::vector<InstanceHandle_t>& subscription_handles) const;
412
413
    /**
414
     * Retrieve the publication data discovery information.
415
     *
416
     * @param [out] publication_data The publication data discovery information.
417
     *
418
     * @return NOT_ENABLED if the writer has not been enabled.
419
     * @return OK if the publication data is returned.
420
     */
421
    ReturnCode_t get_publication_builtin_topic_data(
422
            PublicationBuiltinTopicData& publication_data) const;
423
424
    /**
425
     *  @brief Set a sample prefilter to be used. This filter is always
426
     *  evaluated before sending the sample to any DataReader and prior to
427
     *  any content filtering.
428
     *  Passing a nullptr disables prefiltering.
429
     *
430
     * @param prefilter The prefilter to be set.
431
     *
432
     * @return RETCODE_OK if the prefilter is set correctly.
433
     *
434
     * @note Prefiltering is currently incompatible with DataSharing.
435
     */
436
    ReturnCode_t set_sample_prefilter(
437
            std::shared_ptr<IContentFilter> prefilter);
438
439
    /**
440
     * This operation sets the key of the DataReader that is related to this DataWriter.
441
     * This is used to establish a relationship between a DataReader and a DataWriter
442
     * in the context of RPC over DDS.
443
     *
444
     * @warning This operation is only valid if the entity is not enabled.
445
     *
446
     * @param [in] related_reader Pointer to the DataReader to set as related.
447
     *
448
     * @return RETCODE_OK if the key is set successfully.
449
     * @return RETCODE_ILLEGAL_OPERATION if this entity is enabled.
450
     * @return RETCODE_PRECONDITION_NOT_MET if the entity does not belong to the same participant.
451
     * @return RETCODE_BAD_PARAMETER if the provided GUID is unknown
452
     * @return RETCODE_UNSUPPORTED if the implementation does not support RPC over DDS
453
     * or the pointer is not valid.
454
     */
455
    ReturnCode_t set_related_datareader(
456
            const DataReader* related_reader);
457
458
    /**
459
     * @brief Set the type support context to be used when serializing data for this DataWriter.
460
     *
461
     * @param context Shared pointer to the type support context to be used for serialization.
462
     *
463
     * @pre The DataWriter must not be enabled.
464
     */
465
    void set_type_support_context(
466
            const std::shared_ptr<TopicDataType::Context>& context);
467
468
protected:
469
470
    using IChangePool = eprosima::fastdds::rtps::IChangePool;
471
    using IPayloadPool = eprosima::fastdds::rtps::IPayloadPool;
472
    using ITopicPayloadPool = eprosima::fastdds::rtps::ITopicPayloadPool;
473
474
    PublisherImpl* publisher_ = nullptr;
475
476
    //! Pointer to the associated RTPS Writer.
477
    fastdds::rtps::BaseWriter* writer_ = nullptr;
478
479
    //! Pointer to the TopicDataType object.
480
    TypeSupport type_;
481
482
    Topic* topic_ = nullptr;
483
484
    DataWriterQos qos_;
485
486
    //! Mutex to protect qos_
487
    mutable std::mutex qos_mutex_;
488
489
    //! DataWriterListener
490
    DataWriterListener* listener_ = nullptr;
491
492
    //! Mutex to protect listener_
493
    std::mutex listener_mutex_;
494
495
    //!History
496
    std::unique_ptr<DataWriterHistory> history_;
497
498
    //!Listener to capture the events of the Writer
499
    class InnerDataWriterListener : public fastdds::rtps::WriterListener
500
    {
501
    public:
502
503
        InnerDataWriterListener(
504
                DataWriterImpl* w)
505
0
            : data_writer_(w)
506
0
        {
507
0
        }
508
509
        virtual ~InnerDataWriterListener() override
510
0
        {
511
0
        }
512
513
        void on_writer_matched(
514
                fastdds::rtps::RTPSWriter* writer,
515
                const fastdds::rtps::MatchingInfo& info) override;
516
517
        void on_offered_incompatible_qos(
518
                fastdds::rtps::RTPSWriter* writer,
519
                fastdds::dds::PolicyMask qos) override;
520
521
        void on_writer_change_received_by_all(
522
                fastdds::rtps::RTPSWriter* writer,
523
                fastdds::rtps::CacheChange_t* change) override;
524
525
        void on_liveliness_lost(
526
                fastdds::rtps::RTPSWriter* writer,
527
                const LivelinessLostStatus& status) override;
528
529
        void on_reader_discovery(
530
                fastdds::rtps::RTPSWriter* writer,
531
                fastdds::rtps::ReaderDiscoveryStatus reason,
532
                const fastdds::rtps::GUID_t& reader_guid,
533
                const fastdds::rtps::SubscriptionBuiltinTopicData* reader_info) override;
534
535
#ifdef FASTDDS_STATISTICS
536
        void notify_status_observer(
537
                const uint32_t& status_id);
538
#endif //FASTDDS_STATISTICS
539
540
    private:
541
542
        DataWriterImpl* data_writer_;
543
        std::mutex matching_info_mutex_;
544
    }
545
    writer_listener_;
546
547
    //! A timer used to check for deadlines
548
    fastdds::rtps::TimedEvent* deadline_timer_ = nullptr;
549
550
    //! Deadline duration in microseconds
551
    std::chrono::duration<double, std::ratio<1, 1000000>> deadline_duration_us_;
552
553
    //! The current timer owner, i.e. the instance which started the deadline timer
554
    InstanceHandle_t timer_owner_;
555
556
    //! The publication matched status
557
    PublicationMatchedStatus publication_matched_status_;
558
559
    //! The offered deadline missed status
560
    OfferedDeadlineMissedStatus deadline_missed_status_;
561
562
    //! The liveliness lost status
563
    LivelinessLostStatus liveliness_lost_status_;
564
565
    //! The offered incompatible qos status
566
    OfferedIncompatibleQosStatus offered_incompatible_qos_status_;
567
568
    //! A timed callback to remove expired samples for lifespan QoS
569
    fastdds::rtps::TimedEvent* lifespan_timer_ = nullptr;
570
571
    //! The lifespan duration, in microseconds
572
    std::chrono::duration<double, std::ratio<1, 1000000>> lifespan_duration_us_;
573
574
    DataWriter* user_datawriter_ = nullptr;
575
576
    bool is_data_sharing_compatible_ = false;
577
578
    uint32_t fixed_payload_size_ = 0u;
579
580
    rtps::PoolConfig pool_config_ {};
581
582
    std::shared_ptr<IPayloadPool> payload_pool_;
583
584
    bool is_custom_payload_pool_ = false;
585
586
    std::unique_ptr<LoanCollection> loans_;
587
588
    fastdds::rtps::GUID_t guid_;
589
590
    std::unique_ptr<ReaderFilterCollection> reader_filters_;
591
592
    DataRepresentationId_t data_representation_ {DEFAULT_DATA_REPRESENTATION};
593
594
    mutable std::mutex filters_mtx_;
595
    std::shared_ptr<IContentFilter> sample_prefilter_;
596
597
    std::shared_ptr<TopicDataType::Context> type_support_context_ {};
598
599
    ReturnCode_t check_write_preconditions(
600
            const void* const data,
601
            const InstanceHandle_t& handle,
602
            InstanceHandle_t& instance_handle);
603
604
    ReturnCode_t check_instance_preconditions(
605
            const void* const data,
606
            const InstanceHandle_t& handle,
607
            InstanceHandle_t& instance_handle);
608
609
    InstanceHandle_t do_register_instance(
610
            const void* const key,
611
            const InstanceHandle_t instance_handle,
612
            fastdds::rtps::WriteParams& wparams);
613
614
    /**
615
     *
616
     * @param kind
617
     * @param  data
618
     * @return
619
     */
620
    ReturnCode_t create_new_change(
621
            fastdds::rtps::ChangeKind_t kind,
622
            const void* const data);
623
624
    /**
625
     *
626
     * @param kind
627
     * @param  data
628
     * @param wparams
629
     * @return
630
     */
631
    ReturnCode_t create_new_change_with_params(
632
            fastdds::rtps::ChangeKind_t kind,
633
            const void* const data,
634
            fastdds::rtps::WriteParams& wparams);
635
636
    /**
637
     *
638
     * @param kind
639
     * @param  data
640
     * @param wparams
641
     * @param handle
642
     * @return
643
     */
644
    ReturnCode_t create_new_change_with_params(
645
            fastdds::rtps::ChangeKind_t kind,
646
            const void* const data,
647
            fastdds::rtps::WriteParams& wparams,
648
            const InstanceHandle_t& handle);
649
650
    /**
651
     * Removes the cache change with the minimum sequence number
652
     * @return True if correct.
653
     */
654
    bool remove_min_seq_change();
655
656
    void update_publication_matched_status(
657
            const fastdds::rtps::MatchingInfo& status);
658
659
    /**
660
     * @brief A method called when an instance misses the deadline
661
     */
662
    bool deadline_missed();
663
664
    /**
665
     * @brief A method to reschedule the deadline timer
666
     * @return true if deadline rescheduling succeeded, false otherwise
667
     */
668
    bool deadline_timer_reschedule();
669
670
    /**
671
     * @brief A method to remove expired samples, invoked when the lifespan timer expires
672
     */
673
    bool lifespan_expired();
674
675
    ReturnCode_t check_new_change_preconditions(
676
            fastdds::rtps::ChangeKind_t change_kind,
677
            const void* const data);
678
679
    ReturnCode_t perform_create_new_change(
680
            fastdds::rtps::ChangeKind_t change_kind,
681
            const void* const data,
682
            fastdds::rtps::WriteParams& wparams,
683
            const InstanceHandle_t& handle);
684
685
    static void set_qos(
686
            DataWriterQos& to,
687
            const DataWriterQos& from,
688
            bool update_immutable);
689
690
    /**
691
     * Extends the check_qos() call, including the check for
692
     * resource limits policy.
693
     * @param qos Pointer to the qos to be checked.
694
     * @param type Pointer to the associated TypeSupport object.
695
     * @return True if correct.
696
     */
697
    static ReturnCode_t check_qos_including_resource_limits(
698
            const DataWriterQos& qos,
699
            const TypeSupport& type);
700
701
    /**
702
     * Checks the consistency of the qos configuration.
703
     * @param qos Pointer to the qos to be checked.
704
     * @return True if correct.
705
     */
706
    static ReturnCode_t check_qos(
707
            const DataWriterQos& qos);
708
709
    /**
710
     * Checks resource limits policy: Instance allocation consistency
711
     * @param qos Pointer to the qos to be checked.
712
     * @return True if correct.
713
     */
714
    static ReturnCode_t check_allocation_consistency(
715
            const DataWriterQos& qos);
716
717
    static bool can_qos_be_updated(
718
            const DataWriterQos& to,
719
            const DataWriterQos& from);
720
721
    void publisher_qos_updated();
722
723
    OfferedIncompatibleQosStatus& update_offered_incompatible_qos(
724
            PolicyMask incompatible_policies);
725
726
    /*!
727
     * @brief Updates liveliness lost status.
728
     *
729
     * @param [in] liveliness_lost_status Liveliness lost status coming from RTPS layer.
730
     * @return Current liveliness lost status.
731
     */
732
    LivelinessLostStatus& update_liveliness_lost_status(
733
            const LivelinessLostStatus& liveliness_lost_status);
734
735
    /**
736
     * Returns the most appropriate listener to handle the callback for the given status,
737
     * or nullptr if there is no appropriate listener.
738
     */
739
    DataWriterListener* get_listener_for(
740
            const StatusMask& status);
741
742
    void set_fragment_size_on_change(
743
            fastdds::rtps::WriteParams& wparams,
744
            fastdds::rtps::CacheChange_t* ch,
745
            const uint32_t& high_mark_for_frag);
746
747
    std::shared_ptr<IChangePool> get_change_pool() const;
748
749
    std::shared_ptr<IPayloadPool> get_payload_pool();
750
751
    bool release_payload_pool();
752
753
    ReturnCode_t check_datasharing_compatible(
754
            const fastdds::rtps::WriterAttributes& writer_attributes,
755
            bool& is_datasharing_compatible) const;
756
757
    bool get_free_payload_from_pool(
758
            uint32_t size,
759
            SerializedPayload_t& payload);
760
761
    bool add_loan(
762
            const void* const data,
763
            SerializedPayload_t& payload);
764
765
    bool check_and_remove_loan(
766
            const void* const data,
767
            SerializedPayload_t& payload);
768
769
    /**
770
     * Remove internal filtering information about a reader.
771
     * Called whenever a non-intra-process reader is unmatched.
772
     *
773
     * @param reader_guid  GUID of the reader that has been unmatched.
774
     */
775
    void remove_reader_filter(
776
            const fastdds::rtps::GUID_t& reader_guid);
777
778
    /**
779
     * Process filtering information for a reader.
780
     * Called when a new reader is matched, and whenever the discovery information of a matched reader changes.
781
     *
782
     * @param reader_guid  The GUID of the reader for which the discovery information changed.
783
     * @param reader_info  The reader's discovery information.
784
     */
785
    void process_reader_filter_info(
786
            const fastdds::rtps::GUID_t& reader_guid,
787
            const fastdds::rtps::SubscriptionBuiltinTopicData& reader_info);
788
789
    bool is_relevant(
790
            const fastdds::rtps::CacheChange_t& change,
791
            const fastdds::rtps::GUID_t& reader_guid) const override;
792
793
private:
794
795
    /**
796
     * (Re)configures the deadline timer:
797
     *  In case of infinite deadline period cancel it, for 0 warn and notify once (with max counts), and
798
     *  for non-infinite positive values store period.
799
     */
800
    void configure_deadline_timer_();
801
802
    /**
803
     * Notifies listeners that a deadline has been missed.
804
     */
805
    void notify_deadline_missed_nts_();
806
807
    void create_history(
808
            const std::shared_ptr<IPayloadPool>& payload_pool,
809
            const std::shared_ptr<IChangePool>& change_pool);
810
811
    DataWriterQos get_datawriter_qos_from_settings(
812
            const DataWriterQos& qos);
813
814
};
815
816
} /* namespace dds */
817
} /* namespace fastdds */
818
} /* namespace eprosima */
819
820
#endif //_FASTDDS_DATAWRITERIMPL_HPP_