iceoryx_posh  2.0.2
client_impl.hpp
1 // Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 
17 #ifndef IOX_POSH_POPO_CLIENT_IMPL_HPP
18 #define IOX_POSH_POPO_CLIENT_IMPL_HPP
19 
20 #include "iceoryx_posh/capro/service_description.hpp"
21 #include "iceoryx_posh/internal/popo/base_client.hpp"
22 #include "iceoryx_posh/internal/popo/request_deleter.hpp"
23 #include "iceoryx_posh/internal/popo/response_deleter.hpp"
24 #include "iceoryx_posh/internal/popo/rpc_interface.hpp"
25 #include "iceoryx_posh/internal/popo/typed_port_api_trait.hpp"
26 #include "iceoryx_posh/popo/client_options.hpp"
27 #include "iceoryx_posh/popo/request.hpp"
28 #include "iceoryx_posh/popo/response.hpp"
29 #include "iceoryx_posh/popo/trigger_handle.hpp"
30 #include "iceoryx_posh/runtime/posh_runtime.hpp"
31 
32 namespace iox
33 {
34 namespace popo
35 {
38 template <typename Req, typename Res, typename BaseClientT = BaseClient<>>
39 class ClientImpl : public BaseClientT, private RpcInterface<Request<Req>, ClientSendError>
40 {
41  using RequestTypeAssert = typename TypedPortApiTrait<Req>::Assert;
42  using ResponseTypeAssert = typename TypedPortApiTrait<Res>::Assert;
43 
44  public:
48  explicit ClientImpl(const capro::ServiceDescription& service, const ClientOptions& clientOptions = {}) noexcept;
49  virtual ~ClientImpl() noexcept;
50 
51  ClientImpl(const ClientImpl&) = delete;
52  ClientImpl(ClientImpl&&) = delete;
53  ClientImpl& operator=(const ClientImpl&) = delete;
54  ClientImpl& operator=(ClientImpl&&) = delete;
55 
61  template <typename... Args>
62  cxx::expected<Request<Req>, AllocationError> loan(Args&&... args) noexcept;
63 
67  cxx::expected<ClientSendError> send(Request<Req>&& request) noexcept override;
68 
73  cxx::expected<Response<const Res>, ChunkReceiveResult> take() noexcept;
74 
75  protected:
76  using BaseClientT::port;
77 
78  private:
79  cxx::expected<Request<Req>, AllocationError> loanUninitialized() noexcept;
80 
81  using RequestSampleDeleter = RequestDeleter<typename BaseClientT::PortType>;
82  RequestSampleDeleter m_requestDeleter{port()};
83  using ResponseSampleDeleter = ResponseDeleter<typename BaseClientT::PortType>;
84  ResponseSampleDeleter m_responseDeleter{port()};
85 };
86 } // namespace popo
87 } // namespace iox
88 
89 #include "iceoryx_posh/internal/popo/client_impl.inl"
90 
91 #endif // IOX_POSH_POPO_CLIENT_IMPL_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:81
const PortT & port() const noexcept
const accessor of the underlying port
The ClientImpl class implements the typed client API.
Definition: client_impl.hpp:40
cxx::expected< Request< Req >, AllocationError > loan(Args &&... args) noexcept
Get a Request from loaned shared memory and construct the data with the given arguments.
ClientImpl(const capro::ServiceDescription &service, const ClientOptions &clientOptions={}) noexcept
Constructor for a client.
cxx::expected< ClientSendError > send(Request< Req > &&request) noexcept override
Sends the given Request and then releases its loan.
cxx::expected< Response< const Res >, ChunkReceiveResult > take() noexcept
Take the Response from the top of the receive queue.
The Request class is a mutable abstraction over types which are written to loaned shared memory....
Definition: request.hpp:40
The Response class is a mutable abstraction over types which are written to loaned shared memory....
Definition: response.hpp:42
Definition: request.hpp:33
This struct is used to configure the client.
Definition: client_options.hpp:33