Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No more need of these ones...
[simgrid.git] / src / msg / deployment.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
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. */
7
8 #include"private.h"
9 #include"xbt/sysdep.h"
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)");
14
15 extern char *yytext;
16
17
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;
22
23 static void parse_process_init(void)
24 {
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);
29   parse_argc = 0 ;
30   parse_argv = NULL;
31   parse_argc++;
32   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
33   parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
34 }
35
36 static void parse_argument(void)
37 {
38   parse_argc++;
39   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
40   parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
41 }
42
43 static void parse_process_finalize(void)
44 {
45   MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
46                                     parse_argc,parse_argv);
47 }
48
49 /** \ingroup msg_easier_life
50  * \brief An application deployer.
51  *
52  * Creates the process described in \a file.
53  * @param file a file containing an XML description of the application.
54  */
55 void MSG_launch_application(const char *file) 
56 {
57   MSG_global_init();
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);
63   surf_parse_lex();
64   surf_parse_close();
65 }
66
67 /** \ingroup msg_easier_life
68  * \brief Registers a ::m_process_code_t code in a global table.
69  *
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
74  */
75 void MSG_function_register(const char *name,m_process_code_t code)
76 {
77   MSG_global_init();
78
79   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
80 }
81
82 /** \ingroup msg_easier_life
83  * \brief Registers a ::m_process_t code in a global table.
84  *
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.
88  */
89 m_process_code_t MSG_get_registered_function(const char *name)
90 {
91   m_process_code_t code = NULL;
92
93   MSG_global_init();
94  
95   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
96
97   return code;
98 }
99
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[])}
103  *
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
108  */
109 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
110 {
111   m_process_t process = MSG_process_self();
112   simdata_process_t simdata = NULL;
113
114   xbt_assert0((argc) && (argv), "Invalid parameters");
115   simdata = process->simdata;
116   *argc = simdata->argc;
117   *argv = simdata->argv;
118
119   return MSG_OK;
120 }
121
122 /** \ingroup msg_easier_life
123  * \brief Set the arguments of a process.
124  *
125  * This functions sets the argument number and the arguments table for a
126  * proces.
127  * \param process is the process you want to modify
128  * \param argc the number of arguments
129  * \param argv the arguments table
130  */
131 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
132 {
133   simdata_process_t simdata = NULL;
134
135   xbt_assert0(0,"Deprecated ! Do not use anymore. "
136               "Use MSG_process_create_with_arguments instead.\n");
137
138   return MSG_OK;
139 }
140