Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
an hexadecimal printer I sometime use for debugging
[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 static double start_time = 0.0;
20 static double kill_time = -1.0;
21   
22 static void parse_process_init(void)
23 {
24   parse_host = MSG_get_host_by_name(A_process_host);
25   xbt_assert1(parse_host, "Unknown host %s",A_process_host);
26   parse_code = MSG_get_registered_function(A_process_function);
27   xbt_assert1(parse_code, "Unknown function %s",A_process_function);
28   parse_argc = 0 ;
29   parse_argv = NULL;
30   parse_argc++;
31   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
32   parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
33   surf_parse_get_double(&start_time,A_process_start_time);
34   surf_parse_get_double(&kill_time,A_process_kill_time);
35 }
36
37 static void parse_argument(void)
38 {
39   parse_argc++;
40   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
41   parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
42 }
43
44 static void parse_process_finalize(void)
45 {
46   MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
47                                     parse_argc,parse_argv,start_time,kill_time);
48 }
49
50 /** \ingroup msg_easier_life
51  * \brief An application deployer.
52  *
53  * Creates the process described in \a file.
54  * \param file a filename of a xml description of the application. This file 
55  * follows this DTD :
56  *
57  *     \include surfxml.dtd
58  *
59  * Here is a small example of such a platform 
60  *
61  *     \include small_deployment.xml
62  *
63  * Have a look in the directory examples/msg/ to have a bigger example.
64  */
65 void MSG_launch_application(const char *file) 
66 {
67   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
68   STag_process_fun = parse_process_init;
69   ETag_argument_fun = parse_argument;
70   ETag_process_fun = parse_process_finalize;
71   surf_parse_open(file);
72   xbt_assert1((!surf_parse()),"Parse error in %s",file);
73   surf_parse_close();
74 }
75
76 /** \ingroup msg_easier_life
77  * \brief Registers a #m_process_code_t code in a global table.
78  *
79  * Registers a code function in a global table. 
80  * This table is then used by #MSG_launch_application. 
81  * \param name the reference name of the function.
82  * \param code the function
83  */
84 void MSG_function_register(const char *name,m_process_code_t code)
85 {
86   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
87
88   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
89 }
90
91 /** \ingroup msg_easier_life
92  * \brief Registers a #m_process_t code in a global table.
93  *
94  * Registers a code function in a global table. 
95  * This table is then used by #MSG_launch_application. 
96  * \param name the reference name of the function.
97  */
98 m_process_code_t MSG_get_registered_function(const char *name)
99 {
100   m_process_code_t code = NULL;
101
102   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
103  
104   xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
105
106   return code;
107 }
108
109 /** \ingroup msg_easier_life
110  * \brief Get the arguments of the current process.
111  * \deprecated{Not useful since #m_process_code_t is int (*)(int argc, char *argv[])}
112  *
113  * This functions returns the values set for the current process 
114  * using #MSG_set_arguments or #MSG_launch_application.
115  * \param argc the number of arguments
116  * \param argv the arguments table
117  */
118 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
119 {
120   m_process_t process = MSG_process_self();
121   simdata_process_t simdata = NULL;
122
123   xbt_assert0((argc) && (argv), "Invalid parameters");
124   simdata = process->simdata;
125   *argc = simdata->argc;
126   *argv = simdata->argv;
127
128   return MSG_OK;
129 }
130
131 /** \ingroup msg_easier_life
132  * \brief Set the arguments of a process.
133  *
134  * This functions sets the argument number and the arguments table for a
135  * proces.
136  * \param process is the process you want to modify
137  * \param argc the number of arguments
138  * \param argv the arguments table
139  */
140 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
141 {
142   simdata_process_t simdata = NULL;
143
144   xbt_assert0(0,"Deprecated ! Do not use anymore. "
145               "Use MSG_process_create_with_arguments instead.\n");
146
147   return MSG_OK;
148 }
149