/src/Fast-DDS/src/cpp/rtps/history/BasicPayloadPool.hpp
Line | Count | Source |
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 BasicPayloadPool.hpp |
17 | | */ |
18 | | |
19 | | #ifndef RTPS_HISTORY_BASICPAYLOADPOOL_HPP |
20 | | #define RTPS_HISTORY_BASICPAYLOADPOOL_HPP |
21 | | |
22 | | #include <fastdds/rtps/common/CacheChange.hpp> |
23 | | #include <fastdds/rtps/history/IPayloadPool.hpp> |
24 | | |
25 | | #include <rtps/history/CacheChangePool.h> |
26 | | #include <rtps/history/PoolConfig.h> |
27 | | |
28 | | #include <memory> |
29 | | |
30 | | namespace eprosima { |
31 | | namespace fastdds { |
32 | | namespace rtps { |
33 | | |
34 | | namespace detail { |
35 | | #include "./BasicPayloadPool_impl/Base.hpp" |
36 | | |
37 | | #include "./BasicPayloadPool_impl/Dynamic.hpp" |
38 | | #include "./BasicPayloadPool_impl/DynamicReusable.hpp" |
39 | | #include "./BasicPayloadPool_impl/Preallocated.hpp" |
40 | | #include "./BasicPayloadPool_impl/PreallocatedWithRealloc.hpp" |
41 | | } // namespace detail |
42 | | |
43 | | class BasicPayloadPool |
44 | | { |
45 | | |
46 | | public: |
47 | | |
48 | | static std::shared_ptr<IPayloadPool> get( |
49 | | const PoolConfig& config, |
50 | | std::shared_ptr<IChangePool>& change_pool) |
51 | 0 | { |
52 | 0 | auto payload_pool = get(config); |
53 | 0 | if (payload_pool) |
54 | 0 | { |
55 | 0 | if ((PREALLOCATED_MEMORY_MODE == config.memory_policy) || |
56 | 0 | (PREALLOCATED_WITH_REALLOC_MEMORY_MODE == config.memory_policy)) |
57 | 0 | { |
58 | 0 | change_pool = std::make_shared<CacheChangePool>(config, |
59 | 0 | [&payload_pool, &config]( |
60 | 0 | CacheChange_t* change) |
61 | 0 | { |
62 | 0 | if (payload_pool->get_payload(config.payload_initial_size, |
63 | 0 | change->serializedPayload)) |
64 | 0 | { |
65 | 0 | payload_pool->release_payload(change->serializedPayload); |
66 | 0 | } |
67 | 0 | }); |
68 | 0 | } |
69 | 0 | else |
70 | 0 | { |
71 | 0 | change_pool = std::make_shared<CacheChangePool>(config); |
72 | 0 | } |
73 | 0 | } |
74 | |
|
75 | 0 | return payload_pool; |
76 | 0 | } |
77 | | |
78 | | private: |
79 | | |
80 | | static std::shared_ptr<IPayloadPool> get( |
81 | | const BasicPoolConfig& config) |
82 | 0 | { |
83 | 0 | if (config.payload_initial_size == 0) |
84 | 0 | { |
85 | 0 | return nullptr; |
86 | 0 | } |
87 | | |
88 | 0 | switch (config.memory_policy) |
89 | 0 | { |
90 | 0 | case PREALLOCATED_MEMORY_MODE: |
91 | 0 | return std::make_shared<detail::Impl<PREALLOCATED_MEMORY_MODE>>(config.payload_initial_size); |
92 | 0 | case PREALLOCATED_WITH_REALLOC_MEMORY_MODE: |
93 | 0 | return std::make_shared<detail::Impl<PREALLOCATED_WITH_REALLOC_MEMORY_MODE>>( |
94 | 0 | config.payload_initial_size); |
95 | 0 | case DYNAMIC_RESERVE_MEMORY_MODE: |
96 | 0 | return std::make_shared<detail::Impl<DYNAMIC_RESERVE_MEMORY_MODE>>(); |
97 | 0 | case DYNAMIC_REUSABLE_MEMORY_MODE: |
98 | 0 | return std::make_shared<detail::Impl<DYNAMIC_REUSABLE_MEMORY_MODE>>(); |
99 | 0 | } |
100 | | |
101 | 0 | return nullptr; |
102 | 0 | } |
103 | | |
104 | | }; |
105 | | |
106 | | } // namespace rtps |
107 | | } // namespace fastdds |
108 | | } // namespace eprosima |
109 | | |
110 | | #endif // RTPS_HISTORY_BASICPAYLOADPOOL_HPP |