iceoryx_doc  1.0.1
chunk_receiver.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_POPO_BUILDING_BLOCKS_CHUNK_RECEIVER_HPP
18 #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_RECEIVER_HPP
19 
20 #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver_data.hpp"
22 #include "iceoryx_posh/mepoo/chunk_header.hpp"
23 #include "iceoryx_utils/cxx/expected.hpp"
24 #include "iceoryx_utils/cxx/helplets.hpp"
25 #include "iceoryx_utils/cxx/optional.hpp"
26 
27 namespace iox
28 {
29 namespace popo
30 {
31 enum class ChunkReceiveResult
32 {
33  INVALID_STATE,
34  TOO_MANY_CHUNKS_HELD_IN_PARALLEL,
35  NO_CHUNK_AVAILABLE
36 };
37 
44 template <typename ChunkReceiverDataType>
45 class ChunkReceiver : public ChunkQueuePopper<typename ChunkReceiverDataType::ChunkQueueData_t>
46 {
47  public:
48  using MemberType_t = ChunkReceiverDataType;
50 
51  explicit ChunkReceiver(cxx::not_null<MemberType_t* const> chunkReceiverDataPtr) noexcept;
52 
53  ChunkReceiver(const ChunkReceiver& other) = delete;
54  ChunkReceiver& operator=(const ChunkReceiver&) = delete;
55  ChunkReceiver(ChunkReceiver&& rhs) = default;
56  ChunkReceiver& operator=(ChunkReceiver&& rhs) = default;
57  ~ChunkReceiver() = default;
58 
64  cxx::expected<const mepoo::ChunkHeader*, ChunkReceiveResult> tryGet() noexcept;
65 
68  void release(const mepoo::ChunkHeader* const chunkHeader) noexcept;
69 
73  void releaseAll() noexcept;
74 
75  private:
76  const MemberType_t* getMembers() const noexcept;
77  MemberType_t* getMembers() noexcept;
78 };
79 
80 } // namespace popo
81 } // namespace iox
82 
83 #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.inl"
84 
85 #endif // IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_RECEIVER_HPP
The ChunkQueuePopper is the low layer building block to receive SharedChunks. It follows a first-in-f...
Definition: chunk_queue_popper.hpp:37
The ChunkReceiver is a building block of the shared memory communication infrastructure....
Definition: chunk_receiver.hpp:46
void releaseAll() noexcept
Release all the chunks that are currently held. Caution: Only call this if the user process is no mor...
Definition: chunk_receiver.inl:86
cxx::expected< const mepoo::ChunkHeader *, ChunkReceiveResult > tryGet() noexcept
Tries to get the next received chunk. If there is a new one the ChunkHeader of this new chunk is rece...
Definition: chunk_receiver.inl:50
void release(const mepoo::ChunkHeader *const chunkHeader) noexcept
Release a chunk that was obtained with get.
Definition: chunk_receiver.inl:75
Definition: service_description.hpp:29
Definition: chunk_header.hpp:42