iceoryx_doc  1.0.1
posix_shm_memory_provider.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
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 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_POSH_ROUDI_MEMORY_POSIX_SHM_MEMORY_PROVIDER_HPP
17 #define IOX_POSH_ROUDI_MEMORY_POSIX_SHM_MEMORY_PROVIDER_HPP
18 
19 #include "iceoryx_posh/roudi/memory/memory_provider.hpp"
20 
21 #include "iceoryx_posh/iceoryx_posh_types.hpp"
22 #include "iceoryx_utils/cxx/expected.hpp"
23 #include "iceoryx_utils/cxx/optional.hpp"
24 #include "iceoryx_utils/cxx/string.hpp"
25 #include "iceoryx_utils/internal/posix_wrapper/shared_memory_object.hpp"
26 
27 #include <cstdint>
28 
29 namespace iox
30 {
31 namespace roudi
32 {
35 {
36  public:
42  PosixShmMemoryProvider(const ShmName_t& shmName,
43  const posix::AccessMode accessMode,
44  const posix::OwnerShip ownership) noexcept;
45  ~PosixShmMemoryProvider() noexcept;
46 
48  PosixShmMemoryProvider& operator=(PosixShmMemoryProvider&&) = delete;
49 
51  PosixShmMemoryProvider& operator=(const PosixShmMemoryProvider&) = delete;
52 
53  protected:
59  cxx::expected<void*, MemoryProviderError> createMemory(const uint64_t size, const uint64_t alignment) noexcept;
60 
63  cxx::expected<MemoryProviderError> destroyMemory() noexcept;
64 
65  private:
66  ShmName_t m_shmName;
67  posix::AccessMode m_accessMode{posix::AccessMode::READ_ONLY};
68  posix::OwnerShip m_ownership{posix::OwnerShip::OPEN_EXISTING};
69  cxx::optional<posix::SharedMemoryObject> m_shmObject;
70 };
71 
72 } // namespace roudi
73 } // namespace iox
74 
75 #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:72
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:35
PosixShmMemoryProvider(const ShmName_t &shmName, const posix::AccessMode accessMode, const posix::OwnerShip ownership) noexcept
Constructs a PosixShmMemoryProvider which can be used to request memory via MemoryBlocks.
cxx::expected< MemoryProviderError > destroyMemory() noexcept
Implementation of MemoryProvider::destroyMemory.
cxx::expected< void *, MemoryProviderError > createMemory(const uint64_t size, const uint64_t alignment) noexcept
Implementation of MemoryProvider::createMemory.
MemoryProviderError
Definition: memory_provider.hpp:36
Definition: service_description.hpp:29