1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_S4U_ENGINE_HPP
7 #define SIMGRID_S4U_ENGINE_HPP
14 #include <xbt/functional.hpp>
16 #include <simgrid/simix.hpp>
18 #include <simgrid/s4u/forward.hpp>
25 /** @brief Simulation engine
27 * This class is an interface to the simulation engine.
29 XBT_PUBLIC_CLASS Engine {
34 /** Constructor, taking the command line parameters of your main function */
35 Engine(int *argc, char **argv);
37 /** Finalize the default engine and all its dependencies */
38 static void shutdown();
40 /** @brief Load a platform file describing the environment
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.
45 void loadPlatform(const char *platf);
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**));
50 /** Registers a function as the default main function of actors
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).
55 void registerDefault(int (*code)(int,char**));
57 /** @brief Load a deployment file and launch the actors that it contains */
58 void loadDeployment(const char *deploy);
60 /** @brief Run the simulation */
63 /** @brief Retrieve the simulation time */
64 static double getClock();
66 /** @brief Retrieve the engine singleton */
67 static s4u::Engine *instance();
69 /** @brief Retrieve the root netzone, containing all others */
70 simgrid::s4u::NetZone* netRoot();
72 /** @brief Retrieve the netzone of the given name (or nullptr if not found) */
73 simgrid::s4u::NetZone* netzoneByNameOrNull(const char* name);
75 /** @brief Retrieve the netcard of the given name (or nullptr if not found) */
76 simgrid::kernel::routing::NetCard* netcardByNameOrNull(const char* name);
77 void netcardList(std::vector<simgrid::kernel::routing::NetCard*> * list);
78 void netcardRegister(simgrid::kernel::routing::NetCard * card);
79 void netcardUnregister(simgrid::kernel::routing::NetCard * card);
82 void registerFunction(const char* name)
84 simgrid::simix::registerFunction(name, [](std::vector<std::string> args){
85 return simgrid::simix::ActorCode([args] {
86 F code(std::move(args));
93 void registerFunction(const char* name, F code)
95 simgrid::simix::registerFunction(name, [code](std::vector<std::string> args){
96 return simgrid::simix::ActorCode([code,args] {
97 code(std::move(args));
102 simgrid::kernel::EngineImpl* pimpl;
105 static s4u::Engine *instance_;
107 }} // namespace simgrid::s4u
109 #endif /* SIMGRID_S4U_ENGINE_HPP */