The MAUVE Toolchain
Interface.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_INTERFACE_HPP
19 #define MAUVE_RUNTIME_INTERFACE_HPP
20 
21 #include "AbstractInterface.hpp"
22 #include "ServiceContainer.hpp"
23 #include "EventService.hpp"
24 #include "ReadService.hpp"
25 #include "WriteService.hpp"
26 #include "CallService.hpp"
27 #include "InterfaceContainer.hpp"
28 #include "WithHook.hpp"
29 
30 namespace mauve {
31  namespace runtime {
32 
33  template <typename SHELL, typename CORE>
34  class Interface
35  : public AbstractInterface
36  , virtual public ServiceContainer<CORE>
37  , virtual public WithLogger
38  , virtual public WithHook
39  {
40  public:
41  template <typename S, typename C, typename I>
42  friend class Resource;
43 
44  Interface(Interface const & other) = delete;
45 
46  std::string name() const { return _container->name(); }
47 
48  // ---------- Service ----------
49 
50  std::size_t get_services_size() const override final { return services.size(); }
51 
52  const std::vector<Service*> get_services() const override final;
53 
54  Service* get_service(std::string const & name) const override final;
55 
56  Service* get_service(int index) const override final;
57 
58  int get_service_index(const Service* service) const override final;
59 
60  inline AbstractLogger& logger() const override { return _container->logger(); };
61 
62  inline bool is_configured() const override final { return _configured; }
63 
64  inline bool configure() override final { return _container->configure_interface(); }
65  inline void cleanup() override final { _container->cleanup_interface(); }
66 
67  inline CORE * core_ptr () const override final { return _container->core_ptr(); }
68 
69  protected:
70  Interface();
71  virtual ~Interface() noexcept;
72 
73  inline SHELL & shell() const { return _container->shell(); };
74  inline CORE & core () const { return _container->core(); };
75 
76  // ---------- Service ----------
77 
78  EventService &
79  mk_event_service(std::string const & name, typename EventServiceImpl<CORE>::action_t action);
80 
81  template <typename T>
83  mk_read_service(std::string const & name, typename ReadServiceImpl<CORE, T>::action_t action);
84 
85  template <typename T>
87  mk_write_service(std::string const & name, typename WriteServiceImpl<CORE, T>::action_t action);
88 
89  template <typename R, typename ...P>
90  CallService<R, P...> &
91  mk_call_service(std::string const & name, typename CallServiceImpl<CORE, R, P...>::action_t action);
92 
93  private:
95  bool _configured;
96  std::vector<Service *> services;
97 
98  bool _configure();
99  void _cleanup();
100  };
101 
102  // -------------------- Exceptions --------------------
103 
105  struct AllreadyDefinedService: public std::exception {
107  AllreadyDefinedService(std::string const & name) throw() : name(name) {}
109  const std::string name;
111  virtual const char* what() const throw() {
112  std::string message = "Allready Defined Service " + name;
113  return message.c_str();
114  }
115  };
116 
117  }
118 }
119 
120 #include "ipp/Interface.ipp"
121 
122 #endif
Definition: Interface.hpp:34
std::string name() const
Get the name.
Definition: Interface.hpp:46
const std::string name
Exception name.
Definition: Interface.hpp:109
Class of a Call service.
Definition: CallPort.hpp:27
Definition: ReadPort.hpp:27
AllreadyDefinedService(std::string const &name)
Constructor.
Definition: Interface.hpp:107
Abstract Interface class.
Definition: AbstractInterface.hpp:35
bool configure() overridefinal
Configure the object.
Definition: Interface.hpp:64
Objects with hooks.
Definition: WithHook.hpp:27
Object with a Logger.
Definition: WithLogger.hpp:27
Service * get_service(std::string const &name) const overridefinal
Get a service by name.
Definition: Interface.ipp:75
Class of a generic MAUVE logger.
Definition: logger.hpp:39
The MAUVE namespace.
Definition: tracing.hpp:24
std::function< R(CORE *, P...)> action_t
Service action type.
Definition: CallService.hpp:63
const std::vector< Service * > get_services() const overridefinal
Get the set of services owned by the interface.
Definition: Interface.ipp:66
Definition: Architecture.hpp:38
bool is_configured() const overridefinal
Get the configuration status of the configurable object.
Definition: Interface.hpp:62
void cleanup() overridefinal
Cleanup the object.
Definition: Interface.hpp:65
Definition: EventService.hpp:31
Definition: InterfaceContainer.hpp:30
A Service.
Definition: Service.hpp:30
Definition: WritePort.hpp:27
AbstractLogger & logger() const override
Get the logger.
Definition: Interface.hpp:60
virtual const char * what() const
Exception explanation.
Definition: Interface.hpp:111
Definition: CallService.hpp:29
Exception for Already Defined Services.
Definition: Interface.hpp:105