The MAUVE Toolchain
AbstractDeployer.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_ABSTRACT_DEPLOYER_HPP
19 #define MAUVE_RUNTIME_ABSTRACT_DEPLOYER_HPP
20 
21 #include <signal.h>
22 #include <map>
23 #include <vector>
24 #include <string>
25 
26 #include "common.hpp"
27 
28 #define DEPLOYER_SIG SIGINT
29 
30 namespace mauve {
31  namespace runtime {
32 
33  class Architecture;
34  class AbstractComponent;
35  class AbstractDeployer;
36  class Task;
37  class DeployerLogger;
38 
39  template <typename A>
40  class Manager;
41 
49  template <typename ARCHI>
50  AbstractDeployer* mk_abstract_deployer(ARCHI * architecture, Manager<ARCHI> * manager = nullptr);
51 
56  public:
60  static AbstractDeployer* instance() { return deployer; }
62  virtual ~AbstractDeployer() noexcept;
63 
64  // ---------- Architecture ----------
65 
70  virtual Architecture* get_architecture() = 0;
71 
72  // ---------- Manager ----------
73 
78  virtual std::vector<std::string> manager_actions() const = 0;
84  virtual bool manager_apply(std::string name) = 0;
85 
86  // ---------- Components & Tasks ----------
87 
93  Task* get_task(AbstractComponent * component);
94 
95  // ---------- Start/Stop ----------
96 
101  time_ns_t now() const;
102 
107  time_ns_t get_time() const;
108 
113  bool create_tasks();
114 
120  bool create_task(AbstractComponent * component);
121 
126  bool activate();
127 
133  bool activate(AbstractComponent * component);
134 
140  bool activate(std::string name);
141 
146  bool start();
147 
154  bool start(AbstractComponent * component, time_ns_t start_time);
155 
162  bool start(std::string name, time_ns_t start_time);
163 
169  bool start_deployer();
173  void loop();
174 
178  void stop();
179 
183  bool stop(AbstractComponent * component);
184 
186  bool stop(std::string name);
187 
189  void clear_tasks();
190 
194  bool clear_task(AbstractComponent * component);
195 
197  inline DeployerLogger* logger() { return _logger; };
198 
199  protected:
206 
207  private:
208  template <typename ARCHI>
210 
211  std::map<AbstractComponent*, Task*> tasks;
212  time_ns_t start_time;
213  sigset_t sig_set;
214 
215  };
216 
220  void mk_python_deployer();
221 
222  }
223 }
224 
225 #endif // MAUVE_RUNTIME_ABSTRACT_DEPLOYER_HPP
AbstractDeployer * mk_abstract_deployer(ARCHI *architecture, Manager< ARCHI > *manager=nullptr)
Build the application Deployer from an architecture.
Definition: Deployer.ipp:29
Class of a MAUVE logger for the deployer.
Definition: logger.hpp:230
time_ns_t now() const
Get current deployer time.
bool start()
Start all tasks.
virtual Architecture * get_architecture()=0
Get the deployer architecture.
time_ns_t get_time() const
Get deployer reference time.
Task * get_task(AbstractComponent *component)
Get the task associated to a component.
virtual ~AbstractDeployer() noexcept
Destructor.
bool start_deployer()
Start only the Deployer.
Architecture class.
Definition: Architecture.hpp:41
void mk_python_deployer()
Create the Deployer for access from the python binding.
DeployerLogger * logger()
Access to deployer logger.
Definition: AbstractDeployer.hpp:197
Abstract Deployer class.
Definition: AbstractDeployer.hpp:55
friend AbstractDeployer * mk_abstract_deployer(ARCHI *a, Manager< ARCHI > *m)
Build the application Deployer from an architecture.
Definition: Deployer.ipp:29
The MAUVE namespace.
Definition: tracing.hpp:24
bool create_tasks()
Create all tasks.
static AbstractDeployer * instance()
Get the Deployer instance.
Definition: AbstractDeployer.hpp:60
static AbstractDeployer * deployer
The singleton Deployer instance.
Definition: AbstractDeployer.hpp:203
void clear_tasks()
Clear the tasks.
DeployerLogger * _logger
The Deployer logger.
Definition: AbstractDeployer.hpp:205
bool create_task(AbstractComponent *component)
Create one task.
bool clear_task(AbstractComponent *component)
Clear component task.
virtual std::vector< std::string > manager_actions() const =0
Get the list of Manager actions.
Definition: AbstractDeployer.hpp:40
virtual bool manager_apply(std::string name)=0
Apply a Manager action.
bool activate()
Activate all tasks.
Abstract Component class.
Definition: AbstractComponent.hpp:43
A system Task that executes a component.
Definition: Task.hpp:46