Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/include/fastdds/rtps/history/IPayloadPool.hpp
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 IPayloadPool.hpp
17
 */
18
19
#ifndef FASTDDS_RTPS_HISTORY__IPAYLOADPOOL_HPP
20
#define FASTDDS_RTPS_HISTORY__IPAYLOADPOOL_HPP
21
22
#include <cstdint>
23
#include <memory>
24
25
namespace eprosima {
26
namespace fastdds {
27
namespace rtps {
28
29
struct SerializedPayload_t;
30
31
/**
32
 * An interface for classes responsible of serialized payload management.
33
 */
34
class IPayloadPool
35
{
36
public:
37
38
0
    virtual ~IPayloadPool() = default;
39
40
    /**
41
     * @brief Get a serialized payload for a new sample.
42
     *
43
     * This method will usually be called in one of the following situations:
44
     *     @li When a writer creates a new cache change
45
     *     @li When a reader receives the first fragment of a cache change
46
     *
47
     * In both cases, the received @c size will be for the whole serialized payload.
48
     *
49
     * @param [in]     size     Number of bytes required for the serialized payload.
50
     * @param [in,out] payload  Payload of the cache change used in the operation
51
     *
52
     * @returns whether the operation succeeded or not
53
     *
54
     * @post
55
     *     @li Field @c payload.payload_owner equals this
56
     *     @li Field @c payload.data points to a buffer of at least @c size bytes
57
     *     @li Field @c payload.max_size is greater than or equal to @c size
58
     */
59
    virtual bool get_payload(
60
            uint32_t size,
61
            SerializedPayload_t& payload) = 0;
62
63
    /**
64
     * @brief Assign a serialized payload to a new sample.
65
     *
66
     * This method will usually be called when a reader receives a whole cache change.
67
     *
68
     * @param [in,out] data     Serialized payload received
69
     * @param [in,out] payload  Destination serialized payload
70
     *
71
     * @returns whether the operation succeeded or not
72
     *
73
     * @note If @c data has no owner, it means it is allocated on the stack of a
74
     * reception thread, and a copy should be performed. If the ownership of @c data needs to be changed,
75
     * a consecutive call to this method needs to be performed with the arguments swapped, leveraging the
76
     * post-condition of this method which ensures that @c payload.payload_owner points to @c this.
77
     *
78
     * @post
79
     *     @li Field @c payload.payload_owner equals this
80
     *     @li Field @c payload.data points to a buffer of at least @c data.length bytes
81
     *     @li Field @c payload.length is equal to @c data.length
82
     *     @li Field @c payload.max_size is greater than or equal to @c data.length
83
     *     @li Content of @c payload.data is the same as @c data.data
84
     */
85
    virtual bool get_payload(
86
            const SerializedPayload_t& data,
87
            SerializedPayload_t& payload) = 0;
88
89
    /**
90
     * @brief Release a serialized payload from a sample.
91
     *
92
     * This method will be called when a cache change is removed from a history.
93
     *
94
     * @param [in,out] payload  Payload to be released
95
     *
96
     * @returns whether the operation succeeded or not
97
     *
98
     * @pre @li Field @c payload_owner of @c payload equals this
99
     *
100
     * @post @li Field @c payload_owner of @c payload is @c nullptr
101
     */
102
    virtual bool release_payload(
103
            SerializedPayload_t& payload) = 0;
104
};
105
106
} // namespace rtps
107
} // namespace fastdds
108
} // namespace eprosima
109
110
111
#endif // FASTDDS_RTPS_HISTORY__IPAYLOADPOOL_HPP