3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
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. */
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)");
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;
22 static void parse_process_init(void)
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);
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);
37 static void parse_argument(void)
40 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
41 parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
44 static void parse_process_finalize(void)
46 process_arg_t arg = NULL;
47 m_process_t process = NULL;
48 if(start_time>MSG_get_clock()) {
49 arg = xbt_new0(s_process_arg_t,1);
50 arg->name = parse_argv[0];
51 arg->code = parse_code;
53 arg->host = parse_host;
54 arg->argc = parse_argc;
55 arg->argv = parse_argv;
56 arg-> kill_time = kill_time;
58 surf_timer_resource->extension_public->set(start_time, (void*) &MSG_process_create_with_arguments,
61 if((start_time<0) || (start_time==MSG_get_clock())) {
62 process = MSG_process_create_with_arguments(parse_argv[0], parse_code,
64 parse_argc,parse_argv);
65 if(kill_time > MSG_getClock()) {
66 surf_timer_resource->extension_public->set(kill_time,
67 (void*) &MSG_process_kill,
73 /** \ingroup msg_easier_life
74 * \brief An application deployer.
76 * Creates the process described in \a file.
77 * \param file a filename of a xml description of the application. This file
80 * \include surfxml.dtd
82 * Here is a small example of such a platform
84 * \include small_deployment.xml
86 * Have a look in the directory examples/msg/ to have a bigger example.
88 void MSG_launch_application(const char *file)
90 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
91 STag_process_fun = parse_process_init;
92 ETag_argument_fun = parse_argument;
93 ETag_process_fun = parse_process_finalize;
94 surf_parse_open(file);
95 xbt_assert1((!surf_parse()),"Parse error in %s",file);
99 /** \ingroup msg_easier_life
100 * \brief Registers a #m_process_code_t code in a global table.
102 * Registers a code function in a global table.
103 * This table is then used by #MSG_launch_application.
104 * \param name the reference name of the function.
105 * \param code the function
107 void MSG_function_register(const char *name,m_process_code_t code)
109 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
111 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
114 /** \ingroup msg_easier_life
115 * \brief Registers a #m_process_t code in a global table.
117 * Registers a code function in a global table.
118 * This table is then used by #MSG_launch_application.
119 * \param name the reference name of the function.
121 m_process_code_t MSG_get_registered_function(const char *name)
123 m_process_code_t code = NULL;
125 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
127 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
132 /** \ingroup msg_easier_life
133 * \brief Get the arguments of the current process.
134 * \deprecated{Not useful since #m_process_code_t is int (*)(int argc, char *argv[])}
136 * This functions returns the values set for the current process
137 * using #MSG_set_arguments or #MSG_launch_application.
138 * \param argc the number of arguments
139 * \param argv the arguments table
141 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
143 m_process_t process = MSG_process_self();
144 simdata_process_t simdata = NULL;
146 xbt_assert0((argc) && (argv), "Invalid parameters");
147 simdata = process->simdata;
148 *argc = simdata->argc;
149 *argv = simdata->argv;
154 /** \ingroup msg_easier_life
155 * \brief Set the arguments of a process.
157 * This functions sets the argument number and the arguments table for a
159 * \param process is the process you want to modify
160 * \param argc the number of arguments
161 * \param argv the arguments table
163 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
165 simdata_process_t simdata = NULL;
167 xbt_assert0(0,"Deprecated ! Do not use anymore. "
168 "Use MSG_process_create_with_arguments instead.\n");