Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add an EngineImpl, unused so far
[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 kernel {
22 class EngineImpl;
23 }
24 namespace s4u {
25 /** @brief Simulation engine
26  *
27  * This class is an interface to the simulation engine.
28  */
29 XBT_PUBLIC_CLASS Engine {
30 public:
31   /** Constructor, taking the command line parameters of your main function */
32   Engine(int *argc, char **argv);
33
34   /** Finalize the default engine and all its dependencies */
35   static void shutdown();
36
37   /** @brief Load a platform file describing the environment
38    *
39    * The environment is either a XML file following the simgrid.dtd formalism, or a lua file.
40    * Some examples can be found in the directory examples/platforms.
41    */
42   void loadPlatform(const char *platf);
43
44   /** Registers the main function of an actor that will be launched from the deployment file */
45   void registerFunction(const char*name, int (*code)(int,char**));
46
47   /** Registers a function as the default main function of actors
48    *
49    * It will be used as fallback when the function requested from the deployment file was not registered.
50    * It is used for trace-based simulations (see examples/msg/actions).
51    */
52   void registerDefault(int (*code)(int,char**));
53
54   /** @brief Load a deployment file and launch the actors that it contains */
55   void loadDeployment(const char *deploy);
56
57   /** @brief Run the simulation */
58   void run();
59
60   /** @brief Retrieve the simulation time */
61   static double getClock();
62   
63   /** @brief Retrieve the engine singleton */
64   static s4u::Engine *instance();
65
66   /** @brief Retrieve the root AS, containing all others */
67   simgrid::s4u::As *rootAs();
68   /** @brief Retrieve the AS of the given name (or nullptr if not found) */
69   simgrid::s4u::As *asByNameOrNull(const char *name);
70
71   template<class F>
72   void registerFunction(const char* name)
73   {
74     simgrid::simix::registerFunction(name, [](std::vector<std::string> args){
75       return simgrid::simix::ActorCode([args] {
76         F code(std::move(args));
77         code();
78       });
79     });
80   }
81
82   template<class F>
83   void registerFunction(const char* name, F code)
84   {
85     simgrid::simix::registerFunction(name, [code](std::vector<std::string> args){
86       return simgrid::simix::ActorCode([code,args] {
87         code(std::move(args));
88       });
89     });
90   }
91
92   simgrid::kernel::EngineImpl* pimpl;
93
94 private:
95   static s4u::Engine *instance_;
96 };
97 }} // namespace simgrid::s4u
98
99 #endif /* SIMGRID_S4U_ENGINE_HPP */