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)");
18 /** \ingroup msg_easier_life
19 * \brief An application deployer.
21 * Creates the process described in \a file.
22 * @param file a file containing a simple description of the application.
23 * The format of each line is the following : host_name function_name arguments
24 * You can use C-style comments and C-style strings.
25 * Here is a simple exemple
30 the-doors.ens-lyon.fr master "moby.cri2000.ens-lyon.fr" canaria.ens-lyon.fr popc.ens-lyon.fr
31 // And here are the slaves
32 moby.cri2000.ens-lyon.fr slave
33 canaria.ens-lyon.fr slave
34 popc.ens-lyon.fr slave
38 void MSG_launch_application(const char *file)
40 char *host_name = NULL;
43 m_process_t process = NULL ;
45 m_process_code_t code = NULL;
50 find_section(file, "DEPLOYMENT");
55 if (token == TOKEN_END_SECTION)
57 if (token == TOKEN_NEWLINE)
60 if (token == TOKEN_WORD) {
61 surf_parse_deployment_line(&host_name,&argc,&argv);
62 xbt_assert0(argc,"No function to execute");
64 code = MSG_get_registered_function(argv[0]);
65 xbt_assert1(code, "Unknown function %s",argv[0]);
67 host = MSG_get_host_by_name(host_name);
68 xbt_assert1(host_name, "Unknown host %s",host_name);
70 process = MSG_process_create(argv[0], code, NULL, host);
71 MSG_set_arguments(process, argc, argv);
75 CRITICAL1("Parse error line %d\n", surf_line_pos);
83 /** \ingroup msg_easier_life
84 * \brief Registers a ::m_process_code_t code in a global table.
86 * Registers a code function in a global table.
87 * This table is then used by ::MSG_launch_application.
88 * \param name the reference name of the function.
89 * \param code the function
91 void MSG_function_register(const char *name,m_process_code_t code)
95 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
98 /** \ingroup msg_easier_life
99 * \brief Registers a ::m_process_t code in a global table.
101 * Registers a code function in a global table.
102 * This table is then used by ::MSG_launch_application.
103 * \param name the reference name of the function.
105 m_process_code_t MSG_get_registered_function(const char *name)
107 m_process_code_t code = NULL;
111 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
116 /** \ingroup msg_easier_life
117 * \brief Get the arguments of the current process.
118 * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])}
120 * This functions returns the values set for the current process
121 * using ::MSG_set_arguments or ::MSG_launch_application.
122 * \param argc the number of arguments
123 * \param argv the arguments table
125 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
127 m_process_t process = MSG_process_self();
128 simdata_process_t simdata = NULL;
130 xbt_assert0((argc) && (argv), "Invalid parameters");
131 simdata = process->simdata;
132 *argc = simdata->argc;
133 *argv = simdata->argv;
138 /** \ingroup msg_easier_life
139 * \brief Set the arguments of a process.
141 * This functions sets the argument number and the arguments table for a
143 * \param process is the process you want to modify
144 * \param argc the number of arguments
145 * \param argv the arguments table
147 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
149 simdata_process_t simdata = NULL;
151 xbt_assert0((process) && (process->simdata), "Invalid parameters");
152 simdata = process->simdata;
153 simdata->argc = argc;
154 simdata->argv = argv;