Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a function I need in GRAS
[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 /** \ingroup msg_easier_life
19  * \brief An application deployer.
20  *
21  * Creates the process described in \a file.
22  * @param file a file containing a simple description of the application.
23  * The format of each line is the following : host_name function_name arguments
24  * You can use C-style comments and C-style strings.
25  * Here is a simple exemple
26  * 
27  \verbatim
28 <DEPLOYMENT>
29  // Here is the master
30  the-doors.ens-lyon.fr  master "moby.cri2000.ens-lyon.fr" canaria.ens-lyon.fr popc.ens-lyon.fr
31  // And here are the slaves
32  moby.cri2000.ens-lyon.fr slave
33  canaria.ens-lyon.fr slave
34  popc.ens-lyon.fr slave 
35 </DEPLOYMENT>
36 \endverbatim
37  */
38 void MSG_launch_application(const char *file) 
39 {
40   char *host_name = NULL;
41   int argc = -1 ;
42   char **argv = NULL;
43   m_process_t process = NULL ;
44   m_host_t host = NULL;
45   m_process_code_t code = NULL;
46   e_surf_token_t token;
47
48   MSG_global_init();
49   
50   find_section(file, "DEPLOYMENT");
51
52   while(1) {
53     token = surf_parse();
54
55     if (token == TOKEN_END_SECTION)
56       break;
57     if (token == TOKEN_NEWLINE)
58       continue;
59
60     if (token == TOKEN_WORD) {
61       surf_parse_deployment_line(&host_name,&argc,&argv);
62       xbt_assert0(argc,"No function to execute");
63
64       code = MSG_get_registered_function(argv[0]);
65       xbt_assert1(code, "Unknown function %s",argv[0]);
66
67       host = MSG_get_host_by_name(host_name);
68       xbt_assert1(host, "Unknown host %s",host_name);
69
70       process = MSG_process_create_with_arguments(argv[0], code, NULL, host,argc,argv);
71       argc=-1;
72       argv=NULL;
73       xbt_free(host_name); 
74     }
75     else {
76       CRITICAL1("Parse error line %d\n", surf_line_pos);
77       xbt_abort();
78     }
79   }
80
81   close_section("DEPLOYMENT");
82 }
83
84 /** \ingroup msg_easier_life
85  * \brief Registers a ::m_process_code_t code in a global table.
86  *
87  * Registers a code function in a global table. 
88  * This table is then used by ::MSG_launch_application. 
89  * \param name the reference name of the function.
90  * \param code the function
91  */
92 void MSG_function_register(const char *name,m_process_code_t code)
93 {
94   MSG_global_init();
95
96   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
97 }
98
99 /** \ingroup msg_easier_life
100  * \brief Registers a ::m_process_t code in a global table.
101  *
102  * Registers a code function in a global table. 
103  * This table is then used by ::MSG_launch_application. 
104  * \param name the reference name of the function.
105  */
106 m_process_code_t MSG_get_registered_function(const char *name)
107 {
108   m_process_code_t code = NULL;
109
110   MSG_global_init();
111  
112   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
113
114   return code;
115 }
116
117 /** \ingroup msg_easier_life
118  * \brief Get the arguments of the current process.
119  * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])}
120  *
121  * This functions returns the values set for the current process 
122  * using ::MSG_set_arguments or ::MSG_launch_application.
123  * \param argc the number of arguments
124  * \param argv the arguments table
125  */
126 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
127 {
128   m_process_t process = MSG_process_self();
129   simdata_process_t simdata = NULL;
130
131   xbt_assert0((argc) && (argv), "Invalid parameters");
132   simdata = process->simdata;
133   *argc = simdata->argc;
134   *argv = simdata->argv;
135
136   return MSG_OK;
137 }
138
139 /** \ingroup msg_easier_life
140  * \brief Set the arguments of a process.
141  *
142  * This functions sets the argument number and the arguments table for a
143  * proces.
144  * \param process is the process you want to modify
145  * \param argc the number of arguments
146  * \param argv the arguments table
147  */
148 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
149 {
150   simdata_process_t simdata = NULL;
151
152   xbt_assert0(0,"Deprecated ! Do not use anymore. "
153               "Use MSG_process_create_with_arguments instead.\n");
154
155   return MSG_OK;
156 }
157