Coverage Report

Created: 2026-02-14 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Fast-DDS/include/fastdds/rtps/transport/SenderResource.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 SenderResource.hpp
17
 *
18
 */
19
20
#ifndef FASTDDS_RTPS_TRANSPORT__SENDERRESOURCE_HPP
21
#define FASTDDS_RTPS_TRANSPORT__SENDERRESOURCE_HPP
22
23
#include <fastdds/rtps/common/Types.hpp>
24
25
#include <functional>
26
#include <vector>
27
#include <list>
28
#include <chrono>
29
30
#include <fastdds/rtps/common/LocatorList.hpp>
31
#include <fastdds/rtps/common/LocatorsIterator.hpp>
32
#include <fastdds/rtps/transport/NetworkBuffer.hpp>
33
34
namespace eprosima {
35
namespace fastdds {
36
namespace rtps {
37
38
class RTPSParticipantImpl;
39
class MessageReceiver;
40
41
/**
42
 * RAII object that encapsulates the Send operation over one chanel in an unknown transport.
43
 * A Sender resource is always univocally associated to a transport channel; the
44
 * act of constructing a Sender Resource opens the channel and its destruction
45
 * closes it.
46
 * @ingroup NETWORK_MODULE
47
 */
48
class SenderResource
49
{
50
public:
51
52
    using NetworkBuffer = eprosima::fastdds::rtps::NetworkBuffer;
53
54
    FASTDDS_DEPRECATED_UNTIL(4, send, "Use send with transport_priority instead")
55
    bool send(
56
            const std::vector<NetworkBuffer>& buffers,
57
            const uint32_t& total_bytes,
58
            LocatorsIterator* destination_locators_begin,
59
            LocatorsIterator* destination_locators_end,
60
            const std::chrono::steady_clock::time_point& max_blocking_time_point)
61
0
    {
62
0
        return send(buffers, total_bytes, destination_locators_begin, destination_locators_end,
63
0
                       max_blocking_time_point, 0);
64
0
    }
65
66
    /**
67
     * Sends to a destination locator, through the channel managed by this resource.
68
     * @param buffers Vector of buffers to send.
69
     * @param total_bytes Length of all buffers to be sent. Will be used as a boundary for
70
     * the previous parameter.
71
     * @param destination_locators_begin destination endpoint Locators iterator begin.
72
     * @param destination_locators_end destination endpoint Locators iterator end.
73
     * @param max_blocking_time_point If transport supports it then it will use it as maximum blocking time.
74
     * @param transport_priority Transport priority to be used for the send operation.
75
     * @return Success of the send operation.
76
     */
77
    bool send(
78
            const std::vector<NetworkBuffer>& buffers,
79
            const uint32_t& total_bytes,
80
            LocatorsIterator* destination_locators_begin,
81
            LocatorsIterator* destination_locators_end,
82
            const std::chrono::steady_clock::time_point& max_blocking_time_point,
83
            int32_t transport_priority)
84
0
    {
85
0
        if (send_lambda_)
86
0
        {
87
0
            return send_lambda_(buffers, total_bytes, destination_locators_begin, destination_locators_end,
88
0
                           max_blocking_time_point, transport_priority);
89
0
        }
90
0
        return send_buffers_lambda_(buffers, total_bytes, destination_locators_begin, destination_locators_end,
91
0
                       max_blocking_time_point);
92
0
    }
93
94
    /**
95
     * Resources can only be transfered through move semantics. Copy, assignment, and
96
     * construction outside of the factory are forbidden.
97
     */
98
    SenderResource(
99
            SenderResource&& rValueResource) = default;
100
101
0
    virtual ~SenderResource() = default;
102
103
    int32_t kind() const
104
0
    {
105
0
        return transport_kind_;
106
0
    }
107
108
    /**
109
     * Add locators representing the local endpoints managed by this sender resource.
110
     *
111
     * @param [in,out] locators  List where locators will be added.
112
     */
113
    virtual void add_locators_to_list(
114
            LocatorList_t& locators) const
115
0
    {
116
0
        (void)locators;
117
0
    }
118
119
protected:
120
121
    SenderResource(
122
            int32_t transport_kind)
123
0
        : transport_kind_(transport_kind)
124
0
    {
125
0
    }
126
127
    int32_t transport_kind_;
128
129
    std::function<void()> clean_up;
130
131
    std::function<bool(
132
                const std::vector<NetworkBuffer>&,
133
                uint32_t,
134
                LocatorsIterator* destination_locators_begin,
135
                LocatorsIterator* destination_locators_end,
136
                const std::chrono::steady_clock::time_point&)> send_buffers_lambda_;
137
138
    std::function<bool(
139
                const std::vector<NetworkBuffer>&,
140
                uint32_t,
141
                LocatorsIterator* destination_locators_begin,
142
                LocatorsIterator* destination_locators_end,
143
                const std::chrono::steady_clock::time_point&,
144
                int32_t transport_priority)> send_lambda_;
145
146
private:
147
148
    SenderResource()                                 = delete;
149
    SenderResource(
150
            const SenderResource&)            = delete;
151
    SenderResource& operator =(
152
            const SenderResource&) = delete;
153
};
154
155
} // namespace rtps
156
} // namespace fastdds
157
} // namespace eprosima
158
159
#endif // FASTDDS_RTPS_TRANSPORT__SENDERRESOURCE_HPP