Skip to content

iceoryx_posh/popo/rpc_header.hpp🔗

Namespaces🔗

Name
iox
iox::popo

Classes🔗

Name
class iox::popo::RpcBaseHeader
class iox::popo::RequestHeader
class iox::popo::ResponseHeader

Source code🔗

// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 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_POPO_RPC_HEADER_HPP
#define IOX_POSH_POPO_RPC_HEADER_HPP

#include "iceoryx_hoofs/internal/cxx/unique_id.hpp"
#include "iceoryx_posh/mepoo/chunk_header.hpp"

#include <cstdint>

namespace iox
{
namespace popo
{
class RpcBaseHeader
{
  public:
    explicit RpcBaseHeader(const cxx::UniqueId& uniqueClientQueueId,
                           const uint32_t lastKnownClientQueueIndex,
                           const int64_t sequenceId,
                           const uint8_t rpcHeaderVersion) noexcept;

    RpcBaseHeader(const RpcBaseHeader& other) = delete;
    RpcBaseHeader& operator=(const RpcBaseHeader&) = delete;
    RpcBaseHeader(RpcBaseHeader&& rhs) noexcept = default;
    RpcBaseHeader& operator=(RpcBaseHeader&& rhs) noexcept = default;
    ~RpcBaseHeader() noexcept = default;

    static constexpr uint8_t RPC_HEADER_VERSION{1U};

    static constexpr uint32_t UNKNOWN_CLIENT_QUEUE_INDEX{std::numeric_limits<uint32_t>::max()};
    static constexpr int64_t START_SEQUENCE_ID{0};

    uint8_t getRpcHeaderVersion() const noexcept;

    int64_t getSequenceId() const noexcept;

    mepoo::ChunkHeader* getChunkHeader() noexcept;

    const mepoo::ChunkHeader* getChunkHeader() const noexcept;

    void* getUserPayload() noexcept;

    const void* getUserPayload() const noexcept;

    friend class ServerPortUser;

  protected:
    uint8_t m_rpcHeaderVersion{RPC_HEADER_VERSION};
    uint32_t m_lastKnownClientQueueIndex{UNKNOWN_CLIENT_QUEUE_INDEX};
    cxx::UniqueId m_uniqueClientQueueId;
    int64_t m_sequenceId{0};
};

class RequestHeader : public RpcBaseHeader
{
  public:
    explicit RequestHeader(const cxx::UniqueId& uniqueClientQueueId, const uint32_t lastKnownClientQueueIndex) noexcept;

    RequestHeader(const RequestHeader& other) = delete;
    RequestHeader& operator=(const RequestHeader&) = delete;
    RequestHeader(RequestHeader&& rhs) noexcept = default;
    RequestHeader& operator=(RequestHeader&& rhs) noexcept = default;
    ~RequestHeader() noexcept = default;

    void setSequenceId(const int64_t sequenceId) noexcept;

    static RequestHeader* fromPayload(void* const payload) noexcept;
    static const RequestHeader* fromPayload(const void* const payload) noexcept;
};

class ResponseHeader : public RpcBaseHeader
{
  public:
    explicit ResponseHeader(const cxx::UniqueId& uniqueClientQueueId,
                            const uint32_t lastKnownClientQueueIndex,
                            const int64_t sequenceId) noexcept;

    ResponseHeader(const ResponseHeader& other) = delete;
    ResponseHeader& operator=(const ResponseHeader&) = delete;
    ResponseHeader(ResponseHeader&& rhs) noexcept = default;
    ResponseHeader& operator=(ResponseHeader&& rhs) noexcept = default;
    ~ResponseHeader() noexcept = default;

    void setServerError() noexcept;

    bool hasServerError() const noexcept;

    static ResponseHeader* fromPayload(void* const payload) noexcept;
    static const ResponseHeader* fromPayload(const void* const payload) noexcept;

  private:
    bool m_hasServerError{false};
};

} // namespace popo
} // namespace iox

#endif // IOX_POSH_POPO_RPC_HEADER_HPP

Updated on 17 March 2022 at 12:15:57 CET