The MAUVE Toolchain
Component.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_COMPONENT_HPP
19 #define MAUVE_RUNTIME_COMPONENT_HPP
20 
21 #include "common.hpp"
22 #include "AbstractComponent.hpp"
23 #include "WithLogger.hpp"
24 #include "WithShell.hpp"
25 #include "WithCore.hpp"
26 #include "WithFSM.hpp"
27 #include "ShellContainer.hpp"
28 #include "CoreContainer.hpp"
29 #include "FSMContainer.hpp"
30 
31 #include <string>
32 #include <iostream>
33 #include <pthread.h>
34 
35 #define MIN_PRIO 1
36 #define MAX_PRIO 99
37 
38 namespace mauve {
39  namespace runtime {
40 
41  class Architecture;
42  class Shell;
43  class AbstractCore;
44  class AbstractFiniteStateMachine;
45  template <typename C>
46  class State;
47 
53  template <typename SHELL, typename CORE, typename FSM>
54  class Component final
55  : public AbstractComponent
56  , virtual public Configurable
57  , virtual public WithShell<SHELL>
58  , virtual public WithCore<CORE>
59  , virtual public WithFSM<FSM>
60  , virtual public ShellContainer
61  , virtual public CoreContainer<SHELL>
62  , virtual public FSMContainer<SHELL, CORE>
63  {
64  public:
65  friend class Architecture;
66 
67  Component(Component const & component) = delete;
68  Component * operator&() = delete;
69 
70  // ---------- Logger----------
71 
72  inline AbstractLogger & logger() const override { return *_logger; }
73 
74  // ---------- Component----------
75 
76  bool is_empty () const override;
77  bool is_configured() const override;
78  bool is_created () const override;
79  bool is_activated () const override;
80  bool is_running () const override;
81 
82  bool configure() override;
83  void cleanup () override;
84 
85  void disconnect() override;
86 
87  bool clear() override;
88 
89  template <typename ...P>
90  bool make(P... parameters);
91 
92  template <typename S, typename C, typename F, typename ...P>
93  bool make(P... parameters);
94 
96  inline Task & get_task() const { return *_task; }
97  void set_task(Task* task) override;
98 
99  time_ns_t get_time() const override;
100 
101  inline int get_priority() const override { return _priority; }
102  bool set_priority(int priority) override;
103 
104  inline int get_cpu() const override { return _cpu; }
105  bool set_cpu(int cpu) override;
106 
107  // ---------- Shell ----------
108 
109  inline Shell * get_shell() const override { return _shell; }
110  inline SHELL & shell() const override { return *_shell; }
111 
112  inline bool is_empty_shell() const override { return _shell == nullptr; }
113 
114  bool configure_shell() override;
115  bool cleanup_shell () override;
116 
117  bool clear_shell() override;
118 
119  template <typename ...P>
120  bool make_shell(P... parameters);
121 
122  template <typename S, typename ...P>
123  bool make_shell(P... parameters);
124 
125  template <typename S, typename ...P>
126  bool replace_shell(P... parameters);
127 
128  // ---------- Core ----------
129 
130  inline AbstractCore * get_core() const override { return _core; }
131  inline CORE & core() const override { return *_core; }
132  inline CORE * core_ptr () const override final { return _core; }
133 
134  inline bool is_empty_core() const override { return _core == nullptr; }
135 
136  bool configure_core() override;
137  bool cleanup_core () override;
138 
139  bool clear_core() override;
140 
141  template <typename ...P>
142  bool make_core(P... parameters);
143 
144  template <typename C, typename ...P>
145  bool make_core(P... parameters);
146 
147  template <typename C, typename ...P>
148  bool replace_core(P... parameters);
149 
150  // ---------- Finite State Machine ----------
151 
152  inline AbstractFiniteStateMachine * get_fsm() const override { return _fsm; }
153  inline FSM & fsm() const override { return *_fsm; }
154 
155  inline bool is_empty_fsm() const override { return _fsm == nullptr; }
156 
157  bool configure_fsm() override;
158  bool cleanup_fsm () override;
159 
160  bool clear_fsm() override;
161 
162  template <typename ...P>
163  bool make_fsm(P... parameters);
164 
165  template <typename F, typename ...P>
166  bool make_fsm(P... parameters);
167 
168  template <typename F, typename ...P>
169  bool replace_fsm(P... parameters);
170 
171  bool step() override;
172 
173  AbstractState * current_state() override;
174 
175  private:
176  Component(std::string const & name);
177  ~Component() noexcept;
178 
179  bool run() override;
180 
181  ComponentLogger* _logger;
182  SHELL* _shell;
183  CORE* _core;
184  FSM* _fsm;
185  State<CORE>* current;
186  Task* _task;
187  int _priority;
188  int _cpu;
189  };
190 
191  }} // namespaces
192 
193  #include "ipp/Component.ipp"
194 
195  #endif // MAUVE_RUNTIME_COMPONENT_HPP
Shell * get_shell() const override
Get a pointer to the shell.
Definition: Component.hpp:109
Class of a MAUVE logger for a component.
Definition: logger.hpp:188
void set_task(Task *task) override
Set the task executing this component.
Definition: Component.ipp:140
void disconnect() override
Disconnect the component.
Definition: Component.ipp:108
int get_priority() const override
Get the priority of the component real-time task.
Definition: Component.hpp:101
bool clear() override
Clear the component.
Definition: Component.ipp:114
void cleanup() override
Cleanup the object.
Definition: Component.ipp:100
Definition: ShellContainer.hpp:28
Task & get_task() const
Get the task executing this component.
Definition: Component.hpp:96
Architecture class.
Definition: Architecture.hpp:41
bool is_empty() const override
Check if the component is empty (i.e.
Definition: Component.ipp:62
Definition: FSMContainer.hpp:30
bool set_priority(int priority) override
Sets the real-time task priority.
Definition: Component.ipp:151
bool is_empty_shell() const override
Check if the shell is empty.
Definition: Component.hpp:112
bool step() override
Make one step on the component FSM.
Definition: Component.ipp:380
A Finite State Machine describes the component behavior.
Definition: AbstractFiniteStateMachine.hpp:34
Object with a Shell.
Definition: WithShell.hpp:28
Component class.
Definition: Architecture.hpp:34
bool clear_fsm() override
Clear the FSM.
Definition: Component.ipp:337
Class of a generic MAUVE logger.
Definition: logger.hpp:39
Definition: Component.hpp:46
bool is_empty_fsm() const override
Check if the FSM is empty.
Definition: Component.hpp:155
The MAUVE namespace.
Definition: tracing.hpp:24
Core container.
Definition: CoreContainer.hpp:33
CORE * core_ptr() const overridefinal
Get a pointer to the Core.
Definition: Component.hpp:132
bool configure_fsm() override
Configure the FSM.
Definition: Component.ipp:312
SHELL & shell() const override
Get the shell.
Definition: Component.hpp:110
Abstract State class.
Definition: AbstractState.hpp:34
Configurable trait.
Definition: Configurable.hpp:25
Object with a Core.
Definition: WithCore.hpp:30
int get_cpu() const override
Get the cpu mapping of the component task.
Definition: Component.hpp:104
bool is_created() const override
Check if the component is created.
Definition: Component.ipp:73
bool is_running() const override
Check if the component is running.
Definition: Component.ipp:85
A Shell is the interface of a component.
Definition: Shell.hpp:48
bool configure_shell() override
Configure th shell.
Definition: Component.ipp:171
bool is_activated() const override
Check if the component is activated.
Definition: Component.ipp:79
AbstractFiniteStateMachine * get_fsm() const override
Get a pointer to the FSM.
Definition: Component.hpp:152
bool clear_shell() override
Clear the shell.
Definition: Component.ipp:194
std::string name() const overridefinal
Get component name.
Definition: AbstractComponent.hpp:62
time_ns_t get_time() const override
Get the component current time.
Definition: Component.ipp:145
bool is_empty_core() const override
Check if the Core is empty.
Definition: Component.hpp:134
AbstractState * current_state() override
Get component current State.
Definition: Component.ipp:398
The Core defines the methods of the component.
Definition: AbstractCore.hpp:37
bool cleanup_core() override
Clean up the Core.
Definition: Component.ipp:251
bool is_configured() const override
Get the configuration status of the configurable object.
Definition: Component.ipp:67
Object with a FiniteStateMachine.
Definition: WithFSM.hpp:28
CORE & core() const override
Get the Core.
Definition: Component.hpp:131
bool configure_core() override
Configure the Core.
Definition: Component.ipp:238
AbstractLogger & logger() const override
Get the logger.
Definition: Component.hpp:72
bool configure() override
Configure the object.
Definition: Component.ipp:91
bool clear_core() override
Clear the Core.
Definition: Component.ipp:264
bool cleanup_fsm() override
Clean up the FSM.
Definition: Component.ipp:325
Abstract Component class.
Definition: AbstractComponent.hpp:43
bool cleanup_shell() override
Clean up the shell.
Definition: Component.ipp:182
AbstractCore * get_core() const override
Get a pointer to the Core.
Definition: Component.hpp:130
A system Task that executes a component.
Definition: Task.hpp:46
bool set_cpu(int cpu) override
Set the affinity of the task of the component to a single processor.
Definition: Component.ipp:160
FSM & fsm() const override
Get the FSM.
Definition: Component.hpp:153