Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
updating the doc
[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 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;
19
20 static void parse_process_init(void)
21 {
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);
26   parse_argc = 0 ;
27   parse_argv = NULL;
28   parse_argc++;
29   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
30   parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
31 }
32
33 static void parse_argument(void)
34 {
35   parse_argc++;
36   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
37   parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
38 }
39
40 static void parse_process_finalize(void)
41 {
42   MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
43                                     parse_argc,parse_argv);
44 }
45
46 /** \ingroup msg_easier_life
47  * \brief An application deployer.
48  *
49  * Creates the process described in \a file.
50  * @param file a file containing an XML description of the application.
51  */
52 void MSG_launch_application(const char *file) 
53 {
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);
60   surf_parse_close();
61 }
62
63 /** \ingroup msg_easier_life
64  * \brief Registers a #m_process_code_t code in a global table.
65  *
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
70  */
71 void MSG_function_register(const char *name,m_process_code_t code)
72 {
73   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
74
75   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
76 }
77
78 /** \ingroup msg_easier_life
79  * \brief Registers a #m_process_t code in a global table.
80  *
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.
84  */
85 m_process_code_t MSG_get_registered_function(const char *name)
86 {
87   m_process_code_t code = NULL;
88
89   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
90  
91   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
92
93   return code;
94 }
95
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[])}
99  *
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
104  */
105 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
106 {
107   m_process_t process = MSG_process_self();
108   simdata_process_t simdata = NULL;
109
110   xbt_assert0((argc) && (argv), "Invalid parameters");
111   simdata = process->simdata;
112   *argc = simdata->argc;
113   *argv = simdata->argv;
114
115   return MSG_OK;
116 }
117
118 /** \ingroup msg_easier_life
119  * \brief Set the arguments of a process.
120  *
121  * This functions sets the argument number and the arguments table for a
122  * proces.
123  * \param process is the process you want to modify
124  * \param argc the number of arguments
125  * \param argv the arguments table
126  */
127 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
128 {
129   simdata_process_t simdata = NULL;
130
131   xbt_assert0(0,"Deprecated ! Do not use anymore. "
132               "Use MSG_process_create_with_arguments instead.\n");
133
134   return MSG_OK;
135 }
136