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 "surf/surfxml_parse.h"
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)
20 surf_parse_reset_callbacks();
24 * \brief An application deployer.
26 * Creates the process described in \a file.
27 * \param file a filename of a xml description of the application. This file
30 * \include surfxml.dtd
32 * Here is a small example of such a platform
34 * \include small_deployment.xml
37 void SIMIX_launch_application(const char *file)
39 XBT_ATTRIB_UNUSED int parse_status;
40 xbt_assert(simix_global,
41 "SIMIX_global_init has to be called before SIMIX_launch_application.");
43 SIMIX_init_application();
45 surf_parse_open(file);
47 parse_status = surf_parse();
49 xbt_assert(!parse_status, "Parse error at %s:%d", file,surf_parse_lineno);
52 XBT_ERROR("Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
53 file, surf_parse_lineno);
59 * \brief Registers a #smx_process_code_t code in a global table.
61 * Registers a code function in a global table.
62 * This table is then used by #SIMIX_launch_application.
63 * \param name the reference name of the function.
64 * \param code the function
66 XBT_INLINE void SIMIX_function_register(const char *name,
69 xbt_assert(simix_global,
70 "SIMIX_global_init has to be called before SIMIX_function_register.");
72 xbt_dict_set(simix_global->registered_functions, name, code, NULL);
75 static xbt_main_func_t default_function = NULL;
77 * \brief Registers a #smx_process_code_t code as default value.
79 * 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.
80 * \param code the function
82 void SIMIX_function_register_default(xbt_main_func_t code)
84 xbt_assert(simix_global,
85 "SIMIX_global_init has to be called before SIMIX_function_register.");
87 default_function = code;
91 * \brief Gets a #smx_process_t code from the global table.
93 * Gets a code function from the global table. Returns NULL if there are no function registered with the name.
94 * This table is then used by #SIMIX_launch_application.
95 * \param name the reference name of the function.
96 * \return The #smx_process_t or NULL.
98 xbt_main_func_t SIMIX_get_registered_function(const char *name)
100 xbt_main_func_t res = NULL;
101 xbt_assert(simix_global,
102 "SIMIX_global_init has to be called before SIMIX_get_registered_function.");
104 res = (xbt_main_func_t)xbt_dict_get_or_null(simix_global->registered_functions, name);
105 return res ? res : default_function;
110 * \brief Bypass the parser, get arguments, and set function to each process
113 void SIMIX_process_set_function(const char *process_host,
114 const char *process_function,
115 xbt_dynar_t arguments,
116 double process_start_time,
117 double process_kill_time)
119 s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER;
121 sg_host_t host = sg_host_by_name(process_host);
123 THROWF(arg_error, 0, "Host '%s' unknown", process_host);
124 process.host = sg_host_get_name(host);
126 process.argc = 1 + xbt_dynar_length(arguments);
127 process.argv = (const char**)xbt_new(char *, process.argc + 1);
128 process.argv[0] = xbt_strdup(process_function);
132 xbt_dynar_foreach(arguments, i, arg) {
133 process.argv[i + 1] = xbt_strdup(arg);
135 process.argv[process.argc] = NULL;
137 xbt_main_func_t parse_code = SIMIX_get_registered_function(process_function);
138 xbt_assert(parse_code, "Function '%s' unknown", process_function);
139 process.function = process_function;
141 process.host = process_host;
142 process.kill_time = process_kill_time;
143 process.start_time = process_start_time;
145 sg_platf_new_process(&process);