1 /* Copyright (c) 2007-2019. 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 #include "simgrid/s4u/Host.hpp"
7 #include "smx_private.hpp"
8 #include "src/surf/xml/platf_private.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
9 #include <simgrid/engine.h>
10 #include <simgrid/s4u/Engine.hpp>
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix, "Logging specific to SIMIX (deployment)");
17 void SIMIX_init_application() // XBT_DEPRECATED_v329
23 void SIMIX_launch_application(const std::string& file) // XBT_DEPRECATED_v329
25 simgrid_load_deployment(file.c_str());
27 void SIMIX_function_register(const std::string& name, xbt_main_func_t code) // XBT_DEPRECATED_v329
29 simgrid::s4u::Engine::get_instance()->register_function(name, code);
31 void SIMIX_function_register(const std::string& name, void (*code)(std::vector<std::string>)) // XBT_DEPRECATED_v329
33 simgrid::s4u::Engine::get_instance()->register_function(name, code);
35 void SIMIX_function_register_default(xbt_main_func_t code) // XBT_DEPRECATED_v329
37 simgrid::s4u::Engine::get_instance()->register_default(code);
41 * @brief Gets a #smx_actor_t code from the global table.
43 * Gets a code function from the global table. Returns nullptr if there are no function registered with the name.
44 * This table is then used by #SIMIX_launch_application.
45 * @param name the reference name of the function.
46 * @return The #smx_actor_t or nullptr.
48 simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(const std::string& name)
50 xbt_assert(simix_global,
51 "SIMIX_global_init has to be called before SIMIX_get_actor_code_factory.");
53 auto i = simix_global->registered_functions.find(name);
54 if (i == simix_global->registered_functions.end())
55 return simix_global->default_function;
60 /** @brief Bypass the parser, get arguments, and set function to each process */
62 void SIMIX_process_set_function(const char* process_host, const char* process_function, xbt_dynar_t arguments,
63 double process_start_time, double process_kill_time) // XBT_ATTRIB_DEPRECATED_v329
65 simgrid::kernel::routing::ActorCreationArgs actor;
67 const simgrid::s4u::Host* host = sg_host_by_name(process_host);
69 throw std::invalid_argument(simgrid::xbt::string_printf("Host '%s' unknown", process_host));
70 actor.host = process_host;
71 actor.args.push_back(process_function);
75 xbt_dynar_foreach(arguments, i, arg) {
76 actor.args.push_back(arg);
79 // Check we know how to handle this function name:
80 const simgrid::simix::ActorCodeFactory& parse_code = SIMIX_get_actor_code_factory(process_function);
81 xbt_assert(parse_code, "Function '%s' unknown", process_function);
83 actor.function = process_function;
84 actor.host = process_host;
85 actor.kill_time = process_kill_time;
86 actor.start_time = process_start_time;
87 actor.restart_on_failure = false;
88 sg_platf_new_actor(&actor);
94 void register_function(const std::string& name, const ActorCodeFactory& factory)
96 simix_global->registered_functions[name] = factory;