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