Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the API between Engine and EngineImpl when registering functions
[simgrid.git] / src / simix / smx_deployment.cpp
1 /* Copyright (c) 2007-2020. 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 #include "simgrid/s4u/Host.hpp"
7 #include "smx_private.hpp"
8 #include "src/kernel/EngineImpl.hpp"
9 #include "src/surf/xml/platf_private.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
10 #include <simgrid/engine.h>
11 #include <simgrid/s4u/Engine.hpp>
12
13 #include <string>
14 #include <vector>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix, "Logging specific to SIMIX (deployment)");
17
18 void SIMIX_init_application() // XBT_DEPRECATED_v329
19 {
20   sg_platf_exit();
21   sg_platf_init();
22 }
23
24 void SIMIX_launch_application(const std::string& file) // XBT_DEPRECATED_v329
25 {
26   simgrid_load_deployment(file.c_str());
27 }
28 void SIMIX_function_register(const std::string& name, xbt_main_func_t code) // XBT_DEPRECATED_v329
29 {
30   simgrid::s4u::Engine::get_instance()->register_function(name, code);
31 }
32 void SIMIX_function_register(const std::string& name, void (*code)(std::vector<std::string>)) // XBT_DEPRECATED_v329
33 {
34   simgrid::s4u::Engine::get_instance()->register_function(name, code);
35 }
36 void SIMIX_function_register_default(xbt_main_func_t code) // XBT_DEPRECATED_v329
37 {
38   simgrid::s4u::Engine::get_instance()->register_default(code);
39 }
40
41 /** @brief Bypass the parser, get arguments, and set function to each process */
42 void SIMIX_process_set_function(const char* process_host, const char* process_function, xbt_dynar_t arguments,
43                                 double process_start_time, double process_kill_time) // XBT_ATTRIB_DEPRECATED_v329
44 {
45   simgrid::kernel::routing::ActorCreationArgs actor;
46
47   const simgrid::s4u::Host* host = sg_host_by_name(process_host);
48   if (not host)
49     throw std::invalid_argument(simgrid::xbt::string_printf("Host '%s' unknown", process_host));
50   actor.host = process_host;
51   actor.args.push_back(process_function);
52   /* add arguments */
53   unsigned int i;
54   char *arg;
55   xbt_dynar_foreach(arguments, i, arg) {
56     actor.args.push_back(arg);
57   }
58
59   // Check we know how to handle this function name:
60   const simgrid::kernel::actor::ActorCodeFactory& parse_code =
61       simgrid::kernel::EngineImpl::get_instance()->get_function(process_function);
62   xbt_assert(parse_code, "Function '%s' unknown", process_function);
63
64   actor.function           = process_function;
65   actor.host               = process_host;
66   actor.kill_time          = process_kill_time;
67   actor.start_time         = process_start_time;
68   actor.restart_on_failure = false;
69   sg_platf_new_actor(&actor);
70 }