iceoryx_posh  2.0.2
server_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_SERVER_IMPL_HPP
18 #define IOX_POSH_POPO_SERVER_IMPL_HPP
19 
20 #include "iceoryx_posh/capro/service_description.hpp"
21 #include "iceoryx_posh/internal/popo/base_server.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/request.hpp"
27 #include "iceoryx_posh/popo/response.hpp"
28 #include "iceoryx_posh/popo/server_options.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 BaseServerT = BaseServer<>>
39 class ServerImpl : public BaseServerT, private RpcInterface<Response<Res>, ServerSendError>
40 {
41  using RequestTypeAssert = typename TypedPortApiTrait<Req>::Assert;
42  using ResponseTypeAssert = typename TypedPortApiTrait<Res>::Assert;
43 
44  public:
48  explicit ServerImpl(const capro::ServiceDescription& service, const ServerOptions& serverOptions = {}) noexcept;
49  virtual ~ServerImpl() noexcept;
50 
51  ServerImpl(const ServerImpl&) = delete;
52  ServerImpl(ServerImpl&&) = delete;
53  ServerImpl& operator=(const ServerImpl&) = delete;
54  ServerImpl& operator=(ServerImpl&&) = delete;
55 
60  cxx::expected<Request<const Req>, ServerRequestResult> take() noexcept;
61 
68  template <typename... Args>
69  cxx::expected<Response<Res>, AllocationError> loan(const Request<const Req>& request, Args&&... args) noexcept;
70 
74  cxx::expected<ServerSendError> send(Response<Res>&& response) noexcept override;
75 
76  protected:
77  using BaseServerT::port;
78 
79  private:
80  cxx::expected<Response<Res>, AllocationError> loanUninitialized(const Request<const Req>& request) noexcept;
81 
82  using RequestSampleDeleter = RequestDeleter<typename BaseServerT::PortType>;
83  RequestSampleDeleter m_requestDeleter{port()};
84  using ResponseSampleDeleter = ResponseDeleter<typename BaseServerT::PortType>;
85  ResponseSampleDeleter m_responseDeleter{port()};
86 };
87 } // namespace popo
88 } // namespace iox
89 
90 #include "iceoryx_posh/internal/popo/server_impl.inl"
91 
92 #endif // IOX_POSH_POPO_SERVER_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
port
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
The ServerImpl class implements the typed server API.
Definition: server_impl.hpp:40
cxx::expected< Response< Res >, AllocationError > loan(const Request< const Req > &request, Args &&... args) noexcept
Get a Response from loaned shared memory and construct the data with the given arguments.
ServerImpl(const capro::ServiceDescription &service, const ServerOptions &serverOptions={}) noexcept
Constructor for a sserver.
cxx::expected< ServerSendError > send(Response< Res > &&response) noexcept override
Sends the given Response and then releases its loan.
cxx::expected< Request< const Req >, ServerRequestResult > take() noexcept
Take the Request from the top of the receive queue.
This struct is used to configure the server.
Definition: server_options.hpp:33