3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
4 All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "xbt/sysdep.h"
13 #include "surf/surfxml_parse_private.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix,
16 "Logging specific to SIMIX (deployment)");
17 static int parse_argc = -1 ;
18 static char **parse_argv = NULL;
19 static smx_process_code_t parse_code = NULL;
20 static smx_host_t parse_host = NULL;
21 static double start_time = 0.0;
22 static double kill_time = -1.0;
24 static void parse_process_init(void)
26 parse_host = SIMIX_host_get_by_name(A_surfxml_process_host);
27 xbt_assert1(parse_host, "Unknown host %s",A_surfxml_process_host);
28 parse_code = SIMIX_get_registered_function(A_surfxml_process_function);
29 xbt_assert1(parse_code, "Unknown function %s",A_surfxml_process_function);
33 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
34 parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_process_function);
35 surf_parse_get_double(&start_time,A_surfxml_process_start_time);
36 surf_parse_get_double(&kill_time,A_surfxml_process_kill_time);
39 static void parse_argument(void)
42 parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
43 parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_argument_value);
46 static void parse_process_finalize(void)
48 process_arg_t arg = NULL;
49 smx_process_t process = NULL;
50 if(start_time>SIMIX_get_clock()) {
51 arg = xbt_new0(s_process_arg_t,1);
52 arg->name = parse_argv[0];
53 arg->code = parse_code;
55 arg->host = parse_host;
56 arg->argc = parse_argc;
57 arg->argv = parse_argv;
58 arg->kill_time = kill_time;
60 DEBUG3("Process %s(%s) will be started at time %f", arg->name,
61 arg->host->name,start_time);
62 surf_timer_resource->extension_public->set(start_time, (void*) &SIMIX_process_create_with_arguments,
65 if((start_time<0) || (start_time==SIMIX_get_clock())) {
66 DEBUG2("Starting Process %s(%s) right now", parse_argv[0],
68 process = SIMIX_process_create_with_arguments(parse_argv[0], parse_code,
70 parse_argc,parse_argv);
71 if(kill_time > SIMIX_get_clock()) {
72 surf_timer_resource->extension_public->set(kill_time,
73 (void*) &SIMIX_process_kill,
79 /** \ingroup msg_easier_life
80 * \brief An application deployer.
82 * Creates the process described in \a file.
83 * \param file a filename of a xml description of the application. This file
86 * \include surfxml.dtd
88 * Here is a small example of such a platform
90 * \include small_deployment.xml
92 * Have a look in the directory examples/msg/ to have a bigger example.
94 void SIMIX_launch_application(const char *file)
96 xbt_assert0(simix_global,"SIMIX_global_init_args has to be called before SIMIX_launch_application.");
97 STag_surfxml_process_fun = parse_process_init;
98 ETag_surfxml_argument_fun = parse_argument;
99 ETag_surfxml_process_fun = parse_process_finalize;
100 surf_parse_open(file);
101 xbt_assert1((!surf_parse()),"Parse error in %s",file);
105 /** \ingroup msg_easier_life
106 * \brief Registers a #m_process_code_t code in a global table.
108 * Registers a code function in a global table.
109 * This table is then used by #MSG_launch_application.
110 * \param name the reference name of the function.
111 * \param code the function
113 void SIMIX_function_register(const char *name,smx_process_code_t code)
115 xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_function_register.");
117 xbt_dict_set(simix_global->registered_functions,name,code,NULL);
120 /** \ingroup msg_easier_life
121 * \brief Registers a #m_process_t code in a global table.
123 * Registers a code function in a global table.
124 * This table is then used by #MSG_launch_application.
125 * \param name the reference name of the function.
127 smx_process_code_t SIMIX_get_registered_function(const char *name)
129 smx_process_code_t code = NULL;
131 xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_get_registered_function.");
133 code = xbt_dict_get_or_null(simix_global->registered_functions,name);