iceoryx_doc  1.0.1
segment_manager.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_POSH_MEPOO_SEGMENT_MANAGER_HPP
18 #define IOX_POSH_MEPOO_SEGMENT_MANAGER_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_config.hpp"
21 #include "iceoryx_posh/iceoryx_posh_types.hpp"
22 #include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
23 #include "iceoryx_posh/internal/mepoo/mepoo_segment.hpp"
24 #include "iceoryx_posh/mepoo/segment_config.hpp"
25 #include "iceoryx_utils/cxx/optional.hpp"
26 #include "iceoryx_utils/cxx/string.hpp"
27 #include "iceoryx_utils/cxx/vector.hpp"
28 #include "iceoryx_utils/internal/posix_wrapper/shared_memory_object/allocator.hpp"
29 #include "iceoryx_utils/posix_wrapper/posix_access_rights.hpp"
30 
31 namespace iox
32 {
33 namespace roudi
34 {
35 template <typename MemoryManager, typename SegmentManager, typename PublisherPort>
36 class MemPoolIntrospection;
37 }
38 
39 namespace mepoo
40 {
41 template <typename SegmentType = MePooSegment<>>
43 {
44  public:
45  SegmentManager(const SegmentConfig& segmentConfig, posix::Allocator* managementAllocator) noexcept;
46  ~SegmentManager() noexcept = default;
47 
48  SegmentManager(const SegmentManager& rhs) = delete;
49  SegmentManager(SegmentManager&& rhs) = delete;
50 
51  SegmentManager& operator=(const SegmentManager& rhs) = delete;
52  SegmentManager& operator=(SegmentManager&& rhs) = delete;
53 
55  {
56  public:
57  SegmentMapping(const ShmName_t& sharedMemoryName,
58  void* startAddress,
59  uint64_t size,
60  bool isWritable,
61  uint64_t segmentId,
62  const iox::mepoo::MemoryInfo& memoryInfo = iox::mepoo::MemoryInfo()) noexcept
63  : m_sharedMemoryName(sharedMemoryName)
64  , m_startAddress(startAddress)
65  , m_size(size)
66  , m_isWritable(isWritable)
67  , m_segmentId(segmentId)
68  , m_memoryInfo(memoryInfo)
69 
70  {
71  }
72 
73  ShmName_t m_sharedMemoryName{""};
74  void* m_startAddress{nullptr};
75  uint64_t m_size{0};
76  bool m_isWritable{false};
77  uint64_t m_segmentId{0};
78  iox::mepoo::MemoryInfo m_memoryInfo; // we can specify additional info about a segments memory here
79  };
80 
82  {
83  cxx::optional<std::reference_wrapper<MemoryManager>> m_memoryManager;
84  uint64_t m_segmentID;
85  };
86 
87  using SegmentMappingContainer = cxx::vector<SegmentMapping, MAX_SHM_SEGMENTS>;
88 
89  SegmentMappingContainer getSegmentMappings(const posix::PosixUser& user) noexcept;
90  SegmentUserInformation getSegmentInformationWithWriteAccessForUser(const posix::PosixUser& user) noexcept;
91 
92  static uint64_t requiredManagementMemorySize(const SegmentConfig& config) noexcept;
93  static uint64_t requiredChunkMemorySize(const SegmentConfig& config) noexcept;
94  static uint64_t requiredFullMemorySize(const SegmentConfig& config) noexcept;
95 
96  private:
97  void createSegment(const SegmentConfig::SegmentEntry& segmentEntry) noexcept;
98 
99  private:
100  template <typename MemoryManger, typename SegmentManager, typename PublisherPort>
101  friend class roudi::MemPoolIntrospection;
102 
103  posix::Allocator* m_managementAllocator;
104  cxx::vector<SegmentType, MAX_SHM_SEGMENTS> m_segmentContainer;
105  bool m_createInterfaceEnabled{true};
106 };
107 
108 
109 } // namespace mepoo
110 } // namespace iox
111 
112 #include "iceoryx_posh/internal/mepoo/segment_manager.inl"
113 
114 #endif // IOX_POSH_MEPOO_SEGMENT_MANAGER_HPP
Definition: segment_manager.hpp:43
This class handles the mempool intropection for RouDi. It is recommended to use the MemPoolIntrospect...
Definition: mempool_introspection.hpp:40
Definition: service_description.hpp:29
Stores properties of the memory to be used when we distinguish between different types of memory on e...
Definition: memory_info.hpp:28
Definition: segment_config.hpp:33
Definition: segment_config.hpp:31
Definition: segment_manager.hpp:55
Definition: segment_manager.hpp:82