iceoryx_doc  1.0.1
pointer_repository.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 
18 #ifndef IOX_UTILS_RELOCATABLE_POINTER_POINTER_REPOSITORY_HPP
19 #define IOX_UTILS_RELOCATABLE_POINTER_POINTER_REPOSITORY_HPP
20 
21 #include "iceoryx_utils/cxx/vector.hpp"
22 #include <iostream>
23 
24 #include <assert.h>
25 #include <limits>
26 
27 namespace iox
28 {
29 namespace rp
30 {
36 template <typename id_t, typename ptr_t, uint64_t CAPACITY = 10000U>
38 {
39  private:
40  struct Info
41  {
42  ptr_t basePtr{nullptr};
43  ptr_t endPtr{nullptr};
44  };
45 
49  static constexpr size_t MIN_ID = 1U;
50  static constexpr size_t MAX_ID = CAPACITY - 1U;
51 
52  public:
53  static constexpr id_t INVALID_ID = std::numeric_limits<id_t>::max();
54 
56  PointerRepository() noexcept;
57 
63  bool registerPtr(id_t id, ptr_t ptr, uint64_t size) noexcept;
64 
69  id_t registerPtr(const ptr_t ptr, uint64_t size = 0U) noexcept;
70 
75  bool unregisterPtr(id_t id) noexcept;
76 
79  void unregisterAll() noexcept;
80 
84  ptr_t getBasePtr(id_t id) const noexcept;
85 
89  id_t searchId(ptr_t ptr) const noexcept;
90 
94  bool isValid(id_t id) const noexcept;
95 
97  void print() const noexcept;
98 
99  private:
105 
107  uint64_t m_maxRegistered{0U};
108 };
109 
110 } // namespace rp
111 } // namespace iox
112 
113 #include "iceoryx_utils/internal/relocatable_pointer/pointer_repository.inl"
114 
115 #endif // IOX_UTILS_RELOCATABLE_POINTER_POINTER_REPOSITORY_HPP
C++11 compatible vector implementation. We needed to do some adjustments in the API since we do not u...
Definition: vector.hpp:34
Allows registration of memory segments with their start pointers and size. This class is used to reso...
Definition: pointer_repository.hpp:38
bool isValid(id_t id) const noexcept
checks if given id is valid
Definition: pointer_repository.inl:135
ptr_t getBasePtr(id_t id) const noexcept
gets the base pointer, i.e. the starting address, associated with id
Definition: pointer_repository.inl:101
PointerRepository() noexcept
default constructor
Definition: pointer_repository.inl:28
bool registerPtr(id_t id, ptr_t ptr, uint64_t size) noexcept
registers the start pointer of the segment in another application with a specific id
Definition: pointer_repository.inl:34
void unregisterAll() noexcept
unregisters all ids
Definition: pointer_repository.inl:91
bool unregisterPtr(id_t id) noexcept
unregisters the id
Definition: pointer_repository.inl:74
void print() const noexcept
prints the ids and their associated base pointers
Definition: pointer_repository.inl:141
id_t searchId(ptr_t ptr) const noexcept
returns the id for a given pointer ptr
Definition: pointer_repository.inl:116
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28