Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Headers cleanup
[simgrid.git] / include / simgrid / s4u / engine.hpp
1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_S4U_ENGINE_HPP
7 #define SIMGRID_S4U_ENGINE_HPP
8
9 #include <string>
10 #include <utility>
11 #include <vector>
12
13 #include <xbt/base.h>
14 #include <xbt/functional.hpp>
15
16 #include <simgrid/simix.hpp>
17
18 #include <simgrid/s4u/forward.hpp>
19
20 namespace simgrid {
21 namespace s4u {
22 /** @brief Simulation engine
23  *
24  * This class is an interface to the simulation engine.
25  */
26 XBT_PUBLIC_CLASS Engine {
27 public:
28   /** Constructor, taking the command line parameters of your main function */
29   Engine(int *argc, char **argv);
30
31   /** Finalize the default engine and all its dependencies */
32   static void shutdown();
33
34   /** @brief Load a platform file describing the environment
35    *
36    * The environment is either a XML file following the simgrid.dtd formalism, or a lua file.
37    * Some examples can be found in the directory examples/platforms.
38    */
39   void loadPlatform(const char *platf);
40
41   /** Registers the main function of an actor that will be launched from the deployment file */
42   void registerFunction(const char*name, int (*code)(int,char**));
43
44   /** Registers a function as the default main function of actors
45    *
46    * It will be used as fallback when the function requested from the deployment file was not registered.
47    * It is used for trace-based simulations (see examples/msg/actions).
48    */
49   void registerDefault(int (*code)(int,char**));
50
51   /** @brief Load a deployment file and launch the actors that it contains */
52   void loadDeployment(const char *deploy);
53
54   /** @brief Run the simulation */
55   void run();
56
57   /** @brief Retrieve the simulation time */
58   static double getClock();
59   
60   /** @brief Retrieve the engine singleton */
61   static s4u::Engine *instance();
62
63   /** @brief Retrieve the root AS, containing all others */
64   simgrid::s4u::As *rootAs();
65   /** @brief Retrieve the AS of the given name (or nullptr if not found) */
66   simgrid::s4u::As *asByNameOrNull(const char *name);
67
68   template<class F>
69   void registerFunction(const char* name)
70   {
71     simgrid::simix::registerFunction(name, [](std::vector<std::string> args){
72       return simgrid::simix::ActorCode([args] {
73         F code(std::move(args));
74         code();
75       });
76     });
77   }
78
79   template<class F>
80   void registerFunction(const char* name, F code)
81   {
82     simgrid::simix::registerFunction(name, [code](std::vector<std::string> args){
83       return simgrid::simix::ActorCode([code,args] {
84         code(std::move(args));
85       });
86     });
87   }
88
89 private:
90   static s4u::Engine *instance_;
91 };
92 }} // namespace simgrid::s4u
93
94 #endif /* SIMGRID_S4U_ENGINE_HPP */