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)");
15 static int parse_argc = -1 ;
16 static char **parse_argv = NULL;
17 static m_process_code_t parse_code = NULL;
18 static m_host_t parse_host = NULL;
20 static void parse_process_init(void)
22 parse_host = MSG_get_host_by_name(A_process_host);
23 xbt_assert1(parse_host, "Unknown host %s",A_process_host);
24 parse_code = MSG_get_registered_function(A_process_function);
25 xbt_assert1(parse_code, "Unknown function %s",A_process_function);
29 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
30 parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
33 static void parse_argument(void)
36 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
37 parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
40 static void parse_process_finalize(void)
42 MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
43 parse_argc,parse_argv);
46 /** \ingroup msg_easier_life
47 * \brief An application deployer.
49 * Creates the process described in \a file.
50 * @param file a file containing an XML description of the application.
52 void MSG_launch_application(const char *file)
54 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
55 STag_process_fun = parse_process_init;
56 ETag_argument_fun = parse_argument;
57 ETag_process_fun = parse_process_finalize;
58 surf_parse_open(file);
59 xbt_assert1((!surf_parse()),"Parse error in %s",file);
63 /** \ingroup msg_easier_life
64 * \brief Registers a #m_process_code_t code in a global table.
66 * Registers a code function in a global table.
67 * This table is then used by #MSG_launch_application.
68 * \param name the reference name of the function.
69 * \param code the function
71 void MSG_function_register(const char *name,m_process_code_t code)
73 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
75 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
78 /** \ingroup msg_easier_life
79 * \brief Registers a #m_process_t code in a global table.
81 * Registers a code function in a global table.
82 * This table is then used by #MSG_launch_application.
83 * \param name the reference name of the function.
85 m_process_code_t MSG_get_registered_function(const char *name)
87 m_process_code_t code = NULL;
89 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
91 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
96 /** \ingroup msg_easier_life
97 * \brief Get the arguments of the current process.
98 * \deprecated{Not useful since #m_process_code_t is int (*)(int argc, char *argv[])}
100 * This functions returns the values set for the current process
101 * using #MSG_set_arguments or #MSG_launch_application.
102 * \param argc the number of arguments
103 * \param argv the arguments table
105 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
107 m_process_t process = MSG_process_self();
108 simdata_process_t simdata = NULL;
110 xbt_assert0((argc) && (argv), "Invalid parameters");
111 simdata = process->simdata;
112 *argc = simdata->argc;
113 *argv = simdata->argv;
118 /** \ingroup msg_easier_life
119 * \brief Set the arguments of a process.
121 * This functions sets the argument number and the arguments table for a
123 * \param process is the process you want to modify
124 * \param argc the number of arguments
125 * \param argv the arguments table
127 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
129 simdata_process_t simdata = NULL;
131 xbt_assert0(0,"Deprecated ! Do not use anymore. "
132 "Use MSG_process_create_with_arguments instead.\n");