3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/error.h"
11 #include "surf/surf_parse.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(deployment, msg,
13 "Logging specific to MSG (environment)");
18 static int parse_argc = -1 ;
19 static char **parse_argv = NULL;
20 static m_process_code_t parse_code = NULL;
21 static m_host_t parse_host = NULL;
23 static void parse_process_init(void)
25 parse_host = MSG_get_host_by_name(A_process_host);
26 xbt_assert1(parse_host, "Unknown host %s",A_process_host);
27 parse_code = MSG_get_registered_function(A_process_function);
28 xbt_assert1(parse_code, "Unknown function %s",A_process_function);
32 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
33 parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
36 static void parse_argument(void)
39 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
40 parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
43 static void parse_process_finalize(void)
45 MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
46 parse_argc,parse_argv);
49 /** \ingroup msg_easier_life
50 * \brief An application deployer.
52 * Creates the process described in \a file.
53 * @param file a file containing an XML description of the application.
55 void MSG_launch_application(const char *file)
58 surf_parse_reset_parser();
59 STag_process_fun = parse_process_init;
60 ETag_argument_fun = parse_argument;
61 ETag_process_fun = parse_process_finalize;
62 surf_parse_open(file);
67 /** \ingroup msg_easier_life
68 * \brief Registers a ::m_process_code_t code in a global table.
70 * Registers a code function in a global table.
71 * This table is then used by ::MSG_launch_application.
72 * \param name the reference name of the function.
73 * \param code the function
75 void MSG_function_register(const char *name,m_process_code_t code)
79 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
82 /** \ingroup msg_easier_life
83 * \brief Registers a ::m_process_t code in a global table.
85 * Registers a code function in a global table.
86 * This table is then used by ::MSG_launch_application.
87 * \param name the reference name of the function.
89 m_process_code_t MSG_get_registered_function(const char *name)
91 m_process_code_t code = NULL;
95 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
100 /** \ingroup msg_easier_life
101 * \brief Get the arguments of the current process.
102 * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])}
104 * This functions returns the values set for the current process
105 * using ::MSG_set_arguments or ::MSG_launch_application.
106 * \param argc the number of arguments
107 * \param argv the arguments table
109 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
111 m_process_t process = MSG_process_self();
112 simdata_process_t simdata = NULL;
114 xbt_assert0((argc) && (argv), "Invalid parameters");
115 simdata = process->simdata;
116 *argc = simdata->argc;
117 *argv = simdata->argv;
122 /** \ingroup msg_easier_life
123 * \brief Set the arguments of a process.
125 * This functions sets the argument number and the arguments table for a
127 * \param process is the process you want to modify
128 * \param argc the number of arguments
129 * \param argv the arguments table
131 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
133 simdata_process_t simdata = NULL;
135 xbt_assert0(0,"Deprecated ! Do not use anymore. "
136 "Use MSG_process_create_with_arguments instead.\n");