iceoryx_posh  2.0.2
posix_shm_memory_provider.hpp
1 // Copyright (c) 2020 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_ROUDI_MEMORY_POSIX_SHM_MEMORY_PROVIDER_HPP
18 #define IOX_POSH_ROUDI_MEMORY_POSIX_SHM_MEMORY_PROVIDER_HPP
19 
20 #include "iceoryx_posh/roudi/memory/memory_provider.hpp"
21 
22 #include "iceoryx_hoofs/cxx/expected.hpp"
23 #include "iceoryx_hoofs/cxx/optional.hpp"
24 #include "iceoryx_hoofs/cxx/string.hpp"
25 #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp"
26 #include "iceoryx_posh/iceoryx_posh_types.hpp"
27 
28 #include <cstdint>
29 
30 namespace iox
31 {
32 namespace roudi
33 {
36 {
37  public:
42  PosixShmMemoryProvider(const ShmName_t& shmName,
43  const posix::AccessMode accessMode,
44  const posix::OpenMode openMode) noexcept;
45  ~PosixShmMemoryProvider() noexcept;
46 
48  PosixShmMemoryProvider& operator=(PosixShmMemoryProvider&&) = delete;
49 
51  PosixShmMemoryProvider& operator=(const PosixShmMemoryProvider&) = delete;
52 
53  protected:
56  cxx::expected<void*, MemoryProviderError> createMemory(const uint64_t size, const uint64_t alignment) noexcept;
57 
60  cxx::expected<MemoryProviderError> destroyMemory() noexcept;
61 
62  private:
63  ShmName_t m_shmName;
64  posix::AccessMode m_accessMode{posix::AccessMode::READ_ONLY};
65  posix::OpenMode m_openMode{posix::OpenMode::OPEN_EXISTING};
66  cxx::optional<posix::SharedMemoryObject> m_shmObject;
67 };
68 
69 } // namespace roudi
70 } // namespace iox
71 
72 #endif // IOX_POSH_ROUDI_MEMORY_POSIX_SHM_MEMORY_PROVIDER_HPP
This class creates memory which is requested by the MemoryBlocks. Once the memory is available,...
Definition: memory_provider.hpp:69
uint64_t size() const noexcept
This function provides the size of the created memory.
Creates the shared memory based on a provided configuration.
Definition: posix_shm_memory_provider.hpp:36
PosixShmMemoryProvider(const ShmName_t &shmName, const posix::AccessMode accessMode, const posix::OpenMode openMode) noexcept
Constructs a PosixShmMemoryProvider which can be used to request memory via MemoryBlocks.
cxx::expected< MemoryProviderError > destroyMemory() noexcept
This function needs to be implemented to free the actual memory, e.g. in case of POSIX SHM,...
cxx::expected< void *, MemoryProviderError > createMemory(const uint64_t size, const uint64_t alignment) noexcept
This function needs to be implemented to provide the actual memory, e.g. in case of POSIX SHM,...
MemoryProviderError
Definition: memory_provider.hpp:36