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, "Unknown host %s",host_name);
70 process = MSG_process_create_with_arguments(argv[0], code, NULL, host,argc,argv);
76 CRITICAL1("Parse error line %d\n", surf_line_pos);
81 close_section("DEPLOYMENT");
84 /** \ingroup msg_easier_life
85 * \brief Registers a ::m_process_code_t code in a global table.
87 * Registers a code function in a global table.
88 * This table is then used by ::MSG_launch_application.
89 * \param name the reference name of the function.
90 * \param code the function
92 void MSG_function_register(const char *name,m_process_code_t code)
96 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
99 /** \ingroup msg_easier_life
100 * \brief Registers a ::m_process_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.
106 m_process_code_t MSG_get_registered_function(const char *name)
108 m_process_code_t code = NULL;
112 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
117 /** \ingroup msg_easier_life
118 * \brief Get the arguments of the current process.
119 * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])}
121 * This functions returns the values set for the current process
122 * using ::MSG_set_arguments or ::MSG_launch_application.
123 * \param argc the number of arguments
124 * \param argv the arguments table
126 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
128 m_process_t process = MSG_process_self();
129 simdata_process_t simdata = NULL;
131 xbt_assert0((argc) && (argv), "Invalid parameters");
132 simdata = process->simdata;
133 *argc = simdata->argc;
134 *argv = simdata->argv;
139 /** \ingroup msg_easier_life
140 * \brief Set the arguments of a process.
142 * This functions sets the argument number and the arguments table for a
144 * \param process is the process you want to modify
145 * \param argc the number of arguments
146 * \param argv the arguments table
148 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
150 simdata_process_t simdata = NULL;
152 xbt_assert0(0,"Deprecated ! Do not use anymore. "
153 "Use MSG_process_create_with_arguments instead.\n");