1 /* Copyright (c) 2007, 2009-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smx_private.h"
8 #include "xbt/sysdep.h"
11 #include "src/surf/xml/platf_private.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix,
14 "Logging specific to SIMIX (deployment)");
16 extern int surf_parse_lineno;
18 void SIMIX_init_application(void)
25 * \brief An application deployer.
27 * Creates the process described in \a file.
28 * \param file a filename of a xml description of the application. This file
31 * \include surfxml.dtd
33 * Here is a small example of such a platform
35 * \include small_deployment.xml
38 void SIMIX_launch_application(const char *file)
40 XBT_ATTRIB_UNUSED int parse_status;
41 xbt_assert(simix_global,
42 "SIMIX_global_init has to be called before SIMIX_launch_application.");
44 SIMIX_init_application();
46 surf_parse_open(file);
48 parse_status = surf_parse();
50 xbt_assert(!parse_status, "Parse error at %s:%d", file,surf_parse_lineno);
53 XBT_ERROR("Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
54 file, surf_parse_lineno);
60 * \brief Registers a #smx_process_code_t code in a global table.
62 * Registers a code function in a global table.
63 * This table is then used by #SIMIX_launch_application.
64 * \param name the reference name of the function.
65 * \param code the function
67 void SIMIX_function_register(const char *name, xbt_main_func_t code)
69 xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_function_register.");
70 xbt_dict_set(simix_global->registered_functions, name, (void*) code, NULL);
73 static xbt_main_func_t default_function = NULL;
75 * \brief Registers a #smx_process_code_t code as default value.
77 * Registers a code function as being the default value. This function will get used by SIMIX_launch_application() when there is no registered function of the requested name in.
78 * \param code the function
80 void SIMIX_function_register_default(xbt_main_func_t code)
82 xbt_assert(simix_global,
83 "SIMIX_global_init has to be called before SIMIX_function_register.");
85 default_function = code;
89 * \brief Gets a #smx_process_t code from the global table.
91 * Gets a code function from the global table. Returns NULL if there are no function registered with the name.
92 * This table is then used by #SIMIX_launch_application.
93 * \param name the reference name of the function.
94 * \return The #smx_process_t or NULL.
96 xbt_main_func_t SIMIX_get_registered_function(const char *name)
98 xbt_main_func_t res = NULL;
99 xbt_assert(simix_global,
100 "SIMIX_global_init has to be called before SIMIX_get_registered_function.");
102 res = (xbt_main_func_t)xbt_dict_get_or_null(simix_global->registered_functions, name);
103 return res ? res : default_function;
108 * \brief Bypass the parser, get arguments, and set function to each process
111 void SIMIX_process_set_function(const char *process_host,
112 const char *process_function,
113 xbt_dynar_t arguments,
114 double process_start_time,
115 double process_kill_time)
117 s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER;
119 sg_host_t host = sg_host_by_name(process_host);
121 THROWF(arg_error, 0, "Host '%s' unknown", process_host);
122 process.host = sg_host_get_name(host);
124 process.argc = 1 + xbt_dynar_length(arguments);
125 process.argv = (const char**)xbt_new(char *, process.argc + 1);
126 process.argv[0] = xbt_strdup(process_function);
130 xbt_dynar_foreach(arguments, i, arg) {
131 process.argv[i + 1] = xbt_strdup(arg);
133 process.argv[process.argc] = NULL;
135 xbt_main_func_t parse_code = SIMIX_get_registered_function(process_function);
136 xbt_assert(parse_code, "Function '%s' unknown", process_function);
137 process.function = process_function;
139 process.host = process_host;
140 process.kill_time = process_kill_time;
141 process.start_time = process_start_time;
143 sg_platf_new_process(&process);