iceoryx_posh  2.0.2
rpc_header.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 - 2022 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 
18 #ifndef IOX_POSH_POPO_RPC_HEADER_HPP
19 #define IOX_POSH_POPO_RPC_HEADER_HPP
20 
21 #include "iceoryx_hoofs/internal/cxx/unique_id.hpp"
22 #include "iceoryx_posh/mepoo/chunk_header.hpp"
23 
24 #include <cstdint>
25 
26 namespace iox
27 {
28 namespace popo
29 {
31 {
32  public:
39  explicit RpcBaseHeader(const cxx::UniqueId& uniqueClientQueueId,
40  const uint32_t lastKnownClientQueueIndex,
41  const int64_t sequenceId,
42  const uint8_t rpcHeaderVersion) noexcept;
43 
44  RpcBaseHeader(const RpcBaseHeader& other) = delete;
45  RpcBaseHeader& operator=(const RpcBaseHeader&) = delete;
46  RpcBaseHeader(RpcBaseHeader&& rhs) noexcept = default;
47  RpcBaseHeader& operator=(RpcBaseHeader&& rhs) noexcept = default;
48  ~RpcBaseHeader() noexcept = default;
49 
55  static constexpr uint8_t RPC_HEADER_VERSION{1U};
56 
57  static constexpr uint32_t UNKNOWN_CLIENT_QUEUE_INDEX{std::numeric_limits<uint32_t>::max()};
58  static constexpr int64_t START_SEQUENCE_ID{0};
59 
62  uint8_t getRpcHeaderVersion() const noexcept;
63 
66  int64_t getSequenceId() const noexcept;
67 
70  mepoo::ChunkHeader* getChunkHeader() noexcept;
71 
74  const mepoo::ChunkHeader* getChunkHeader() const noexcept;
75 
78  void* getUserPayload() noexcept;
79 
82  const void* getUserPayload() const noexcept;
83 
84  friend class ServerPortUser;
85 
86  protected:
87  uint8_t m_rpcHeaderVersion{RPC_HEADER_VERSION};
88  uint32_t m_lastKnownClientQueueIndex{UNKNOWN_CLIENT_QUEUE_INDEX};
89  cxx::UniqueId m_uniqueClientQueueId;
90  int64_t m_sequenceId{0};
91 };
92 
94 {
95  public:
100  explicit RequestHeader(const cxx::UniqueId& uniqueClientQueueId, const uint32_t lastKnownClientQueueIndex) noexcept;
101 
102  RequestHeader(const RequestHeader& other) = delete;
103  RequestHeader& operator=(const RequestHeader&) = delete;
104  RequestHeader(RequestHeader&& rhs) noexcept = default;
105  RequestHeader& operator=(RequestHeader&& rhs) noexcept = default;
106  ~RequestHeader() noexcept = default;
107 
113  void setSequenceId(const int64_t sequenceId) noexcept;
114 
115  static RequestHeader* fromPayload(void* const payload) noexcept;
116  static const RequestHeader* fromPayload(const void* const payload) noexcept;
117 };
118 
120 {
121  public:
127  explicit ResponseHeader(const cxx::UniqueId& uniqueClientQueueId,
128  const uint32_t lastKnownClientQueueIndex,
129  const int64_t sequenceId) noexcept;
130 
131  ResponseHeader(const ResponseHeader& other) = delete;
132  ResponseHeader& operator=(const ResponseHeader&) = delete;
133  ResponseHeader(ResponseHeader&& rhs) noexcept = default;
134  ResponseHeader& operator=(ResponseHeader&& rhs) noexcept = default;
135  ~ResponseHeader() noexcept = default;
136 
138  void setServerError() noexcept;
139 
142  bool hasServerError() const noexcept;
143 
144  static ResponseHeader* fromPayload(void* const payload) noexcept;
145  static const ResponseHeader* fromPayload(const void* const payload) noexcept;
146 
147  private:
148  bool m_hasServerError{false};
149 };
150 
151 } // namespace popo
152 } // namespace iox
153 
154 #endif // IOX_POSH_POPO_RPC_HEADER_HPP
Definition: rpc_header.hpp:94
RequestHeader(const cxx::UniqueId &uniqueClientQueueId, const uint32_t lastKnownClientQueueIndex) noexcept
Constructs and initializes a RpcBaseHeader.
void setSequenceId(const int64_t sequenceId) noexcept
Sets the sequence ID which is used to match a response to a request.
Definition: rpc_header.hpp:120
ResponseHeader(const cxx::UniqueId &uniqueClientQueueId, const uint32_t lastKnownClientQueueIndex, const int64_t sequenceId) noexcept
Constructs and initializes a RpcBaseHeader.
Definition: rpc_header.hpp:31
RpcBaseHeader(const cxx::UniqueId &uniqueClientQueueId, const uint32_t lastKnownClientQueueIndex, const int64_t sequenceId, const uint8_t rpcHeaderVersion) noexcept
Constructs and initializes a RpcBaseHeader.
mepoo::ChunkHeader * getChunkHeader() noexcept
Get the pointer to the ChunkHeader.
uint8_t getRpcHeaderVersion() const noexcept
The RpcBaseHeader version is used to detect incompatibilities for record&replay functionality.
int64_t getSequenceId() const noexcept
void * getUserPayload() noexcept
Get the pointer to the user-payload.
static constexpr uint8_t RPC_HEADER_VERSION
From the 2.0 release onward, this must be incremented for each incompatible change,...
Definition: rpc_header.hpp:55