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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_deployment, msg,
14 "Logging specific to MSG (deployment)");
16 static int parse_argc = -1 ;
17 static char **parse_argv = NULL;
18 static m_process_code_t parse_code = NULL;
19 static m_host_t parse_host = NULL;
20 static double start_time = 0.0;
21 static double kill_time = -1.0;
23 static void parse_process_init(void)
25 parse_host = MSG_get_host_by_name(A_surfxml_process_host);
26 xbt_assert1(parse_host, "Unknown host %s",A_surfxml_process_host);
27 parse_code = MSG_get_registered_function(A_surfxml_process_function);
28 xbt_assert1(parse_code, "Unknown function %s",A_surfxml_process_function);
32 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
33 parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_process_function);
34 surf_parse_get_double(&start_time,A_surfxml_process_start_time);
35 surf_parse_get_double(&kill_time,A_surfxml_process_kill_time);
38 static void parse_argument(void)
41 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
42 parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_argument_value);
45 static void parse_process_finalize(void)
47 process_arg_t arg = NULL;
48 m_process_t process = NULL;
49 if(start_time>MSG_get_clock()) {
50 arg = xbt_new0(s_process_arg_t,1);
51 arg->name = parse_argv[0];
52 arg->code = parse_code;
54 arg->host = parse_host;
55 arg->argc = parse_argc;
56 arg->argv = parse_argv;
57 arg-> kill_time = kill_time;
59 DEBUG3("Process %s(%s) will be started at time %f", arg->name,
60 arg->host->name,start_time);
61 surf_timer_resource->extension_public->set(start_time, (void*) &MSG_process_create_with_arguments,
64 if((start_time<0) || (start_time==MSG_get_clock())) {
65 DEBUG2("Starting Process %s(%s) right now", parse_argv[0],
67 process = MSG_process_create_with_arguments(parse_argv[0], parse_code,
69 parse_argc,parse_argv);
70 if(kill_time > MSG_get_clock()) {
71 surf_timer_resource->extension_public->set(kill_time,
72 (void*) &MSG_process_kill,
78 /** \ingroup msg_easier_life
79 * \brief An application deployer.
81 * Creates the process described in \a file.
82 * \param file a filename of a xml description of the application. This file
85 * \include surfxml.dtd
87 * Here is a small example of such a platform
89 * \include small_deployment.xml
91 * Have a look in the directory examples/msg/ to have a bigger example.
93 void MSG_launch_application(const char *file)
95 xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
96 STag_surfxml_process_fun = parse_process_init;
97 ETag_surfxml_argument_fun = parse_argument;
98 ETag_surfxml_process_fun = parse_process_finalize;
99 surf_parse_open(file);
100 xbt_assert1((!surf_parse()),"Parse error in %s",file);
104 /** \ingroup msg_easier_life
105 * \brief Registers a #m_process_code_t code in a global table.
107 * Registers a code function in a global table.
108 * This table is then used by #MSG_launch_application.
109 * \param name the reference name of the function.
110 * \param code the function
112 void MSG_function_register(const char *name,m_process_code_t code)
114 xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_function_register.");
116 xbt_dict_set(msg_global->registered_functions,name,code,NULL);
119 /** \ingroup msg_easier_life
120 * \brief Registers a #m_process_t code in a global table.
122 * Registers a code function in a global table.
123 * This table is then used by #MSG_launch_application.
124 * \param name the reference name of the function.
126 m_process_code_t MSG_get_registered_function(const char *name)
128 m_process_code_t code = NULL;
130 xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_get_registered_function.");
132 code = xbt_dict_get_or_null(msg_global->registered_functions,name);