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;
20 static void parse_process_init(void)
22 parse_host = MSG_get_host_by_name(A_process_host);
23 xbt_assert1(parse_host, "Unknown host %s",A_process_host);
24 parse_code = MSG_get_registered_function(A_process_function);
25 xbt_assert1(parse_code, "Unknown function %s",A_process_function);
29 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
30 parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
33 static void parse_argument(void)
36 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
37 parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
40 static void parse_process_finalize(void)
42 MSG_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,
43 parse_argc,parse_argv);
46 /** \ingroup msg_easier_life
47 * \brief An application deployer.
49 * Creates the process described in \a file.
50 * \param file a filename of a xml description of the application. This file
53 * \include surfxml.dtd
55 * Here is a small example of such a platform
57 * \include small_deployment.xml
59 * Have a look in the directory examples/msg/ to have a bigger example.
61 void MSG_launch_application(const char *file)
63 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
64 STag_process_fun = parse_process_init;
65 ETag_argument_fun = parse_argument;
66 ETag_process_fun = parse_process_finalize;
67 surf_parse_open(file);
68 xbt_assert1((!surf_parse()),"Parse error in %s",file);
72 /** \ingroup msg_easier_life
73 * \brief Registers a #m_process_code_t code in a global table.
75 * Registers a code function in a global table.
76 * This table is then used by #MSG_launch_application.
77 * \param name the reference name of the function.
78 * \param code the function
80 void MSG_function_register(const char *name,m_process_code_t code)
82 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_function_register.");
84 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
87 /** \ingroup msg_easier_life
88 * \brief Registers a #m_process_t code in a global table.
90 * Registers a code function in a global table.
91 * This table is then used by #MSG_launch_application.
92 * \param name the reference name of the function.
94 m_process_code_t MSG_get_registered_function(const char *name)
96 m_process_code_t code = NULL;
98 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
100 xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
105 /** \ingroup msg_easier_life
106 * \brief Get the arguments of the current process.
107 * \deprecated{Not useful since #m_process_code_t is int (*)(int argc, char *argv[])}
109 * This functions returns the values set for the current process
110 * using #MSG_set_arguments or #MSG_launch_application.
111 * \param argc the number of arguments
112 * \param argv the arguments table
114 MSG_error_t MSG_get_arguments(int *argc, char ***argv)
116 m_process_t process = MSG_process_self();
117 simdata_process_t simdata = NULL;
119 xbt_assert0((argc) && (argv), "Invalid parameters");
120 simdata = process->simdata;
121 *argc = simdata->argc;
122 *argv = simdata->argv;
127 /** \ingroup msg_easier_life
128 * \brief Set the arguments of a process.
130 * This functions sets the argument number and the arguments table for a
132 * \param process is the process you want to modify
133 * \param argc the number of arguments
134 * \param argv the arguments table
136 MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
138 simdata_process_t simdata = NULL;
140 xbt_assert0(0,"Deprecated ! Do not use anymore. "
141 "Use MSG_process_create_with_arguments instead.\n");