X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ac50b8930983a4feabb64975226a1e090883179f..70dc601f33c2b92b5632f2023865a99476a86c6d:/src/s4u/s4u_Engine.cpp diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index c30e3ef10f..c773d0e75f 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -23,6 +23,7 @@ #include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON #include +#include #include XBT_LOG_NEW_CATEGORY(s4u, "Log channels of the S4U (Simgrid for you) interface"); @@ -41,7 +42,7 @@ Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see Engine::Engine(int* argc, char** argv) : pimpl(new kernel::EngineImpl()) { xbt_assert(Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine"); - TRACE_global_init(); + instr::init(); SIMIX_global_init(argc, argv); Engine::instance_ = this; @@ -92,7 +93,10 @@ void Engine::load_platform(const std::string& platf) void Engine::register_function(const std::string& name, int (*code)(int, char**)) // deprecated { - register_function(name, [code](std::vector args) { return xbt::wrap_main(code, std::move(args)); }); + kernel::actor::ActorCodeFactory code_factory = [code](std::vector args) { + return xbt::wrap_main(code, std::move(args)); + }; + register_function(name, std::move(code_factory)); } void Engine::register_default(int (*code)(int, char**)) // deprecated { @@ -100,23 +104,28 @@ void Engine::register_default(int (*code)(int, char**)) // deprecated } /** Registers the main function of an actor that will be launched from the deployment file */ -void Engine::register_function(const std::string& name, void (*code)(int, char**)) +void Engine::register_function(const std::string& name, const std::function& code) { - register_function(name, [code](std::vector args) { return xbt::wrap_main(code, std::move(args)); }); + kernel::actor::ActorCodeFactory code_factory = [code](std::vector args) { + return xbt::wrap_main(code, std::move(args)); + }; + register_function(name, std::move(code_factory)); } /** Registers the main function of an actor that will be launched from the deployment file */ -void Engine::register_function(const std::string& name, void (*code)(std::vector)) +void Engine::register_function(const std::string& name, const std::function)>& code) { - register_function(name, - [code](std::vector args) { return std::bind(std::move(code), std::move(args)); }); + kernel::actor::ActorCodeFactory code_factory = [code](std::vector args) { + return std::bind(std::move(code), std::move(args)); + }; + register_function(name, std::move(code_factory)); } /** Registers a function as the default main function of actors * * It will be used as fallback when the function requested from the deployment file was not registered. * It is used for trace-based simulations (see examples/s4u/replay-comms and similar). */ -void Engine::register_default(void (*code)(int, char**)) +void Engine::register_default(const std::function& code) { register_default([code](std::vector args) { return xbt::wrap_main(code, std::move(args)); }); } @@ -301,7 +310,6 @@ size_t Engine::get_actor_count() std::vector Engine::get_all_actors() { std::vector actor_list; - actor_list.push_back(simgrid::s4u::Actor::self()); for (auto const& kv : simix_global->process_list) { actor_list.push_back(kv.second->iface()); } @@ -401,6 +409,23 @@ void Engine::set_config(const std::string& str) { config::set_parse(str); } +void Engine::set_config(const std::string& name, int value) +{ + config::set_value(name.c_str(), value); +} +void Engine::set_config(const std::string& name, double value) +{ + config::set_value(name.c_str(), value); +} +void Engine::set_config(const std::string& name, bool value) +{ + config::set_value(name.c_str(), value); +} +void Engine::set_config(const std::string& name, const std::string& value) +{ + config::set_value(name.c_str(), value); +} + } // namespace s4u } // namespace simgrid @@ -434,7 +459,8 @@ double simgrid_get_clock() { return simgrid::s4u::Engine::get_clock(); } -int simgrid_get_actor_count() + +int simgrid_get_actor_count() // XBT_ATTRIB_DEPRECATED_v330 { return simgrid::s4u::Engine::get_instance()->get_actor_count(); }