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 MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
47 parse_argc,parse_argv,start_time,kill_time);
50 /** \ingroup msg_easier_life
51 * \brief An application deployer.
53 * Creates the process described in \a file.
54 * \param file a filename of a xml description of the application. This file
57 * \include surfxml.dtd
59 * Here is a small example of such a platform
61 * \include small_deployment.xml
63 * Have a look in the directory examples/msg/ to have a bigger example.
65 void MSG_launch_application(const char *file)
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);
76 /** \ingroup msg_easier_life
77 * \brief Registers a #m_process_code_t code in a global table.
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
84 void MSG_function_register(const char *name,m_process_code_t code)
86 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
88 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
91 /** \ingroup msg_easier_life
92 * \brief Registers a #m_process_t code in a global table.
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.
98 m_process_code_t MSG_get_registered_function(const char *name)
100 m_process_code_t code = NULL;
102 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
104 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
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[])}
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
118 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
120 m_process_t process = MSG_process_self();
121 simdata_process_t simdata = NULL;
123 xbt_assert0((argc) && (argv), "Invalid parameters");
124 simdata = process->simdata;
125 *argc = simdata->argc;
126 *argv = simdata->argv;
131 /** \ingroup msg_easier_life
132 * \brief Set the arguments of a process.
134 * This functions sets the argument number and the arguments table for a
136 * \param process is the process you want to modify
137 * \param argc the number of arguments
138 * \param argv the arguments table
140 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
142 simdata_process_t simdata = NULL;
144 xbt_assert0(0,"Deprecated ! Do not use anymore. "
145 "Use MSG_process_create_with_arguments instead.\n");