Coverage Report

Created: 2025-07-03 06:58

/src/Fast-DDS/src/cpp/rtps/transport/ChainingSenderResource.hpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2021 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
#ifndef _RTPS_TRANSPORT_CHAININGSENDERRESOURCE_HPP_
16
#define _RTPS_TRANSPORT_CHAININGSENDERRESOURCE_HPP_
17
18
#include <fastdds/rtps/transport/ChainingTransport.hpp>
19
#include <fastdds/rtps/transport/SenderResource.hpp>
20
21
namespace eprosima {
22
namespace fastdds {
23
namespace rtps {
24
25
class ChainingSenderResource : public SenderResource
26
{
27
public:
28
29
    ChainingSenderResource(
30
            ChainingTransport& transport,
31
            std::unique_ptr<SenderResource>& low_sender_resource)
32
        : SenderResource(transport.kind())
33
        , low_sender_resource_(std::move(low_sender_resource))
34
0
    {
35
0
        // Implementation functions are bound to the right transport parameters
36
0
        clean_up = []()
37
0
                {
38
0
                    // No cleanup is required.
39
0
                    // low_sender_resources_ makes its clean up on destruction.
40
0
                };
41
0
42
0
        send_buffers_lambda_ = [this, &transport](
43
0
            const std::vector<NetworkBuffer>& buffers,
44
0
            uint32_t total_bytes,
45
0
            LocatorsIterator* destination_locators_begin,
46
0
            LocatorsIterator* destination_locators_end,
47
0
            const std::chrono::steady_clock::time_point& timeout) -> bool
48
0
                {
49
0
                    if (low_sender_resource_)
50
0
                    {
51
0
                        return transport.send(low_sender_resource_.get(), buffers, total_bytes,
52
0
                                       destination_locators_begin, destination_locators_end, timeout);
53
0
                    }
54
0
55
0
                    return false;
56
0
                };
57
0
    }
58
59
    SenderResource* lower_sender_cast()
60
0
    {
61
0
        SenderResource* lower_sender_cast = nullptr;
62
63
0
        if (low_sender_resource_)
64
0
        {
65
0
            lower_sender_cast = static_cast<SenderResource*>(low_sender_resource_.get());
66
0
        }
67
68
0
        return lower_sender_cast;
69
0
    }
70
71
    virtual ~ChainingSenderResource()
72
0
    {
73
0
        if (clean_up)
74
0
        {
75
0
            clean_up();
76
0
        }
77
0
    }
78
79
private:
80
81
    ChainingSenderResource() = delete;
82
83
    ChainingSenderResource(
84
            const SenderResource&) = delete;
85
86
    ChainingSenderResource& operator =(
87
            const SenderResource&) = delete;
88
89
    std::unique_ptr<SenderResource> low_sender_resource_;
90
};
91
92
} // namespace rtps
93
} // namespace fastdds
94
} // namespace eprosima
95
96
#endif // _RTPS_TRANSPORT_CHAININGSENDERRESOURCE_HPP_