Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/src/cpp/rtps/transport/TCPSenderResource.hpp
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
#ifndef __TRANSPORT_TCPSENDERRESOURCE_HPP__
16
#define __TRANSPORT_TCPSENDERRESOURCE_HPP__
17
18
#include <fastdds/rtps/common/LocatorsIterator.hpp>
19
#include <fastdds/rtps/transport/SenderResource.hpp>
20
21
#include <rtps/transport/ChainingSenderResource.hpp>
22
#include <rtps/transport/TCPChannelResource.h>
23
#include <rtps/transport/TCPTransportInterface.h>
24
25
namespace eprosima {
26
namespace fastdds {
27
namespace rtps {
28
29
class TCPSenderResource : public SenderResource
30
{
31
public:
32
33
    TCPSenderResource(
34
            TCPTransportInterface& transport,
35
            Locator_t& locator)
36
0
        : SenderResource(transport.kind())
37
0
        , locator_(locator)
38
0
    {
39
        // Implementation functions are bound to the right transport parameters
40
0
        clean_up = [this, &transport]()
41
0
                {
42
0
                    transport.SenderResourceHasBeenClosed(locator_);
43
0
                };
44
45
0
        send_buffers_lambda_ = [this, &transport](
46
0
            const std::vector<NetworkBuffer>& buffers,
47
0
            uint32_t total_bytes,
48
0
            LocatorsIterator* destination_locators_begin,
49
0
            LocatorsIterator* destination_locators_end,
50
0
            const std::chrono::steady_clock::time_point&) -> bool
51
0
                {
52
0
                    return transport.send(buffers, total_bytes, locator_, destination_locators_begin,
53
0
                                   destination_locators_end);
54
0
                };
55
0
    }
56
57
    virtual ~TCPSenderResource()
58
0
    {
59
0
        if (clean_up)
60
0
        {
61
0
            clean_up();
62
0
        }
63
0
    }
64
65
    Locator_t& locator()
66
0
    {
67
0
        return locator_;
68
0
    }
69
70
    static TCPSenderResource* cast(
71
            const TransportInterface& transport,
72
            SenderResource* sender_resource)
73
0
    {
74
0
        TCPSenderResource* returned_resource = nullptr;
75
76
0
        if (sender_resource->kind() == transport.kind())
77
0
        {
78
0
            returned_resource = dynamic_cast<TCPSenderResource*>(sender_resource);
79
80
            //! May be chained
81
0
            if (!returned_resource)
82
0
            {
83
0
                auto chaining_sender = dynamic_cast<ChainingSenderResource*>(sender_resource);
84
85
0
                if (chaining_sender)
86
0
                {
87
0
                    returned_resource = dynamic_cast<TCPSenderResource*>(chaining_sender->lower_sender_cast());
88
0
                }
89
0
            }
90
0
        }
91
92
0
        return returned_resource;
93
0
    }
94
95
private:
96
97
    TCPSenderResource() = delete;
98
99
    TCPSenderResource(
100
            const SenderResource&) = delete;
101
102
    TCPSenderResource& operator =(
103
            const SenderResource&) = delete;
104
105
    Locator_t locator_;
106
};
107
108
} // namespace rtps
109
} // namespace fastdds
110
} // namespace eprosima
111
112
#endif // __TRANSPORT_UDPSENDERRESOURCE_HPP__