iceoryx_doc  1.0.1
chunk_distributor.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_DISTRIBUTOR_HPP
18 #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_DISTRIBUTOR_HPP
19 
20 #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor_data.hpp"
22 #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp"
23 #include "iceoryx_utils/cxx/helplets.hpp"
24 
25 #include <thread>
26 
27 namespace iox
28 {
29 namespace popo
30 {
31 enum class ChunkDistributorError
32 {
33  INVALID_STATE,
34  QUEUE_CONTAINER_OVERFLOW,
35  QUEUE_NOT_IN_CONTAINER
36 };
37 
61 template <typename ChunkDistributorDataType>
63 {
64  public:
65  using MemberType_t = ChunkDistributorDataType;
66  using ChunkQueueData_t = typename ChunkDistributorDataType::ChunkQueueData_t;
67  using ChunkQueuePusher_t = typename ChunkDistributorDataType::ChunkQueuePusher_t;
68 
69  explicit ChunkDistributor(cxx::not_null<MemberType_t* const> chunkDistrubutorDataPtr) noexcept;
70 
71  ChunkDistributor(const ChunkDistributor& other) = delete;
72  ChunkDistributor& operator=(const ChunkDistributor&) = delete;
73  ChunkDistributor(ChunkDistributor&& rhs) = default;
74  ChunkDistributor& operator=(ChunkDistributor&& rhs) = default;
75  virtual ~ChunkDistributor() = default;
76 
83  cxx::expected<ChunkDistributorError> tryAddQueue(cxx::not_null<ChunkQueueData_t* const> queueToAdd,
84  const uint64_t requestedHistory = 0u) noexcept;
85 
89  cxx::expected<ChunkDistributorError> tryRemoveQueue(cxx::not_null<ChunkQueueData_t* const> queueToRemove) noexcept;
90 
92  void removeAllQueues() noexcept;
93 
96  bool hasStoredQueues() const noexcept;
97 
101  void deliverToAllStoredQueues(mepoo::SharedChunk chunk) noexcept;
102 
108  bool deliverToQueue(cxx::not_null<ChunkQueueData_t* const> queue, mepoo::SharedChunk chunk) noexcept;
109 
113  void addToHistoryWithoutDelivery(mepoo::SharedChunk chunk) noexcept;
114 
117  uint64_t getHistorySize() noexcept;
118 
121  uint64_t getHistoryCapacity() const noexcept;
122 
124  void clearHistory() noexcept;
125 
127  void cleanup() noexcept;
128 
129  protected:
130  const MemberType_t* getMembers() const noexcept;
131  MemberType_t* getMembers() noexcept;
132 
133  private:
134  MemberType_t* m_chunkDistrubutorDataPtr{nullptr};
135 };
136 
137 } // namespace popo
138 } // namespace iox
139 
140 #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl"
141 
142 #endif // IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_DISTRIBUTOR_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
cxx::expected< ChunkDistributorError > tryRemoveQueue(cxx::not_null< ChunkQueueData_t *const > queueToRemove) noexcept
Remove a queue from the internal list of chunk queues.
Definition: chunk_distributor.inl:98
cxx::expected< ChunkDistributorError > tryAddQueue(cxx::not_null< ChunkQueueData_t *const > queueToAdd, const uint64_t requestedHistory=0u) noexcept
Add a queue to the internal list of chunk queues to which chunks are delivered when calling deliverTo...
Definition: chunk_distributor.inl:47
bool deliverToQueue(cxx::not_null< ChunkQueueData_t *const > queue, mepoo::SharedChunk chunk) noexcept
Deliver the provided shared chunk to the provided chunk queue. The chunk will NOT be added to the chu...
Definition: chunk_distributor.inl:204
uint64_t getHistoryCapacity() const noexcept
Get the capacity of the chunk history.
Definition: chunk_distributor.inl:238
void cleanup() noexcept
cleanup the used shrared memory chunks
Definition: chunk_distributor.inl:257
void deliverToAllStoredQueues(mepoo::SharedChunk chunk) noexcept
Deliver the provided shared chunk to all the stored chunk queues. The chunk will be added to the chun...
Definition: chunk_distributor.inl:134
void removeAllQueues() noexcept
Delete all the stored chunk queues.
Definition: chunk_distributor.inl:118
uint64_t getHistorySize() noexcept
Get the current size of the chunk history.
Definition: chunk_distributor.inl:230
bool hasStoredQueues() const noexcept
Get the information whether there are any stored chunk queues.
Definition: chunk_distributor.inl:126
void addToHistoryWithoutDelivery(mepoo::SharedChunk chunk) noexcept
Update the chunk history but do not deliver the chunk to any chunk queue. E.g. use case is to to upda...
Definition: chunk_distributor.inl:211
void clearHistory() noexcept
Clears the chunk history.
Definition: chunk_distributor.inl:244
Definition: service_description.hpp:29