Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/src/cpp/rtps/writer/PersistentWriter.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2018 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 PersistentWriter.cpp
17
 *
18
 */
19
20
#include <fastdds/rtps/writer/PersistentWriter.h>
21
#include <fastdds/rtps/history/WriterHistory.h>
22
#include <rtps/persistence/PersistenceService.h>
23
#include <fastrtps_deprecated/participant/ParticipantImpl.h>
24
#include <rtps/DataSharing/WriterPool.hpp>
25
26
namespace eprosima {
27
namespace fastrtps {
28
namespace rtps {
29
30
31
PersistentWriter::PersistentWriter(
32
        const GUID_t& guid,
33
        const WriterAttributes& att,
34
        const std::shared_ptr<IPayloadPool>& payload_pool,
35
        const std::shared_ptr<IChangePool>& change_pool,
36
        WriterHistory* hist,
37
        IPersistenceService* persistence)
38
    : persistence_(persistence)
39
    , persistence_guid_()
40
0
{
41
    // When persistence GUID is unknown, create from rtps GUID
42
0
    GUID_t p_guid = att.endpoint.persistence_guid == c_Guid_Unknown ? guid : att.endpoint.persistence_guid;
43
0
    std::ostringstream ss;
44
0
    ss << p_guid;
45
0
    persistence_guid_ = ss.str();
46
47
0
    persistence_->load_writer_from_storage(persistence_guid_, guid, hist,
48
0
            change_pool, payload_pool, hist->m_lastCacheChangeSeqNum);
49
50
    // Update history state after loading from DB
51
0
    hist->m_isHistoryFull =
52
0
            hist->m_att.maximumReservedCaches > 0 &&
53
0
            static_cast<int32_t>(hist->m_changes.size()) == hist->m_att.maximumReservedCaches;
54
55
    // Prepare the changes for datasharing if compatible
56
0
    if (att.endpoint.data_sharing_configuration().kind() != OFF)
57
0
    {
58
0
        auto pool = std::dynamic_pointer_cast<WriterPool>(payload_pool);
59
0
        assert(pool != nullptr);
60
0
        for (auto change : hist->m_changes)
61
0
        {
62
0
            pool->add_to_shared_history(change);
63
0
        }
64
0
    }
65
0
}
66
67
PersistentWriter::~PersistentWriter()
68
0
{
69
0
    delete persistence_;
70
0
}
71
72
/*
73
 * CHANGE-RELATED METHODS
74
 */
75
76
void PersistentWriter::add_persistent_change(
77
        CacheChange_t* cptr)
78
0
{
79
0
    persistence_->add_writer_change_to_storage(persistence_guid_, *cptr);
80
0
}
81
82
void PersistentWriter::remove_persistent_change(
83
        CacheChange_t* change)
84
0
{
85
0
    persistence_->remove_writer_change_from_storage(persistence_guid_, *change);
86
0
}
87
88
} // namespace rtps
89
} // namespace fastrtps
90
} // namespace eprosima