Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
moving include/surf to src/include/surf (continued)
[simgrid.git] / src / msg / deployment.c
index 2e792b9..4f61e3a 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(deployment, msg,
                                "Logging specific to MSG (environment)");
 
-extern char *yytext;
+static int parse_argc = -1 ;
+static char **parse_argv = NULL;
+static m_process_code_t parse_code = NULL;
+static m_host_t parse_host = NULL;
 
+static void parse_process_init(void)
+{
+  parse_host = MSG_get_host_by_name(A_process_host);
+  xbt_assert1(parse_host, "Unknown host %s",A_process_host);
+  parse_code = MSG_get_registered_function(A_process_function);
+  xbt_assert1(parse_code, "Unknown function %s",A_process_function);
+  parse_argc = 0 ;
+  parse_argv = NULL;
+  parse_argc++;
+  parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
+  parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
+}
+
+static void parse_argument(void)
+{
+  parse_argc++;
+  parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
+  parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
+}
+
+static void parse_process_finalize(void)
+{
+  MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
+                                   parse_argc,parse_argv);
+}
 
 /** \ingroup msg_easier_life
  * \brief An application deployer.
  *
  * Creates the process described in \a file.
- * @param file a file containing a simple description of the application.
- * The format of each line is the following : host_name function_name arguments
- * You can use C-style comments and C-style strings.
- * Here is a simple exemple
- * 
- \verbatim
-<DEPLOYMENT>
- // Here is the master
- the-doors.ens-lyon.fr  master "moby.cri2000.ens-lyon.fr" canaria.ens-lyon.fr popc.ens-lyon.fr
- // And here are the slaves
- moby.cri2000.ens-lyon.fr slave
- canaria.ens-lyon.fr slave
- popc.ens-lyon.fr slave 
-</DEPLOYMENT>
-\endverbatim
+ * \param file a filename of a xml description of the application. This file 
+ * follows this DTD :
+ *
+ *     \include surfxml.dtd
+ *
+ * Here is a small example of such a platform 
+ *
+ *     \include small_deployment.xml
+ *
+ * Have a look in the directory examples/msg/ to have a bigger example.
  */
 void MSG_launch_application(const char *file) 
 {
-  char *host_name = NULL;
-  int argc = 0 ;
-  char **argv = NULL;
-  m_process_t process = NULL ;
-  m_host_t host = NULL;
-  m_process_code_t code = NULL;
-  e_surf_token_t token;
-
-  MSG_global_init();
-  
-  find_section(file, "DEPLOYMENT");
-
-  while(1) {
-    token = surf_parse();
-
-    if (token == TOKEN_END_SECTION)
-      break;
-    if (token == TOKEN_NEWLINE)
-      continue;
-
-    if (token == TOKEN_WORD) {
-      surf_parse_deployment_line(&host_name,&argc,&argv);
-      xbt_assert0(argc,"No function to execute");
-
-      code = MSG_get_registered_function(argv[0]);
-      xbt_assert1(code, "Unknown function %s",argv[0]);
-
-      host = MSG_get_host_by_name(host_name);
-      xbt_assert1(host_name, "Unknown host %s",host_name);
-
-     process = MSG_process_create(argv[0], code, NULL, host);
-     MSG_set_arguments(process, argc, argv);
-     xbt_free(host_name); 
-    }
-    else {
-      CRITICAL1("Parse error line %d\n", surf_line_pos);
-      xbt_abort();
-    }
-  }
-
-  close_section("CPU");
+  xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
+  STag_process_fun = parse_process_init;
+  ETag_argument_fun = parse_argument;
+  ETag_process_fun = parse_process_finalize;
+  surf_parse_open(file);
+  xbt_assert1((!surf_parse()),"Parse error in %s",file);
+  surf_parse_close();
 }
 
 /** \ingroup msg_easier_life
- * \brief Registers a ::m_process_code_t code in a global table.
+ * \brief Registers a #m_process_code_t code in a global table.
  *
  * Registers a code function in a global table. 
- * This table is then used by ::MSG_launch_application. 
+ * This table is then used by #MSG_launch_application. 
  * \param name the reference name of the function.
  * \param code the function
  */
 void MSG_function_register(const char *name,m_process_code_t code)
 {
-  MSG_global_init();
+  xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
 
   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
 }
 
 /** \ingroup msg_easier_life
- * \brief Registers a ::m_process_t code in a global table.
+ * \brief Registers a #m_process_t code in a global table.
  *
  * Registers a code function in a global table. 
- * This table is then used by ::MSG_launch_application. 
+ * This table is then used by #MSG_launch_application. 
  * \param name the reference name of the function.
  */
 m_process_code_t MSG_get_registered_function(const char *name)
 {
   m_process_code_t code = NULL;
 
-  MSG_global_init();
+  xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
  
   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
 
@@ -115,10 +104,10 @@ m_process_code_t MSG_get_registered_function(const char *name)
 
 /** \ingroup msg_easier_life
  * \brief Get the arguments of the current process.
- * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])}
+ * \deprecated{Not useful since #m_process_code_t is int (*)(int argc, char *argv[])}
  *
  * This functions returns the values set for the current process 
- * using ::MSG_set_arguments or ::MSG_launch_application.
+ * using #MSG_set_arguments or #MSG_launch_application.
  * \param argc the number of arguments
  * \param argv the arguments table
  */
@@ -148,10 +137,9 @@ MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
 {
   simdata_process_t simdata = NULL;
 
-  xbt_assert0((process) && (process->simdata), "Invalid parameters");
-  simdata = process->simdata;
-  simdata->argc = argc;
-  simdata->argv = argv;
+  xbt_assert0(0,"Deprecated ! Do not use anymore. "
+             "Use MSG_process_create_with_arguments instead.\n");
+
   return MSG_OK;
 }