iceoryx_doc  1.0.1
server_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_SERVER_PORT_USER_HPP
18 #define IOX_POSH_POPO_PORTS_SERVER_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/server_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 ServerPortUser : public BasePort
40 {
41  public:
43 
44  explicit ServerPortUser(cxx::not_null<MemberType_t* const> serverPortDataPtr) noexcept;
45 
46  ServerPortUser(const ServerPortUser& other) = delete;
47  ServerPortUser& operator=(const ServerPortUser&) = delete;
48  ServerPortUser(ServerPortUser&& rhs) = default;
49  ServerPortUser& operator=(ServerPortUser&& rhs) = default;
50  ~ServerPortUser() = default;
51 
56  cxx::expected<cxx::optional<const RequestHeader*>, ChunkReceiveResult> getRequest() noexcept;
57 
60  void releaseRequest(const RequestHeader* const requestHeader) noexcept;
61 
64  bool hasNewRequests() const noexcept;
65 
69 
75  cxx::expected<ResponseHeader*, AllocationError> allocateResponse(const uint32_t userPayloadSize) noexcept;
76 
79  void freeResponse(ResponseHeader* const responseHeader) noexcept;
80 
83  void sendResponse(ResponseHeader* const responseHeader) noexcept;
84 
86  void offer() noexcept;
87 
89  void stopOffer() noexcept;
90 
93  bool isOffered() const noexcept;
94 
97  bool hasClients() const noexcept;
98 
101  void setConditionVariable(ConditionVariableData& conditionVariableData, const uint64_t notificationIndex) noexcept;
102 
104  void unsetConditionVariable() noexcept;
105 
108  bool isConditionVariableSet() const noexcept;
109 
110  private:
111  const MemberType_t* getMembers() const noexcept;
112  MemberType_t* getMembers() noexcept;
113 
114  ChunkSender<ServerChunkSenderData_t> m_chunkSender;
115  ChunkReceiver<ServerChunkReceiverData_t> m_chunkReceiver;
116 };
117 
118 } // namespace popo
119 } // namespace iox
120 
121 #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
Definition: client_server_port_types.hpp:97
Definition: client_server_port_types.hpp:136
The ServerPortUser provides the API for accessing a server port from the user side....
Definition: server_port_user.hpp:40
void unsetConditionVariable() noexcept
unset a condition variable from the client
void sendResponse(ResponseHeader *const responseHeader) noexcept
Send an allocated request chunk to the server port.
bool isOffered() const noexcept
Checks whether the server port is currently offered.
bool hasNewRequests() const noexcept
check if there are requests in the queue
void offer() noexcept
offer this server port in the system
bool hasLostRequestsSinceLastCall() noexcept
check if there was a queue overflow since the last call of hasLostRequestsSinceLastCall
void freeResponse(ResponseHeader *const responseHeader) noexcept
Free an allocated response without sending it.
cxx::expected< ResponseHeader *, AllocationError > allocateResponse(const uint32_t userPayloadSize) noexcept
Allocate a response, the ownerhip of the SharedChunk remains in the ServerPortUser for being able to ...
void setConditionVariable(ConditionVariableData &conditionVariableData, const uint64_t notificationIndex) noexcept
set a condition variable (via its pointer) to the client
bool hasClients() const noexcept
Checks whether there are currently clients connected to this server.
void releaseRequest(const RequestHeader *const requestHeader) noexcept
Release a request that was obtained with getRequest.
void stopOffer() noexcept
stop offering this server port, all clients will be disconnected from this server
bool isConditionVariableSet() const noexcept
check if there's a condition variable set
cxx::expected< cxx::optional< const RequestHeader * >, ChunkReceiveResult > getRequest() noexcept
Tries to get the next request from the queue. If there is a new one, the ChunkHeader of the oldest re...
Definition: service_description.hpp:29
Defines different base port data.
Definition: base_port_data.hpp:34
Definition: condition_variable_data.hpp:31
Definition: server_port_data.hpp:34