Logo AND Algorithmique Numérique Distribuée

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