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)
57 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
58 STag_process_fun = parse_process_init;
59 ETag_argument_fun = parse_argument;
60 ETag_process_fun = parse_process_finalize;
61 surf_parse_open(file);
62 xbt_assert1((!surf_parse()),"Parse error in %s",file);
66 /** \ingroup msg_easier_life
67 * \brief Registers a ::m_process_code_t code in a global table.
69 * Registers a code function in a global table.
70 * This table is then used by ::MSG_launch_application.
71 * \param name the reference name of the function.
72 * \param code the function
74 void MSG_function_register(const char *name,m_process_code_t code)
76 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
78 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
81 /** \ingroup msg_easier_life
82 * \brief Registers a ::m_process_t code in a global table.
84 * Registers a code function in a global table.
85 * This table is then used by ::MSG_launch_application.
86 * \param name the reference name of the function.
88 m_process_code_t MSG_get_registered_function(const char *name)
90 m_process_code_t code = NULL;
92 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
94 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
99 /** \ingroup msg_easier_life
100 * \brief Get the arguments of the current process.
101 * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])}
103 * This functions returns the values set for the current process
104 * using ::MSG_set_arguments or ::MSG_launch_application.
105 * \param argc the number of arguments
106 * \param argv the arguments table
108 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
110 m_process_t process = MSG_process_self();
111 simdata_process_t simdata = NULL;
113 xbt_assert0((argc) && (argv), "Invalid parameters");
114 simdata = process->simdata;
115 *argc = simdata->argc;
116 *argv = simdata->argv;
121 /** \ingroup msg_easier_life
122 * \brief Set the arguments of a process.
124 * This functions sets the argument number and the arguments table for a
126 * \param process is the process you want to modify
127 * \param argc the number of arguments
128 * \param argv the arguments table
130 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
132 simdata_process_t simdata = NULL;
134 xbt_assert0(0,"Deprecated ! Do not use anymore. "
135 "Use MSG_process_create_with_arguments instead.\n");