Coverage Report

Created: 2025-07-03 06:58

/src/Fast-DDS/src/cpp/rtps/writer/ReaderLocator.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 ReaderLocator.hpp
17
 */
18
#ifndef FASTDDS_RTPS_WRITER__READERLOCATOR_HPP
19
#define FASTDDS_RTPS_WRITER__READERLOCATOR_HPP
20
21
#include <vector>
22
#include <fastdds/rtps/common/Locator.hpp>
23
#include <fastdds/rtps/common/Guid.hpp>
24
#include <fastdds/rtps/common/SequenceNumber.hpp>
25
#include <fastdds/rtps/messages/RTPSMessageSenderInterface.hpp>
26
#include <fastdds/rtps/common/LocatorSelectorEntry.hpp>
27
28
#include <rtps/reader/LocalReaderPointer.hpp>
29
30
namespace eprosima {
31
namespace fastdds {
32
namespace rtps {
33
34
class RTPSParticipantImpl;
35
class BaseWriter;
36
class BaseReader;
37
class IDataSharingNotifier;
38
39
/**
40
 * Class ReaderLocator, contains information about a remote reader, without saving its state.
41
 * It also implements RTPSMessageSenderInterface, so it can be used when separate sending is enabled.
42
 * @ingroup WRITER_MODULE
43
 */
44
class ReaderLocator : public RTPSMessageSenderInterface
45
{
46
public:
47
48
    virtual ~ReaderLocator();
49
50
    /**
51
     * Construct a ReaderLocator.
52
     *
53
     * @param owner                   Pointer to the BaseWriter creating this object.
54
     * @param max_unicast_locators    Maximum number of unicast locators to hold.
55
     * @param max_multicast_locators  Maximum number of multicast locators to hold.
56
     */
57
    ReaderLocator(
58
            BaseWriter* owner,
59
            size_t max_unicast_locators,
60
            size_t max_multicast_locators);
61
62
    bool expects_inline_qos() const
63
0
    {
64
0
        return expects_inline_qos_;
65
0
    }
66
67
    bool is_local_reader() const
68
0
    {
69
0
        return is_local_reader_;
70
0
    }
71
72
    LocalReaderPointer::Instance local_reader();
73
74
    void local_reader(
75
            std::shared_ptr<LocalReaderPointer> local_reader)
76
0
    {
77
0
        local_reader_ = local_reader;
78
0
    }
79
80
    const GUID_t& remote_guid() const
81
0
    {
82
0
        return general_locator_info_.remote_guid;
83
0
    }
84
85
    LocatorSelectorEntry* general_locator_selector_entry()
86
0
    {
87
0
        return &general_locator_info_;
88
0
    }
89
90
    LocatorSelectorEntry* async_locator_selector_entry()
91
0
    {
92
0
        return &async_locator_info_;
93
0
    }
94
95
    /**
96
     * Try to start using this object for a new matched reader.
97
     *
98
     * @param remote_guid         GUID of the remote reader.
99
     * @param unicast_locators    Unicast locators of the remote reader.
100
     * @param multicast_locators  Multicast locators of the remote reader.
101
     * @param expects_inline_qos  Whether remote reader expects to receive inline QoS.
102
     * @param is_datasharing      Whether remote reader can be reached through datasharing.
103
     *
104
     * @return false when this object was already started, true otherwise.
105
     */
106
    bool start(
107
            const GUID_t& remote_guid,
108
            const ResourceLimitedVector<Locator_t>& unicast_locators,
109
            const ResourceLimitedVector<Locator_t>& multicast_locators,
110
            bool expects_inline_qos,
111
            bool is_datasharing = false);
112
113
    /**
114
     * Try to update information of this object.
115
     *
116
     * @param unicast_locators    Unicast locators of the remote reader.
117
     * @param multicast_locators  Multicast locators of the remote reader.
118
     * @param expects_inline_qos  Whether remote reader expects to receive inline QoS.
119
     *
120
     * @return true when information has changed, false otherwise.
121
     */
122
    bool update(
123
            const ResourceLimitedVector<Locator_t>& unicast_locators,
124
            const ResourceLimitedVector<Locator_t>& multicast_locators,
125
            bool expects_inline_qos);
126
127
    /**
128
     * Try to stop using this object for an unmatched reader.
129
     *
130
     * @param remote_guid  GUID of the remote reader.
131
     *
132
     * @return true if this object was started for remote_guid, false otherwise.
133
     */
134
    bool stop(
135
            const GUID_t& remote_guid);
136
137
    /**
138
     * Try to stop using this object for an unmatched reader.
139
     */
140
    void stop();
141
142
    /**
143
     * Check if the destinations managed by this sender interface have changed.
144
     *
145
     * @return true if destinations have changed, false otherwise.
146
     */
147
    bool destinations_have_changed() const override
148
0
    {
149
0
        return false;
150
0
    }
151
152
    /**
153
     * Get a GUID prefix representing all destinations.
154
     *
155
     * @return When all the destinations share the same prefix (i.e. belong to the same participant)
156
     * that prefix is returned. When there are no destinations, or they belong to different
157
     * participants, c_GuidPrefix_Unknown is returned.
158
     */
159
    GuidPrefix_t destination_guid_prefix() const override
160
0
    {
161
0
        return general_locator_info_.remote_guid.guidPrefix;
162
0
    }
163
164
    /**
165
     * Get the GUID prefix of all the destination participants.
166
     *
167
     * @return a const reference to a vector with the GUID prefix of all destination participants.
168
     */
169
    const std::vector<GuidPrefix_t>& remote_participants() const override
170
0
    {
171
0
        return guid_prefix_as_vector_;
172
0
    }
173
174
    /**
175
     * Get the GUID of all destinations.
176
     *
177
     * @return a const reference to a vector with the GUID of all destinations.
178
     */
179
    const std::vector<GUID_t>& remote_guids() const override
180
0
    {
181
0
        return guid_as_vector_;
182
0
    }
183
184
    /**
185
     * Send a message through this interface.
186
     *
187
     * @param buffers Vector of NetworkBuffers to send with data already serialized.
188
     * @param total_bytes Total number of bytes to send. Should be equal to the sum of the @c size field of all buffers.
189
     * @param max_blocking_time_point Future timepoint where blocking send should end.
190
     */
191
    bool send(
192
            const std::vector<eprosima::fastdds::rtps::NetworkBuffer>& buffers,
193
            const uint32_t& total_bytes,
194
            std::chrono::steady_clock::time_point max_blocking_time_point) const override;
195
196
    /**
197
     * Check if the reader is datasharing compatible with this writer
198
     * @return true if the reader datasharing compatible with this writer
199
     */
200
    bool is_datasharing_reader() const;
201
202
    /**
203
     * @return The datasharing notifier for this reader or nullptr if the reader is not datasharing.
204
     */
205
    IDataSharingNotifier* datasharing_notifier()
206
0
    {
207
0
        return datasharing_notifier_;
208
0
    }
209
210
    /**
211
     * @return The datasharing notifier for this reader or nullptr if the reader is not datasharing.
212
     */
213
    const IDataSharingNotifier* datasharing_notifier() const
214
0
    {
215
0
        return datasharing_notifier_;
216
0
    }
217
218
    /**
219
     * Performs datasharing notification of changes on the state of a writer to the reader represented by this class.
220
     */
221
    void datasharing_notify();
222
223
    size_t locators_size() const
224
0
    {
225
0
        if (general_locator_info_.remote_guid != c_Guid_Unknown && !is_local_reader_)
226
0
        {
227
0
            if (general_locator_info_.unicast.size() > 0)
228
0
            {
229
0
                return general_locator_info_.unicast.size();
230
0
            }
231
0
            else
232
0
            {
233
0
                return general_locator_info_.multicast.size();
234
0
            }
235
0
        }
236
237
0
        return 0;
238
239
0
    }
240
241
    /*
242
     * Do nothing.
243
     * This object always is protected by writer's mutex.
244
     */
245
    void lock() override
246
0
    {
247
0
    }
248
249
    /*
250
     * Do nothing.
251
     * This object always is protected by writer's mutex.
252
     */
253
    void unlock() override
254
0
    {
255
0
    }
256
257
private:
258
259
    BaseWriter* owner_;
260
    RTPSParticipantImpl* participant_owner_;
261
    LocatorSelectorEntry general_locator_info_;
262
    LocatorSelectorEntry async_locator_info_;
263
    bool expects_inline_qos_;
264
    bool is_local_reader_;
265
    std::shared_ptr<LocalReaderPointer> local_reader_;
266
    std::vector<GuidPrefix_t> guid_prefix_as_vector_;
267
    std::vector<GUID_t> guid_as_vector_;
268
    IDataSharingNotifier* datasharing_notifier_;
269
};
270
271
} /* namespace rtps */
272
} /* namespace fastdds */
273
} /* namespace eprosima */
274
275
#endif // FASTDDS_RTPS_WRITER__READERLOCATOR_HPP