Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update the double extern declaration bis
[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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_deployment, msg,
14                                 "Logging specific to MSG (deployment)");
15
16 static int parse_argc = -1 ;
17 static char **parse_argv = NULL;
18 static m_process_code_t parse_code = NULL;
19 static m_host_t parse_host = NULL;
20 static double start_time = 0.0;
21 static double kill_time = -1.0;
22   
23 static void parse_process_init(void)
24 {
25   parse_host = MSG_get_host_by_name(A_surfxml_process_host);
26   xbt_assert1(parse_host, "Unknown host %s",A_surfxml_process_host);
27   parse_code = MSG_get_registered_function(A_surfxml_process_function);
28   xbt_assert1(parse_code, "Unknown function %s",A_surfxml_process_function);
29   parse_argc = 0 ;
30   parse_argv = NULL;
31   parse_argc++;
32   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
33   parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_process_function);
34   surf_parse_get_double(&start_time,A_surfxml_process_start_time);
35   surf_parse_get_double(&kill_time,A_surfxml_process_kill_time);
36 }
37
38 static void parse_argument(void)
39 {
40   parse_argc++;
41   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
42   parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_argument_value);
43 }
44
45 static void parse_process_finalize(void)
46 {
47   process_arg_t arg = NULL;
48   m_process_t process = NULL;
49   if(start_time>MSG_get_clock()) {
50     arg = xbt_new0(s_process_arg_t,1);
51     arg->name = parse_argv[0];
52     arg->code = parse_code;
53     arg->data = NULL;
54     arg->host = parse_host;
55     arg->argc = parse_argc;
56     arg->argv = parse_argv;
57     arg-> kill_time = kill_time;
58
59     DEBUG3("Process %s(%s) will be started at time %f", arg->name, 
60            arg->host->name,start_time);
61     surf_timer_resource->extension_public->set(start_time, (void*) &MSG_process_create_with_arguments,
62                                                arg);
63   }
64   if((start_time<0) || (start_time==MSG_get_clock())) {
65     DEBUG2("Starting Process %s(%s) right now", parse_argv[0],
66            parse_host->name);
67     process = MSG_process_create_with_arguments(parse_argv[0], parse_code, 
68                                                 NULL, parse_host,
69                                                 parse_argc,parse_argv);
70     if(kill_time > MSG_get_clock()) {
71       surf_timer_resource->extension_public->set(kill_time, 
72                                                  (void*) &MSG_process_kill,
73                                                  (void*) process);
74     }
75   }
76 }
77
78 /** \ingroup msg_easier_life
79  * \brief An application deployer.
80  *
81  * Creates the process described in \a file.
82  * \param file a filename of a xml description of the application. This file 
83  * follows this DTD :
84  *
85  *     \include surfxml.dtd
86  *
87  * Here is a small example of such a platform 
88  *
89  *     \include small_deployment.xml
90  *
91  * Have a look in the directory examples/msg/ to have a bigger example.
92  */
93 void MSG_launch_application(const char *file) 
94 {
95   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
96   STag_surfxml_process_fun = parse_process_init;
97   ETag_surfxml_argument_fun = parse_argument;
98   ETag_surfxml_process_fun = parse_process_finalize;
99   surf_parse_open(file);
100   xbt_assert1((!surf_parse()),"Parse error in %s",file);
101   surf_parse_close();
102 }
103
104 /** \ingroup msg_easier_life
105  * \brief Registers a #m_process_code_t code in a global table.
106  *
107  * Registers a code function in a global table. 
108  * This table is then used by #MSG_launch_application. 
109  * \param name the reference name of the function.
110  * \param code the function
111  */
112 void MSG_function_register(const char *name,m_process_code_t code)
113 {
114   xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_function_register.");
115
116   xbt_dict_set(msg_global->registered_functions,name,code,NULL);
117 }
118
119 /** \ingroup msg_easier_life
120  * \brief Registers a #m_process_t code in a global table.
121  *
122  * Registers a code function in a global table. 
123  * This table is then used by #MSG_launch_application. 
124  * \param name the reference name of the function.
125  */
126 m_process_code_t MSG_get_registered_function(const char *name)
127 {
128   m_process_code_t code = NULL;
129
130   xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_get_registered_function.");
131
132   code = xbt_dict_get_or_null(msg_global->registered_functions,name);
133
134   return code;
135 }
136