X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2ba74eff4ca1ae75c21507c120d74d59f5b728b1..6443d4868c5974225d792156daf319775234b087:/src/msg/deployment.c diff --git a/src/msg/deployment.c b/src/msg/deployment.c index 45353ec349..fadf887a22 100644 --- a/src/msg/deployment.c +++ b/src/msg/deployment.c @@ -1,79 +1,12 @@ -/* $Id$ */ - -/* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */ +/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "private.h" +#include "msg/private.h" #include "xbt/sysdep.h" #include "xbt/log.h" -#include "surf/surfxml_parse_private.h" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_deployment, msg, - "Logging specific to MSG (deployment)"); - -static int parse_argc = -1 ; -static char **parse_argv = NULL; -static m_process_code_t parse_code = NULL; -static m_host_t parse_host = NULL; -static double start_time = 0.0; -static double kill_time = -1.0; - -static void parse_process_init(void) -{ - parse_host = MSG_get_host_by_name(A_surfxml_process_host); - xbt_assert1(parse_host, "Unknown host %s",A_surfxml_process_host); - parse_code = MSG_get_registered_function(A_surfxml_process_function); - xbt_assert1(parse_code, "Unknown function %s",A_surfxml_process_function); - parse_argc = 0 ; - parse_argv = NULL; - parse_argc++; - parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *)); - parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_process_function); - surf_parse_get_double(&start_time,A_surfxml_process_start_time); - surf_parse_get_double(&kill_time,A_surfxml_process_kill_time); -} - -static void parse_argument(void) -{ - parse_argc++; - parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *)); - parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_argument_value); -} - -static void parse_process_finalize(void) -{ - process_arg_t arg = NULL; - m_process_t process = NULL; - if(start_time>MSG_get_clock()) { - arg = xbt_new0(s_process_arg_t,1); - arg->name = parse_argv[0]; - arg->code = parse_code; - arg->data = NULL; - arg->host = parse_host; - arg->argc = parse_argc; - arg->argv = parse_argv; - arg-> kill_time = kill_time; - - DEBUG3("Process %s(%s) will be started at time %f", arg->name, - arg->host->name,start_time); - surf_timer_resource->extension_public->set(start_time, (void*) &MSG_process_create_with_arguments, - arg); - } - if((start_time<0) || (start_time==MSG_get_clock())) { - DEBUG2("Starting Process %s(%s) right now", parse_argv[0], - parse_host->name); - process = MSG_process_create_with_arguments(parse_argv[0], parse_code, - NULL, parse_host, - parse_argc,parse_argv); - if(kill_time > MSG_get_clock()) { - surf_timer_resource->extension_public->set(kill_time, - (void*) &MSG_process_kill, - (void*) process); - } - } -} /** \ingroup msg_easier_life * \brief An application deployer. @@ -82,55 +15,68 @@ static void parse_process_finalize(void) * \param file a filename of a xml description of the application. This file * follows this DTD : * - * \include surfxml.dtd + * \include simgrid.dtd * * Here is a small example of such a platform * - * \include small_deployment.xml + * \include msg/masterslave/deployment_masterslave.xml * * Have a look in the directory examples/msg/ to have a bigger example. */ -void MSG_launch_application(const char *file) +void MSG_launch_application(const char *file) { - xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application."); - STag_surfxml_process_fun = parse_process_init; - ETag_surfxml_argument_fun = parse_argument; - ETag_surfxml_process_fun = parse_process_finalize; - surf_parse_open(file); - xbt_assert1((!surf_parse()),"Parse error in %s",file); - surf_parse_close(); + + xbt_assert(msg_global, + "MSG_global_init_args has to be called before MSG_launch_application."); + + SIMIX_launch_application(file); + + return; } /** \ingroup msg_easier_life - * \brief Registers a #m_process_code_t code in a global table. + * \brief Registers the main function of an agent in a global table. * * Registers a code function in a global table. * This table is then used by #MSG_launch_application. * \param name the reference name of the function. - * \param code the function + * \param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char *argv[])) */ -void MSG_function_register(const char *name,m_process_code_t code) +void MSG_function_register(const char *name, xbt_main_func_t code) { - xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_function_register."); + SIMIX_function_register(name, code); + return; +} - xbt_dict_set(msg_global->registered_functions,name,code,NULL); +/** \ingroup msg_easier_life + * \brief Registers a function as the default main function of agents. + * + * Registers a code function as being the default value. This function will get used by MSG_launch_application() when there is no registered function of the requested name in. + * \param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char *argv[])) + */ +void MSG_function_register_default(xbt_main_func_t code) +{ + SIMIX_function_register_default(code); } /** \ingroup msg_easier_life - * \brief Registers a #m_process_t code in a global table. + * \brief Retrieves a registered main function * * Registers a code function in a global table. * This table is then used by #MSG_launch_application. * \param name the reference name of the function. */ -m_process_code_t MSG_get_registered_function(const char *name) +xbt_main_func_t MSG_get_registered_function(const char *name) { - m_process_code_t code = NULL; - - xbt_assert0(msg_global,"MSG_global_init has to be called before MSG_get_registered_function."); + return SIMIX_get_registered_function(name); +} - code = xbt_dict_get_or_null(msg_global->registered_functions,name); +/** + * \brief register functions bypassing the parser + */ - return code; +void MSG_set_function(const char *host_id, const char *function_name, + xbt_dynar_t arguments) +{ + SIMIX_process_set_function(host_id, function_name, arguments, -1, -1); } -