Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/src/cpp/rtps/messages/RTPSGapBuilder.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2020 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 RTPSGapBuilder.cpp
17
 *
18
 */
19
20
#include "RTPSGapBuilder.hpp"
21
22
namespace eprosima {
23
namespace fastrtps {
24
namespace rtps {
25
26
RTPSGapBuilder::~RTPSGapBuilder()
27
0
{
28
0
    flush();
29
0
}
30
31
bool RTPSGapBuilder::add(
32
        const SequenceNumber_t& gap_sequence)
33
0
{
34
    // Check if it is the first gap being added
35
0
    if (!is_gap_pending_)
36
0
    {
37
0
        is_gap_pending_ = true;
38
0
        initial_sequence_ = gap_sequence;
39
0
        gap_bitmap_.base(gap_sequence + 1);
40
0
        return true;
41
0
    }
42
43
    // Check for contiguous from initial_sequence_
44
0
    SequenceNumber_t base = gap_bitmap_.base();
45
0
    if (gap_sequence == base)
46
0
    {
47
0
        gap_bitmap_.base(gap_sequence + 1);
48
0
        return true;
49
0
    }
50
51
    // Check if past last in bitmap
52
0
    if (gap_bitmap_.add(gap_sequence))
53
0
    {
54
0
        return true;
55
0
    }
56
57
    // Did not fit inside bitmap. Difference between gap_sequence and base is greater than 255.
58
    // Send GAP with current info and prepare info for next GAP.
59
0
    bool ret_val = flush();
60
0
    is_gap_pending_ = true;
61
0
    initial_sequence_ = gap_sequence;
62
0
    gap_bitmap_.base(gap_sequence + 1);
63
64
0
    return ret_val;
65
0
}
66
67
bool RTPSGapBuilder::flush()
68
0
{
69
0
    if (is_gap_pending_)
70
0
    {
71
0
        bool ok = with_specific_destination_ ?
72
0
            group_.add_gap(initial_sequence_, gap_bitmap_, reader_guid_) :
73
0
            group_.add_gap(initial_sequence_, gap_bitmap_);
74
0
        if (!ok)
75
0
        {
76
0
            return false;
77
0
        }
78
0
    }
79
80
0
    is_gap_pending_ = false;
81
0
    return true;
82
0
}
83
84
} // namespace rtps
85
} // namespace fastrtps
86
} // namespace eprosima