The MAUVE Toolchain
CallService.hpp
1 /*
2 * Copyright 2017 ONERA
3 *
4 * This file is part of the MAUVE Runtime project.
5 *
6 * MAUVE Runtime is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * MAUVE Runtime is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with MAUVE. If not, see <https://www.gnu.org/licenses/lgpl-3.0>.
17 */
18 #ifndef MAUVE_RUNTIME_CALL_SERVICE_HPP
19 #define MAUVE_RUNTIME_CALL_SERVICE_HPP
20 
21 #include <functional>
22 
23 #include "Service.hpp"
24 
25 namespace mauve {
26  namespace runtime {
27 
28  template <typename C>
30 
31  template <typename R, typename ...P>
32  class CallPort;
33 
35  template <typename R, typename ...P>
36  class CallService: public Service {
37  public:
39  CallService(std::string const & name): Service{name} {}
40  virtual ~CallService() noexcept {}
41 
42  CallService() = delete;
43  CallService(const CallService<R, P...> & other) = delete;
44 
45  connection_type get_type() const override final { return CALL; }
46 
48  virtual R call(P... parameters) const = 0;
50  inline R operator()(P... parameters) const { return call(parameters ...); };
51  };
52 
59  template <typename CORE, typename R, typename ...P>
60  class CallServiceImpl final: public CallService<R, P...> {
61  public:
63  using action_t = std::function<R(CORE*, P...)>;
64 
66  CallServiceImpl(ServiceContainer<CORE> * container, std::string const & name, action_t action);
67  ~CallServiceImpl() noexcept;
68 
69  CallServiceImpl() = delete;
71  CallServiceImpl(const CallService<CORE, R, P...> & other) = delete;
72 
73  std::string get_resource_name() const override { return container->name(); }
74 
76  R call(P... parameters) const override;
77 
78  private:
79  ServiceContainer<CORE> * container;
80  action_t action;
81  };
82 
83  }
84 } // namespaces
85 
86 #include "ipp/CallService.ipp"
87 
88 #endif
R operator()(P...parameters) const
Helper.
Definition: CallService.hpp:50
Call Service implementation.
Definition: CallService.hpp:60
Class of a Call service.
Definition: CallPort.hpp:27
The MAUVE namespace.
Definition: tracing.hpp:24
const std::string name
Service name.
Definition: Service.hpp:40
std::function< R(CORE *, P...)> action_t
Service action type.
Definition: CallService.hpp:63
virtual R call(P...parameters) const =0
Call the service.
A Service.
Definition: Service.hpp:30
connection_type
Port types.
Definition: AbstractPort.hpp:28
CallService(std::string const &name)
Constructor.
Definition: CallService.hpp:39
Definition: CallService.hpp:29
A Port to call a service.
Definition: CallPort.hpp:31