Skip to content

iceoryx_posh/mepoo/chunk_header.hpp🔗

Namespaces🔗

Name
iox
iox::popo
iox::mepoo
Mepoo Component Description.

Classes🔗

Name
class iox::popo::ChunkSender
The ChunkSender is a building block of the shared memory communication infrastructure. It extends the functionality of a ChunkDistributor with the abililty to allocate and free memory chunks. For getting chunks of memory the MemoryManger is used. Together with the ChunkReceiver, they are the next abstraction layer on top of ChunkDistributor and ChunkQueuePopper. The ChunkSender holds the ownership of the SharedChunks and does a bookkeeping which chunks are currently passed to the user side.
struct iox::mepoo::NoUserHeader
Helper struct to use as default template parameter when no user-header is used.
struct iox::mepoo::ChunkHeader

Source code🔗

// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_POSH_MEPOO_CHUNK_HEADER_HPP
#define IOX_POSH_MEPOO_CHUNK_HEADER_HPP

#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/internal/popo/building_blocks/typed_unique_id.hpp"
#include "iceoryx_posh/mepoo/chunk_settings.hpp"

#include <cstdint>

namespace iox
{
namespace popo
{
template <typename T>
class ChunkSender;
}

namespace mepoo
{
struct NoUserHeader
{
};

struct ChunkHeader
{
    using UserPayloadOffset_t = uint32_t;

    ChunkHeader(const uint32_t chunkSize, const ChunkSettings& chunkSettings) noexcept;

    // copy/move ctors/assignment operators are deleted since the calculations for the user-header and user-payload
    // alignment are dependent on the address of the this pointer
    ChunkHeader(const ChunkHeader&) = delete;
    ChunkHeader(ChunkHeader&&) = delete;

    ChunkHeader& operator=(const ChunkHeader&) = delete;
    ChunkHeader& operator=(ChunkHeader&&) = delete;

    static constexpr uint8_t CHUNK_HEADER_VERSION{1U};

    static constexpr uint16_t NO_USER_HEADER{0x0000};
    static constexpr uint16_t UNKNOWN_USER_HEADER{0xFFFF};

    uint8_t chunkHeaderVersion() const noexcept;

    uint16_t userHeaderId() const noexcept;

    void* userHeader() noexcept;

    const void* userHeader() const noexcept;

    void* userPayload() noexcept;

    const void* userPayload() const noexcept;

    static ChunkHeader* fromUserPayload(void* const userPayload) noexcept;

    static const ChunkHeader* fromUserPayload(const void* const userPayload) noexcept;

    uint32_t usedSizeOfChunk() const noexcept;

    uint32_t chunkSize() const noexcept;

    uint32_t userHeaderSize() const noexcept;

    uint32_t userPayloadSize() const noexcept;

    uint32_t userPayloadAlignment() const noexcept;

    UniquePortId originId() const noexcept;

    uint64_t sequenceNumber() const noexcept;

  private:
    template <typename T>
    friend class popo::ChunkSender;

    void setOriginId(UniquePortId originId) noexcept;

    void setSequenceNumber(uint64_t sequenceNumber) noexcept;

    uint64_t overflowSafeUsedSizeOfChunk() const noexcept;

  private:
    // the order of these members must be changed carefully and if this happens, the m_chunkHeaderVersion
    // needs to be adapted in order to be able to detect incompatibilities between publisher/subscriber
    // or record&replay, m_chunkSize and m_chunkHeaderVersion should therefore neither changed the type,
    // nor the position

    // size of the whole chunk, including the header
    uint32_t m_chunkSize{0U};
    uint8_t m_chunkHeaderVersion{CHUNK_HEADER_VERSION};
    // reserved for future functionality and used to indicate the padding bytes; currently not used and set to `0`
    uint8_t m_reserved{0};
    // currently just a placeholder
    uint16_t m_userHeaderId{NO_USER_HEADER};
    UniquePortId m_originId{popo::InvalidId};
    uint64_t m_sequenceNumber{0U};
    uint32_t m_userHeaderSize{0U};
    uint32_t m_userPayloadSize{0U};
    uint32_t m_userPayloadAlignment{1U};
    UserPayloadOffset_t m_userPayloadOffset{sizeof(ChunkHeader)};
};

} // namespace mepoo
} // namespace iox

#endif // IOX_POSH_MEPOO_CHUNK_HEADER_HPP

Updated on 17 June 2021 at 11:15:27 CEST