Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Using logs and making some message more clear.
[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   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);
63   surf_parse_close();
64 }
65
66 /** \ingroup msg_easier_life
67  * \brief Registers a ::m_process_code_t code in a global table.
68  *
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
73  */
74 void MSG_function_register(const char *name,m_process_code_t code)
75 {
76   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
77
78   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
79 }
80
81 /** \ingroup msg_easier_life
82  * \brief Registers a ::m_process_t code in a global table.
83  *
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.
87  */
88 m_process_code_t MSG_get_registered_function(const char *name)
89 {
90   m_process_code_t code = NULL;
91
92   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
93  
94   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
95
96   return code;
97 }
98
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[])}
102  *
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
107  */
108 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
109 {
110   m_process_t process = MSG_process_self();
111   simdata_process_t simdata = NULL;
112
113   xbt_assert0((argc) && (argv), "Invalid parameters");
114   simdata = process->simdata;
115   *argc = simdata->argc;
116   *argv = simdata->argv;
117
118   return MSG_OK;
119 }
120
121 /** \ingroup msg_easier_life
122  * \brief Set the arguments of a process.
123  *
124  * This functions sets the argument number and the arguments table for a
125  * proces.
126  * \param process is the process you want to modify
127  * \param argc the number of arguments
128  * \param argv the arguments table
129  */
130 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
131 {
132   simdata_process_t simdata = NULL;
133
134   xbt_assert0(0,"Deprecated ! Do not use anymore. "
135               "Use MSG_process_create_with_arguments instead.\n");
136
137   return MSG_OK;
138 }
139