iceoryx_doc  1.0.1
chunk_sender.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_SENDER_HPP
18 #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_SENDER_HPP
19 
20 #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp"
22 #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender_data.hpp"
23 #include "iceoryx_posh/internal/popo/building_blocks/typed_unique_id.hpp"
24 #include "iceoryx_posh/mepoo/chunk_header.hpp"
25 #include "iceoryx_utils/cxx/expected.hpp"
26 #include "iceoryx_utils/cxx/helplets.hpp"
27 #include "iceoryx_utils/cxx/optional.hpp"
28 #include "iceoryx_utils/error_handling/error_handling.hpp"
29 
30 namespace iox
31 {
32 namespace popo
33 {
34 enum class AllocationError
35 {
36  INVALID_STATE,
37  RUNNING_OUT_OF_CHUNKS,
38  TOO_MANY_CHUNKS_ALLOCATED_IN_PARALLEL,
39  INVALID_PARAMETER_FOR_USER_PAYLOAD_OR_USER_HEADER,
40 };
41 
47 template <typename ChunkSenderDataType>
48 class ChunkSender : public ChunkDistributor<typename ChunkSenderDataType::ChunkDistributorData_t>
49 {
50  public:
51  using MemberType_t = ChunkSenderDataType;
53 
54  explicit ChunkSender(cxx::not_null<MemberType_t* const> chunkSenderDataPtr) noexcept;
55 
56  ChunkSender(const ChunkSender& other) = delete;
57  ChunkSender& operator=(const ChunkSender&) = delete;
58  ChunkSender(ChunkSender&& rhs) = default;
59  ChunkSender& operator=(ChunkSender&& rhs) = default;
60  ~ChunkSender() = default;
61 
73  cxx::expected<mepoo::ChunkHeader*, AllocationError> tryAllocate(const UniquePortId originId,
74  const uint32_t userPayloadSize,
75  const uint32_t userPayloadAlignment,
76  const uint32_t userHeaderSize,
77  const uint32_t userHeaderAlignment) noexcept;
78 
81  void release(const mepoo::ChunkHeader* const chunkHeader) noexcept;
82 
85  void send(mepoo::ChunkHeader* const chunkHeader) noexcept;
86 
89  void pushToHistory(mepoo::ChunkHeader* const chunkHeader) noexcept;
90 
93  cxx::optional<const mepoo::ChunkHeader*> tryGetPreviousChunk() const noexcept;
94 
98  void releaseAll() noexcept;
99 
100  private:
105  bool getChunkReadyForSend(const mepoo::ChunkHeader* const chunkHeader, mepoo::SharedChunk& chunk) noexcept;
106 
107  const MemberType_t* getMembers() const noexcept;
108  MemberType_t* getMembers() noexcept;
109 };
110 
111 } // namespace popo
112 } // namespace iox
113 
114 #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl"
115 
116 #endif // IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_SENDER_HPP
WARNING: SharedChunk is not thread safe! Don't share SharedChunk objects between threads!...
Definition: shared_chunk.hpp:35
The ChunkDistributor is the low layer building block to send SharedChunks to a dynamic number of Chun...
Definition: chunk_distributor.hpp:63
The ChunkSender is a building block of the shared memory communication infrastructure....
Definition: chunk_sender.hpp:49
void release(const mepoo::ChunkHeader *const chunkHeader) noexcept
Release an allocated chunk without sending it.
Definition: chunk_sender.inl:114
void send(mepoo::ChunkHeader *const chunkHeader) noexcept
Send an allocated chunk to all connected ChunkQueuePopper.
Definition: chunk_sender.inl:125
void pushToHistory(mepoo::ChunkHeader *const chunkHeader) noexcept
Push an allocated chunk to the history without sending it.
Definition: chunk_sender.inl:140
cxx::expected< mepoo::ChunkHeader *, AllocationError > tryAllocate(const UniquePortId originId, const uint32_t userPayloadSize, const uint32_t userPayloadAlignment, const uint32_t userHeaderSize, const uint32_t userHeaderAlignment) noexcept
allocate a chunk, the ownership of the SharedChunk remains in the ChunkSender for being able to clean...
Definition: chunk_sender.inl:45
void releaseAll() noexcept
Release all the chunks that are currently held. Caution: Only call this if the user process is no mor...
Definition: chunk_sender.inl:168
cxx::optional< const mepoo::ChunkHeader * > tryGetPreviousChunk() const noexcept
Returns the last sent chunk if there is one.
Definition: chunk_sender.inl:155
Definition: service_description.hpp:29
Definition: chunk_header.hpp:42