Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No need to rebuild the parser if you're not a maintainer.
[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 filename of a xml description of the application. This file 
51  * follows this DTD :
52  *
53  *     \include surfxml.dtd
54  *
55  * Here is a small example of such a platform 
56  *
57  *     \include small_deployment.xml
58  *
59  * Have a look in the directory examples/msg/ to have a bigger example.
60  */
61 void MSG_launch_application(const char *file) 
62 {
63   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
64   STag_process_fun = parse_process_init;
65   ETag_argument_fun = parse_argument;
66   ETag_process_fun = parse_process_finalize;
67   surf_parse_open(file);
68   xbt_assert1((!surf_parse()),"Parse error in %s",file);
69   surf_parse_close();
70 }
71
72 /** \ingroup msg_easier_life
73  * \brief Registers a #m_process_code_t code in a global table.
74  *
75  * Registers a code function in a global table. 
76  * This table is then used by #MSG_launch_application. 
77  * \param name the reference name of the function.
78  * \param code the function
79  */
80 void MSG_function_register(const char *name,m_process_code_t code)
81 {
82   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
83
84   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
85 }
86
87 /** \ingroup msg_easier_life
88  * \brief Registers a #m_process_t code in a global table.
89  *
90  * Registers a code function in a global table. 
91  * This table is then used by #MSG_launch_application. 
92  * \param name the reference name of the function.
93  */
94 m_process_code_t MSG_get_registered_function(const char *name)
95 {
96   m_process_code_t code = NULL;
97
98   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
99  
100   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
101
102   return code;
103 }
104
105 /** \ingroup msg_easier_life
106  * \brief Get the arguments of the current process.
107  * \deprecated{Not useful since #m_process_code_t is int (*)(int argc, char *argv[])}
108  *
109  * This functions returns the values set for the current process 
110  * using #MSG_set_arguments or #MSG_launch_application.
111  * \param argc the number of arguments
112  * \param argv the arguments table
113  */
114 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
115 {
116   m_process_t process = MSG_process_self();
117   simdata_process_t simdata = NULL;
118
119   xbt_assert0((argc) && (argv), "Invalid parameters");
120   simdata = process->simdata;
121   *argc = simdata->argc;
122   *argv = simdata->argv;
123
124   return MSG_OK;
125 }
126
127 /** \ingroup msg_easier_life
128  * \brief Set the arguments of a process.
129  *
130  * This functions sets the argument number and the arguments table for a
131  * proces.
132  * \param process is the process you want to modify
133  * \param argc the number of arguments
134  * \param argv the arguments table
135  */
136 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
137 {
138   simdata_process_t simdata = NULL;
139
140   xbt_assert0(0,"Deprecated ! Do not use anymore. "
141               "Use MSG_process_create_with_arguments instead.\n");
142
143   return MSG_OK;
144 }
145