iceoryx_doc  1.0.1
client_port_user.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_PORTS_CLIENT_PORT_USER_HPP
18 #define IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_HPP
19 
20 #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp"
22 #include "iceoryx_posh/internal/popo/ports/base_port.hpp"
23 #include "iceoryx_posh/internal/popo/ports/client_port_data.hpp"
24 #include "iceoryx_posh/mepoo/chunk_header.hpp"
25 #include "iceoryx_utils/cxx/expected.hpp"
26 #include "iceoryx_utils/cxx/helplets.hpp"
27 #include "iceoryx_utils/cxx/optional.hpp"
28 #include "iceoryx_utils/error_handling/error_handling.hpp"
29 
30 namespace iox
31 {
32 namespace popo
33 {
39 class ClientPortUser : public BasePort
40 {
41  public:
43 
44  explicit ClientPortUser(cxx::not_null<MemberType_t* const> clientPortDataPtr) noexcept;
45 
46  ClientPortUser(const ClientPortUser& other) = delete;
47  ClientPortUser& operator=(const ClientPortUser&) = delete;
48  ClientPortUser(ClientPortUser&& rhs) = default;
49  ClientPortUser& operator=(ClientPortUser&& rhs) = default;
50  ~ClientPortUser() = default;
51 
57  cxx::expected<RequestHeader*, AllocationError> allocateRequest(const uint32_t userPayloadSize) noexcept;
58 
61  void freeRequest(RequestHeader* const requestHeader) noexcept;
62 
65  void sendRequest(RequestHeader* const requestHeader) noexcept;
66 
74  void connect() noexcept;
75 
77  void disconnect() noexcept;
78 
83  ConnectionState getConnectionState() const noexcept;
84 
89  cxx::expected<cxx::optional<const ResponseHeader*>, ChunkReceiveResult> getResponse() noexcept;
90 
93  void releaseResponse(const ResponseHeader* const responseHeader) noexcept;
94 
97  bool hasNewResponses() const noexcept;
98 
102 
104  void setConditionVariable(ConditionVariableData& conditionVariableData, const uint64_t notificationIndex) noexcept;
105 
107  void unsetConditionVariable() noexcept;
108 
111  bool isConditionVariableSet() const noexcept;
112 
113  private:
114  const MemberType_t* getMembers() const noexcept;
115  MemberType_t* getMembers() noexcept;
116 
117  ChunkSender<ClientChunkSenderData_t> m_chunkSender;
118  ChunkReceiver<ClientChunkReceiverData_t> m_chunkReceiver;
119 };
120 
121 } // namespace popo
122 } // namespace iox
123 
124 #endif // IOX_POSH_POPO_PORTS_PUBLISHER_PORT_USER_HPP
this class is the base for all ports. it is constructed from a member pointer and is only movable....
Definition: base_port.hpp:43
The ChunkReceiver is a building block of the shared memory communication infrastructure....
Definition: chunk_receiver.hpp:46
The ChunkSender is a building block of the shared memory communication infrastructure....
Definition: chunk_sender.hpp:49
The ClientPortUser provides the API for accessing a client port from the user side....
Definition: client_port_user.hpp:40
void releaseResponse(const ResponseHeader *const responseHeader) noexcept
Release a response that was obtained with getResponseChunk.
bool hasNewResponses() const noexcept
check if there are responses in the queue
bool isConditionVariableSet() const noexcept
check if there's a condition variable set
bool hasLostResponsesSinceLastCall() noexcept
check if there was a queue overflow since the last call of hasLostResponseChunks
cxx::expected< cxx::optional< const ResponseHeader * >, ChunkReceiveResult > getResponse() noexcept
Tries to get the next response from the queue. If there is a new one, the ChunkHeader of the oldest r...
void unsetConditionVariable() noexcept
unset a condition variable from the client
void sendRequest(RequestHeader *const requestHeader) noexcept
Send an allocated request chunk to the server port.
void setConditionVariable(ConditionVariableData &conditionVariableData, const uint64_t notificationIndex) noexcept
set a condition variable (via its pointer) to the client
cxx::expected< RequestHeader *, AllocationError > allocateRequest(const uint32_t userPayloadSize) noexcept
Allocate a chunk, the ownerhip of the SharedChunk remains in the ClientPortUser for being able to cle...
void disconnect() noexcept
disconnect from the server
void freeRequest(RequestHeader *const requestHeader) noexcept
Free an allocated request without sending it.
ConnectionState getConnectionState() const noexcept
get the current connection state. Caution: There can be delays between calling connect and a change i...
void connect() noexcept
try to connect to the server Caution: There can be delays between calling connect and a change in the...
Definition: client_server_port_types.hpp:97
Definition: client_server_port_types.hpp:136
Definition: service_description.hpp:29
Defines different base port data.
Definition: base_port_data.hpp:34
Definition: client_port_data.hpp:34
Definition: condition_variable_data.hpp:31