Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/writer/ReaderLocator.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
/**
16
 * @file ReaderLocator.h
17
 */
18
#ifndef _FASTDDS_RTPS_READERLOCATOR_H_
19
#define _FASTDDS_RTPS_READERLOCATOR_H_
20
21
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
22
23
#include <vector>
24
#include <fastdds/rtps/common/Locator.h>
25
#include <fastdds/rtps/common/Guid.h>
26
#include <fastdds/rtps/common/SequenceNumber.h>
27
#include <fastdds/rtps/messages/RTPSMessageGroup.h>
28
#include <fastdds/rtps/common/LocatorSelectorEntry.hpp>
29
30
namespace eprosima {
31
namespace fastrtps {
32
namespace rtps {
33
34
class RTPSParticipantImpl;
35
class RTPSWriter;
36
class RTPSReader;
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 RTPSWriter 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
            RTPSWriter* 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
    RTPSReader* local_reader();
73
74
    void local_reader(
75
            RTPSReader* 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 message Pointer to the buffer with the message already serialized.
188
     * @param max_blocking_time_point Future timepoint where blocking send should end.
189
     */
190
    bool send(
191
            CDRMessage_t* message,
192
            std::chrono::steady_clock::time_point max_blocking_time_point) const override;
193
194
    /**
195
     * Check if the reader is datasharing compatible with this writer
196
     * @return true if the reader datasharing compatible with this writer
197
     */
198
    bool is_datasharing_reader() const;
199
200
    /**
201
     * @return The datasharing notifier for this reader or nullptr if the reader is not datasharing.
202
     */
203
    IDataSharingNotifier* datasharing_notifier()
204
0
    {
205
0
        return datasharing_notifier_;
206
0
    }
207
208
    /**
209
     * @return The datasharing notifier for this reader or nullptr if the reader is not datasharing.
210
     */
211
    const IDataSharingNotifier* datasharing_notifier() const
212
0
    {
213
0
        return datasharing_notifier_;
214
0
    }
215
216
    /**
217
     * Performs datasharing notification of changes on the state of a writer to the reader represented by this class.
218
     */
219
    void datasharing_notify();
220
221
    size_t locators_size() const
222
0
    {
223
0
        if (general_locator_info_.remote_guid != c_Guid_Unknown && !is_local_reader_)
224
0
        {
225
0
            if (general_locator_info_.unicast.size() > 0)
226
0
            {
227
0
                return general_locator_info_.unicast.size();
228
0
            }
229
0
            else
230
0
            {
231
0
                return general_locator_info_.multicast.size();
232
0
            }
233
0
        }
234
0
235
0
        return 0;
236
0
237
0
    }
238
239
    /*
240
     * Do nothing.
241
     * This object always is protected by writer's mutex.
242
     */
243
    void lock() override
244
0
    {
245
0
    }
246
247
    /*
248
     * Do nothing.
249
     * This object always is protected by writer's mutex.
250
     */
251
    void unlock() override
252
0
    {
253
0
    }
254
255
private:
256
257
    RTPSWriter* owner_;
258
    RTPSParticipantImpl* participant_owner_;
259
    LocatorSelectorEntry general_locator_info_;
260
    LocatorSelectorEntry async_locator_info_;
261
    bool expects_inline_qos_;
262
    bool is_local_reader_;
263
    RTPSReader* local_reader_;
264
    std::vector<GuidPrefix_t> guid_prefix_as_vector_;
265
    std::vector<GUID_t> guid_as_vector_;
266
    IDataSharingNotifier* datasharing_notifier_;
267
};
268
269
} /* namespace rtps */
270
} /* namespace fastrtps */
271
} /* namespace eprosima */
272
273
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
274
#endif /* _FASTDDS_RTPS_READERLOCATOR_H_ */