iceoryx_doc  1.0.1
shared_chunk.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_SHARED_CHUNK_HPP
18 #define IOX_POSH_MEPOO_SHARED_CHUNK_HPP
19 
20 #include "iceoryx_posh/internal/mepoo/chunk_management.hpp"
21 #include "iceoryx_posh/internal/mepoo/mem_pool.hpp"
22 #include "iceoryx_posh/mepoo/chunk_header.hpp"
23 #include "iceoryx_utils/internal/relocatable_pointer/relative_pointer.hpp"
24 
25 namespace iox
26 {
27 namespace mepoo
28 {
29 template <typename>
30 class SharedPointer;
31 
35 {
36  public:
37  SharedChunk() = default;
38  SharedChunk(ChunkManagement* const resource) noexcept;
39  ~SharedChunk() noexcept;
40 
41  SharedChunk(const SharedChunk& rhs) noexcept;
42  SharedChunk(SharedChunk&& rhs) noexcept;
43 
44  SharedChunk& operator=(const SharedChunk& rhs) noexcept;
45  SharedChunk& operator=(SharedChunk&& rhs) noexcept;
46 
47  ChunkHeader* getChunkHeader() const noexcept;
48  void* getUserPayload() const noexcept;
49 
50  ChunkManagement* release() noexcept;
51 
52  bool operator==(const SharedChunk& rhs) const noexcept;
54  bool operator==(const void* const rhs) const noexcept;
55 
56  bool operator!=(const SharedChunk& rhs) const noexcept;
57  bool operator!=(const void* const rhs) const noexcept;
58 
59  operator bool() const noexcept;
60 
61  template <typename>
62  friend class SharedPointer;
63 
64  private:
65  void decrementReferenceCounter() noexcept;
66  void incrementReferenceCounter() noexcept;
67  void freeChunk() noexcept;
68 
69  private:
70  ChunkManagement* m_chunkManagement{nullptr};
71 };
72 } // namespace mepoo
73 } // namespace iox
74 
75 #endif // IOX_POSH_MEPOO_SHARED_CHUNK_HPP
WARNING: SharedChunk is not thread safe! Don't share SharedChunk objects between threads!...
Definition: shared_chunk.hpp:35
bool operator==(const void *const rhs) const noexcept
DesignPattern::Creation offers us a create method which forwards the arguments to the constructor....
Definition: shared_pointer.hpp:47
Definition: service_description.hpp:29
Definition: chunk_header.hpp:42
Definition: chunk_management.hpp:35