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>
22 /** @brief Simulation engine
24 * This class is an interface to the simulation engine.
26 XBT_PUBLIC_CLASS Engine {
28 /** Constructor, taking the command line parameters of your main function */
29 Engine(int *argc, char **argv);
31 /** Finalize the default engine and all its dependencies */
32 static void shutdown();
34 /** @brief Load a platform file describing the environment
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.
39 void loadPlatform(const char *platf);
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**));
44 /** Registers a function as the default main function of actors
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).
49 void registerDefault(int (*code)(int,char**));
51 /** @brief Load a deployment file and launch the actors that it contains */
52 void loadDeployment(const char *deploy);
54 /** @brief Run the simulation */
57 /** @brief Retrieve the simulation time */
58 static double getClock();
60 /** @brief Retrieve the engine singleton */
61 static s4u::Engine *instance();
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);
69 void registerFunction(const char* name)
71 simgrid::simix::registerFunction(name, [](std::vector<std::string> args){
72 return simgrid::simix::ActorCode([args] {
73 F code(std::move(args));
80 void registerFunction(const char* name, F code)
82 simgrid::simix::registerFunction(name, [code](std::vector<std::string> args){
83 return simgrid::simix::ActorCode([code,args] {
84 code(std::move(args));
90 static s4u::Engine *instance_;
92 }} // namespace simgrid::s4u
94 #endif /* SIMGRID_S4U_ENGINE_HPP */