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. */
9 #include "xbt/sysdep.h"
11 #include "surf/surfxml_parse_private.h"
13 static int parse_argc = -1 ;
14 static char **parse_argv = NULL;
15 static m_process_code_t parse_code = NULL;
16 static m_host_t parse_host = NULL;
17 static double start_time = 0.0;
18 static double kill_time = -1.0;
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);
31 surf_parse_get_double(&start_time,A_process_start_time);
32 surf_parse_get_double(&kill_time,A_process_kill_time);
35 static void parse_argument(void)
38 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
39 parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
42 static void parse_process_finalize(void)
44 process_arg_t arg = NULL;
45 m_process_t process = NULL;
46 if(start_time>MSG_get_clock()) {
47 arg = xbt_new0(s_process_arg_t,1);
48 arg->name = parse_argv[0];
49 arg->code = parse_code;
51 arg->host = parse_host;
52 arg->argc = parse_argc;
53 arg->argv = parse_argv;
54 arg-> kill_time = kill_time;
56 surf_timer_resource->extension_public->set(start_time, (void*) &MSG_process_create_with_arguments,
59 if((start_time<0) || (start_time==MSG_get_clock())) {
60 process = MSG_process_create_with_arguments(parse_argv[0], parse_code,
62 parse_argc,parse_argv);
63 if(kill_time > MSG_get_clock()) {
64 surf_timer_resource->extension_public->set(kill_time,
65 (void*) &MSG_process_kill,
71 /** \ingroup msg_easier_life
72 * \brief An application deployer.
74 * Creates the process described in \a file.
75 * \param file a filename of a xml description of the application. This file
78 * \include surfxml.dtd
80 * Here is a small example of such a platform
82 * \include small_deployment.xml
84 * Have a look in the directory examples/msg/ to have a bigger example.
86 void MSG_launch_application(const char *file)
88 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
89 STag_process_fun = parse_process_init;
90 ETag_argument_fun = parse_argument;
91 ETag_process_fun = parse_process_finalize;
92 surf_parse_open(file);
93 xbt_assert1((!surf_parse()),"Parse error in %s",file);
97 /** \ingroup msg_easier_life
98 * \brief Registers a #m_process_code_t code in a global table.
100 * Registers a code function in a global table.
101 * This table is then used by #MSG_launch_application.
102 * \param name the reference name of the function.
103 * \param code the function
105 void MSG_function_register(const char *name,m_process_code_t code)
107 xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_function_register.");
109 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
112 /** \ingroup msg_easier_life
113 * \brief Registers a #m_process_t code in a global table.
115 * Registers a code function in a global table.
116 * This table is then used by #MSG_launch_application.
117 * \param name the reference name of the function.
119 m_process_code_t MSG_get_registered_function(const char *name)
121 m_process_code_t code = NULL;
123 xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_get_registered_function.");
125 code = xbt_dict_get_or_null(msg_global->registered_functions,name);