iceoryx_posh  2.0.2
iceoryx_roudi_memory_manager.hpp
1 // Copyright (c) 2020 - 2021 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_ICEORYX_ROUDI_MEMORY_MANAGER_HPP
18 #define IOX_POSH_ROUDI_MEMORY_ICEORYX_ROUDI_MEMORY_MANAGER_HPP
19 
20 #include "iceoryx_posh/roudi/memory/roudi_memory_interface.hpp"
21 
22 #include "iceoryx_hoofs/posix_wrapper/file_lock.hpp"
23 #include "iceoryx_posh/internal/log/posh_logging.hpp"
24 #include "iceoryx_posh/roudi/memory/default_roudi_memory.hpp"
25 #include "iceoryx_posh/roudi/memory/roudi_memory_manager.hpp"
26 #include "iceoryx_posh/roudi/port_pool.hpp"
27 
28 namespace iox
29 {
30 namespace roudi
31 {
33 {
34  public:
35  IceOryxRouDiMemoryManager(const RouDiConfig_t& roudiConfig) noexcept;
37  virtual ~IceOryxRouDiMemoryManager() noexcept = default;
38 
41 
43  IceOryxRouDiMemoryManager& operator=(const IceOryxRouDiMemoryManager&) = delete;
44 
48  cxx::expected<RouDiMemoryManagerError> createAndAnnounceMemory() noexcept override;
49 
52  cxx::expected<RouDiMemoryManagerError> destroyMemory() noexcept override;
53 
54  const PosixShmMemoryProvider* mgmtMemoryProvider() const noexcept override;
55  cxx::optional<PortPool*> portPool() noexcept override;
56  cxx::optional<mepoo::MemoryManager*> introspectionMemoryManager() const noexcept override;
57  cxx::optional<mepoo::SegmentManager<>*> segmentManager() const noexcept override;
58 
59  private:
60  // in order to prevent a second RouDi to cleanup the memory resources of a running RouDi, this resources are
61  // protected by a file lock
62  posix::FileLock fileLock =
63  std::move(posix::FileLock::create(ROUDI_LOCK_NAME)
64  .or_else([](auto& error) {
65  if (error == posix::FileLockError::LOCKED_BY_OTHER_PROCESS)
66  {
67  LogFatal() << "Could not acquire lock, is RouDi still running?";
68  errorHandler(Error::kICEORYX_ROUDI_MEMORY_MANAGER__ROUDI_STILL_RUNNING,
69  nullptr,
70  iox::ErrorLevel::FATAL);
71  }
72  else
73  {
74  LogFatal() << "Error occurred while acquiring file lock named " << ROUDI_LOCK_NAME;
75  errorHandler(Error::kICEORYX_ROUDI_MEMORY_MANAGER__COULD_NOT_ACQUIRE_FILE_LOCK,
76  nullptr,
77  iox::ErrorLevel::FATAL);
78  }
79  })
80  .value());
81 
82  PortPoolMemoryBlock m_portPoolBlock;
83  cxx::optional<PortPool> m_portPool;
84  DefaultRouDiMemory m_defaultMemory;
85  RouDiMemoryManager m_memoryManager;
86 };
87 } // namespace roudi
88 } // namespace iox
89 
90 #endif // IOX_POSH_ROUDI_MEMORY_ICEORYX_ROUDI_MEMORY_MANAGER_HPP
Definition: iceoryx_roudi_memory_manager.hpp:33
cxx::expected< RouDiMemoryManagerError > createAndAnnounceMemory() noexcept override
The RouDiMemoryManager calls the the MemoryProvider to create the memory and announce the availabilit...
cxx::expected< RouDiMemoryManagerError > destroyMemory() noexcept override
The RouDiMemoryManager calls the the MemoryProvider to destroy the memory, which in turn prompts the ...
virtual ~IceOryxRouDiMemoryManager() noexcept=default
The Destructor of the IceOryxRouDiMemoryManager also calls destroy on the registered MemoryProvider.
Definition: port_pool.hpp:62
Creates the shared memory based on a provided configuration.
Definition: posix_shm_memory_provider.hpp:36
Definition: roudi_memory_interface.hpp:36
Definition: roudi_memory_manager.hpp:53
RouDiMemoryManagerError
Definition: roudi_memory_manager.hpp:39
Definition: default_roudi_memory.hpp:28