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 char * 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 = xbt_strdup(A_surfxml_process_host);
27 xbt_assert1(SIMIX_host_get_by_name(A_surfxml_process_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 void * 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->hostname = 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->hostname,start_time);
62 if (simix_global->create_process_function)
63 surf_timer_resource->extension_public->set(start_time, (void*) simix_global->create_process_function, arg);
65 surf_timer_resource->extension_public->set(start_time, (void*) &SIMIX_process_create, arg);
68 if((start_time<0) || (start_time==SIMIX_get_clock())) {
69 DEBUG2("Starting Process %s(%s) right now", parse_argv[0], parse_host);
71 if (simix_global->create_process_function)
72 process = simix_global->create_process_function(parse_argv[0], parse_code, NULL, parse_host, parse_argc,parse_argv);
74 process = SIMIX_process_create(parse_argv[0], parse_code, NULL, parse_host, parse_argc,parse_argv, NULL);
76 if(kill_time > SIMIX_get_clock()) {
77 if (simix_global->kill_process_function)
78 surf_timer_resource->extension_public->set(start_time, (void*) simix_global->kill_process_function, arg);
80 surf_timer_resource->extension_public->set(kill_time, (void*) &SIMIX_process_kill, (void*) process);
87 * \brief An application deployer.
89 * Creates the process described in \a file.
90 * \param file a filename of a xml description of the application. This file
93 * \include surfxml.dtd
95 * Here is a small example of such a platform
97 * \include small_deployment.xml
100 void SIMIX_launch_application(const char *file)
102 xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_launch_application.");
103 STag_surfxml_process_fun = parse_process_init;
104 ETag_surfxml_argument_fun = parse_argument;
105 ETag_surfxml_process_fun = parse_process_finalize;
106 surf_parse_open(file);
107 xbt_assert1((!surf_parse()),"Parse error in %s",file);
112 * \brief Registers a #smx_process_code_t code in a global table.
114 * Registers a code function in a global table.
115 * This table is then used by #SIMIX_launch_application.
116 * \param name the reference name of the function.
117 * \param code the function
119 void SIMIX_function_register(const char *name,smx_process_code_t code)
121 xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_function_register.");
123 xbt_dict_set(simix_global->registered_functions,name,code,NULL);
127 * \brief Gets a #smx_process_t code from the global table.
129 * Gets a code function from the global table. Returns NULL if there are no function registered with the name.
130 * This table is then used by #SIMIX_launch_application.
131 * \param name the reference name of the function.
132 * \return The #smx_process_t or NULL.
134 smx_process_code_t SIMIX_get_registered_function(const char *name)
136 smx_process_code_t code = NULL;
138 xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_get_registered_function.");
140 code = xbt_dict_get_or_null(simix_global->registered_functions,name);