iceoryx_doc  1.0.1
chunk_settings.hpp
1 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 
17 #ifndef IOX_POSH_MEPOO_CHUNK_SETTINGS_HPP
18 #define IOX_POSH_MEPOO_CHUNK_SETTINGS_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_types.hpp"
21 #include "iceoryx_utils/cxx/expected.hpp"
22 
23 #include <cstdint>
24 
25 namespace iox
26 {
27 namespace mepoo
28 {
30 {
31  public:
32  enum class Error
33  {
34  ALIGNMENT_NOT_POWER_OF_TWO,
35  USER_HEADER_ALIGNMENT_EXCEEDS_CHUNK_HEADER_ALIGNMENT,
36  USER_HEADER_SIZE_NOT_MULTIPLE_OF_ITS_ALIGNMENT,
37  REQUIRED_CHUNK_SIZE_EXCEEDS_MAX_CHUNK_SIZE,
38  INVALID_STATE
39  };
40 
47  static cxx::expected<ChunkSettings, ChunkSettings::Error>
48  create(const uint32_t userPayloadSize,
49  const uint32_t userPayloadAlignment = iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT,
50  const uint32_t userHeaderSize = iox::CHUNK_NO_USER_HEADER_SIZE,
51  const uint32_t userHeaderAlignment = iox::CHUNK_NO_USER_HEADER_ALIGNMENT) noexcept;
52 
55  uint32_t requiredChunkSize() const noexcept;
56 
59  uint32_t userPayloadSize() const noexcept;
60 
63  uint32_t userPayloadAlignment() const noexcept;
64 
67  uint32_t userHeaderSize() const noexcept;
68 
71  uint32_t userHeaderAlignment() const noexcept;
72 
73  private:
74  ChunkSettings(const uint32_t userPayloadSize,
75  const uint32_t userPayloadAlignment,
76  const uint32_t userHeaderSize,
77  const uint32_t userHeaderAlignment,
78  const uint32_t requiredChunkSize) noexcept;
79 
80  static uint64_t calculateRequiredChunkSize(const uint32_t userPayloadSize,
81  const uint32_t userPayloadAlignment,
82  const uint32_t userHeaderSize) noexcept;
83 
84  private:
85  uint32_t m_userPayloadSize{0U};
86  uint32_t m_userPayloadAlignment{0U};
87  uint32_t m_userHeaderSize{0U};
88  uint32_t m_userHeaderAlignment{0U};
89  uint32_t m_requiredChunkSize{0U};
90 };
91 
92 } // namespace mepoo
93 } // namespace iox
94 
95 #endif // IOX_POSH_MEPOO_CHUNK_SETTINGS_HPP
Definition: chunk_settings.hpp:30
uint32_t userHeaderAlignment() const noexcept
getter method for the user-header alignment
uint32_t userHeaderSize() const noexcept
getter method for the user-header size
uint32_t userPayloadSize() const noexcept
getter method for the user-payload size
static cxx::expected< ChunkSettings, ChunkSettings::Error > create(const uint32_t userPayloadSize, const uint32_t userPayloadAlignment=iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT, const uint32_t userHeaderSize=iox::CHUNK_NO_USER_HEADER_SIZE, const uint32_t userHeaderAlignment=iox::CHUNK_NO_USER_HEADER_ALIGNMENT) noexcept
constructs and initializes a ChunkSettings
uint32_t userPayloadAlignment() const noexcept
getter method for the user-payload alignment
uint32_t requiredChunkSize() const noexcept
getter method for the chunk size fulfilling the user-payload and user-header requirements
Definition: service_description.hpp:29