X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/110275bdfe31a33027e51860ed41f199da963cef..fda00496f6a31c2f09ed65b91d6052c2e50686df:/src/msg/deployment.c diff --git a/src/msg/deployment.c b/src/msg/deployment.c index 3cf1577e1d..984792cb9c 100644 --- a/src/msg/deployment.c +++ b/src/msg/deployment.c @@ -1,157 +1,81 @@ -/* $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"xbt/sysdep.h" -#include "xbt/error.h" -#include "surf/surf_parse.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(deployment, msg, - "Logging specific to MSG (environment)"); - -extern char *yytext; - +#include "msg/private.h" +#include "xbt/sysdep.h" +#include "xbt/log.h" /** \ingroup msg_easier_life * \brief An application deployer. * * Creates the process described in \a file. - * @param file a file containing a simple description of the application. - * The format of each line is the following : host_name function_name arguments - * You can use C-style comments and C-style strings. - * Here is a simple exemple - * - \verbatim - - // Here is the master - the-doors.ens-lyon.fr master "moby.cri2000.ens-lyon.fr" canaria.ens-lyon.fr popc.ens-lyon.fr - // And here are the slaves - moby.cri2000.ens-lyon.fr slave - canaria.ens-lyon.fr slave - popc.ens-lyon.fr slave - -\endverbatim + * \param file a filename of a xml description of the application. This file + * follows this DTD : + * + * \include simgrid.dtd + * + * Here is a small example of such a platform + * + * \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) { - char *host_name = NULL; - int argc = 0 ; - char **argv = NULL; - m_process_t process = NULL ; - m_host_t host = NULL; - m_process_code_t code = NULL; - e_surf_token_t token; - MSG_global_init(); - - find_section(file, "DEPLOYMENT"); + xbt_assert0(msg_global, + "MSG_global_init_args has to be called before MSG_launch_application."); - while(1) { - token = surf_parse(); + SIMIX_launch_application(file); - if (token == TOKEN_END_SECTION) - break; - if (token == TOKEN_NEWLINE) - continue; - - if (token == TOKEN_WORD) { - surf_parse_deployment_line(&host_name,&argc,&argv); - xbt_assert0(argc,"No function to execute"); - - code = MSG_get_registered_function(argv[0]); - xbt_assert1(code, "Unknown function %s",argv[0]); - - host = MSG_get_host_by_name(host_name); - xbt_assert1(host, "Unknown host %s",host_name); - - process = MSG_process_create(argv[0], code, NULL, host); - MSG_set_arguments(process, argc, argv); - xbt_free(host_name); - } - else { - CRITICAL1("Parse error line %d\n", surf_line_pos); - xbt_abort(); - } - } - - close_section("DEPLOYMENT"); + 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. + * 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) { - MSG_global_init(); - - xbt_dict_set(msg_global->registered_functions,name,code,NULL); + SIMIX_function_register(name, code); + return; } /** \ingroup msg_easier_life - * \brief Registers a ::m_process_t code in a global table. + * \brief Registers a function as the default main function of agents. * - * 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. + * 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[])) */ -m_process_code_t MSG_get_registered_function(const char *name) +void MSG_function_register_default(xbt_main_func_t code) { - m_process_code_t code = NULL; - - MSG_global_init(); - - xbt_dict_get(msg_global->registered_functions,name,(void **) &code); - - return code; + SIMIX_function_register_default(code); } /** \ingroup msg_easier_life - * \brief Get the arguments of the current process. - * \deprecated{Not useful since m_process_code_t is int (*)(int argc, char *argv[])} + * \brief Retrieves a registered main function * - * This functions returns the values set for the current process - * using ::MSG_set_arguments or ::MSG_launch_application. - * \param argc the number of arguments - * \param argv the arguments 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. */ -MSG_error_t MSG_get_arguments(int *argc, char ***argv) +xbt_main_func_t MSG_get_registered_function(const char *name) { - m_process_t process = MSG_process_self(); - simdata_process_t simdata = NULL; - - xbt_assert0((argc) && (argv), "Invalid parameters"); - simdata = process->simdata; - *argc = simdata->argc; - *argv = simdata->argv; - - return MSG_OK; + return SIMIX_get_registered_function(name); } -/** \ingroup msg_easier_life - * \brief Set the arguments of a process. - * - * This functions sets the argument number and the arguments table for a - * proces. - * \param process is the process you want to modify - * \param argc the number of arguments - * \param argv the arguments table +/** + * \brief register functions bypassing the parser */ -MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[]) -{ - simdata_process_t simdata = NULL; - xbt_assert0((process) && (process->simdata), "Invalid parameters"); - simdata = process->simdata; - simdata->argc = argc; - simdata->argv = argv; - return MSG_OK; +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); } -