/src/Fast-DDS/include/fastdds/rtps/transport/SenderResource.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 | | /** |
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 | | /** |
55 | | * Sends to a destination locator, through the channel managed by this resource. |
56 | | * @param buffers Vector of buffers to send. |
57 | | * @param total_bytes Length of all buffers to be sent. Will be used as a boundary for |
58 | | * the previous parameter. |
59 | | * @param destination_locators_begin destination endpoint Locators iterator begin. |
60 | | * @param destination_locators_end destination endpoint Locators iterator end. |
61 | | * @param max_blocking_time_point If transport supports it then it will use it as maximum blocking time. |
62 | | * @return Success of the send operation. |
63 | | */ |
64 | | bool send( |
65 | | const std::vector<NetworkBuffer>& buffers, |
66 | | const uint32_t& total_bytes, |
67 | | LocatorsIterator* destination_locators_begin, |
68 | | LocatorsIterator* destination_locators_end, |
69 | | const std::chrono::steady_clock::time_point& max_blocking_time_point) |
70 | 0 | { |
71 | 0 | return send_buffers_lambda_(buffers, total_bytes, destination_locators_begin, destination_locators_end, |
72 | 0 | max_blocking_time_point); |
73 | 0 | } |
74 | | |
75 | | /** |
76 | | * Resources can only be transfered through move semantics. Copy, assignment, and |
77 | | * construction outside of the factory are forbidden. |
78 | | */ |
79 | | SenderResource( |
80 | | SenderResource&& rValueResource) |
81 | 0 | { |
82 | 0 | clean_up.swap(rValueResource.clean_up); |
83 | 0 | send_buffers_lambda_.swap(rValueResource.send_buffers_lambda_); |
84 | 0 | } |
85 | | |
86 | 0 | virtual ~SenderResource() = default; |
87 | | |
88 | | int32_t kind() const |
89 | 0 | { |
90 | 0 | return transport_kind_; |
91 | 0 | } |
92 | | |
93 | | /** |
94 | | * Add locators representing the local endpoints managed by this sender resource. |
95 | | * |
96 | | * @param [in,out] locators List where locators will be added. |
97 | | */ |
98 | | virtual void add_locators_to_list( |
99 | | LocatorList_t& locators) const |
100 | 0 | { |
101 | 0 | (void)locators; |
102 | 0 | } |
103 | | |
104 | | protected: |
105 | | |
106 | | SenderResource( |
107 | | int32_t transport_kind) |
108 | 0 | : transport_kind_(transport_kind) |
109 | 0 | { |
110 | 0 | } |
111 | | |
112 | | int32_t transport_kind_; |
113 | | |
114 | | std::function<void()> clean_up; |
115 | | |
116 | | std::function<bool( |
117 | | const std::vector<NetworkBuffer>&, |
118 | | uint32_t, |
119 | | LocatorsIterator* destination_locators_begin, |
120 | | LocatorsIterator* destination_locators_end, |
121 | | const std::chrono::steady_clock::time_point&)> send_buffers_lambda_; |
122 | | |
123 | | private: |
124 | | |
125 | | SenderResource() = delete; |
126 | | SenderResource( |
127 | | const SenderResource&) = delete; |
128 | | SenderResource& operator =( |
129 | | const SenderResource&) = delete; |
130 | | }; |
131 | | |
132 | | } // namespace rtps |
133 | | } // namespace fastdds |
134 | | } // namespace eprosima |
135 | | |
136 | | #endif // FASTDDS_RTPS_TRANSPORT__SENDERRESOURCE_HPP |