Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv surf_parse -> surfxml_parse
[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/log.h"
11 #include "surf/surfxml_parse_private.h"
12
13 static int parse_argc = -1 ;
14 static char **parse_argv = NULL;
15 static m_process_code_t parse_code = NULL;
16 static m_host_t parse_host = NULL;
17 static double start_time = 0.0;
18 static double kill_time = -1.0;
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   surf_parse_get_double(&start_time,A_process_start_time);
32   surf_parse_get_double(&kill_time,A_process_kill_time);
33 }
34
35 static void parse_argument(void)
36 {
37   parse_argc++;
38   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
39   parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
40 }
41
42 static void parse_process_finalize(void)
43 {
44   process_arg_t arg = NULL;
45   m_process_t process = NULL;
46   if(start_time>MSG_get_clock()) {
47     arg = xbt_new0(s_process_arg_t,1);
48     arg->name = parse_argv[0];
49     arg->code = parse_code;
50     arg->data = NULL;
51     arg->host = parse_host;
52     arg->argc = parse_argc;
53     arg->argv = parse_argv;
54     arg-> kill_time = kill_time;
55
56     surf_timer_resource->extension_public->set(start_time, (void*) &MSG_process_create_with_arguments,
57                                                arg);
58   }
59   if((start_time<0) || (start_time==MSG_get_clock())) {
60     process = MSG_process_create_with_arguments(parse_argv[0], parse_code, 
61                                                 NULL, parse_host,
62                                                 parse_argc,parse_argv);
63     if(kill_time > MSG_get_clock()) {
64       surf_timer_resource->extension_public->set(kill_time, 
65                                                  (void*) &MSG_process_kill,
66                                                  (void*) process);
67     }
68   }
69 }
70
71 /** \ingroup msg_easier_life
72  * \brief An application deployer.
73  *
74  * Creates the process described in \a file.
75  * \param file a filename of a xml description of the application. This file 
76  * follows this DTD :
77  *
78  *     \include surfxml.dtd
79  *
80  * Here is a small example of such a platform 
81  *
82  *     \include small_deployment.xml
83  *
84  * Have a look in the directory examples/msg/ to have a bigger example.
85  */
86 void MSG_launch_application(const char *file) 
87 {
88   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
89   STag_process_fun = parse_process_init;
90   ETag_argument_fun = parse_argument;
91   ETag_process_fun = parse_process_finalize;
92   surf_parse_open(file);
93   xbt_assert1((!surf_parse()),"Parse error in %s",file);
94   surf_parse_close();
95 }
96
97 /** \ingroup msg_easier_life
98  * \brief Registers a #m_process_code_t code in a global table.
99  *
100  * Registers a code function in a global table. 
101  * This table is then used by #MSG_launch_application. 
102  * \param name the reference name of the function.
103  * \param code the function
104  */
105 void MSG_function_register(const char *name,m_process_code_t code)
106 {
107   xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_function_register.");
108
109   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
110 }
111
112 /** \ingroup msg_easier_life
113  * \brief Registers a #m_process_t code in a global table.
114  *
115  * Registers a code function in a global table. 
116  * This table is then used by #MSG_launch_application. 
117  * \param name the reference name of the function.
118  */
119 m_process_code_t MSG_get_registered_function(const char *name)
120 {
121   m_process_code_t code = NULL;
122
123   xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_get_registered_function.");
124
125   code = xbt_dict_get_or_null(msg_global->registered_functions,name);
126
127   return code;
128 }
129