X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/56c92988c6bf8a4e5c1df4a5af4388310f879353..0e16ef4c4c660214ac42b733a0abc6f6c12e9ef3:/src/surf/surfxml_parse.c diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 1dcddf9fc2..fa7e68167f 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -7,15 +7,39 @@ #include "xbt/misc.h" #include "xbt/log.h" +#include "xbt/dict.h" #include "surf/surfxml_parse_private.h" #include "surf/surf_private.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf ,"Logging specific to the SURF module"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf, + "Logging specific to the SURF module"); #undef CLEANUP #include "surfxml.c" -static xbt_dynar_t surf_input_buffer_stack=NULL; -static xbt_dynar_t surf_file_to_parse_stack=NULL; +/* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */ +xbt_dynar_t STag_surfxml_platform_description_cb_list = NULL; +xbt_dynar_t ETag_surfxml_platform_description_cb_list = NULL; +xbt_dynar_t STag_surfxml_host_cb_list = NULL; +xbt_dynar_t ETag_surfxml_host_cb_list = NULL; +xbt_dynar_t STag_surfxml_router_cb_list = NULL; +xbt_dynar_t ETag_surfxml_router_cb_list = NULL; +xbt_dynar_t STag_surfxml_link_cb_list = NULL; +xbt_dynar_t ETag_surfxml_link_cb_list = NULL; +xbt_dynar_t STag_surfxml_route_cb_list = NULL; +xbt_dynar_t ETag_surfxml_route_cb_list = NULL; +xbt_dynar_t STag_surfxml_link_c_ctn_cb_list = NULL; +xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list = NULL; +xbt_dynar_t STag_surfxml_process_cb_list = NULL; +xbt_dynar_t ETag_surfxml_process_cb_list = NULL; +xbt_dynar_t STag_surfxml_argument_cb_list = NULL; +xbt_dynar_t ETag_surfxml_argument_cb_list = NULL; +xbt_dynar_t STag_surfxml_prop_cb_list = NULL; +xbt_dynar_t ETag_surfxml_prop_cb_list = NULL; + +static xbt_dynar_t surf_input_buffer_stack = NULL; +static xbt_dynar_t surf_file_to_parse_stack = NULL; + +void surfxml_call_cb_functions(xbt_dynar_t); void nil_function(void); void nil_function(void) @@ -23,174 +47,200 @@ void nil_function(void) return; } -void_f_void_t STag_surfxml_platform_description_fun = nil_function; -void_f_void_t ETag_surfxml_platform_description_fun = nil_function; -void_f_void_t STag_surfxml_cpu_fun = nil_function; -void_f_void_t ETag_surfxml_cpu_fun = nil_function; -void_f_void_t STag_surfxml_network_link_fun = nil_function; -void_f_void_t ETag_surfxml_network_link_fun = nil_function; -void_f_void_t STag_surfxml_route_fun = nil_function; -void_f_void_t ETag_surfxml_route_fun = nil_function; -void_f_void_t STag_surfxml_route_element_fun = nil_function; -void_f_void_t ETag_surfxml_route_element_fun = nil_function; -void_f_void_t STag_surfxml_process_fun = nil_function; -void_f_void_t ETag_surfxml_process_fun = nil_function; -void_f_void_t STag_surfxml_argument_fun = nil_function; -void_f_void_t ETag_surfxml_argument_fun = nil_function; - YY_BUFFER_STATE surf_input_buffer; FILE *surf_file_to_parse; void surf_parse_reset_parser(void) { - STag_surfxml_platform_description_fun = nil_function; - ETag_surfxml_platform_description_fun = nil_function; - STag_surfxml_cpu_fun = nil_function; - ETag_surfxml_cpu_fun = nil_function; - STag_surfxml_network_link_fun = nil_function; - ETag_surfxml_network_link_fun = nil_function; - STag_surfxml_route_fun = nil_function; - ETag_surfxml_route_fun = nil_function; - STag_surfxml_route_element_fun = nil_function; - ETag_surfxml_route_element_fun = nil_function; - STag_surfxml_process_fun = nil_function; - ETag_surfxml_process_fun = nil_function; - STag_surfxml_argument_fun = nil_function; - ETag_surfxml_argument_fun = nil_function; + + STag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free); + } void STag_surfxml_include(void) { - xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer); - xbt_dynar_push(surf_file_to_parse_stack,&surf_file_to_parse); - - surf_file_to_parse = surf_fopen(A_surfxml_include_file,"r"); + xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer); + xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); + + surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file); - surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10); + surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10); surf_parse__switch_to_buffer(surf_input_buffer); - printf("STAG\n"); fflush(NULL); + printf("STAG\n"); + fflush(NULL); } void ETag_surfxml_include(void) { - printf("ETAG\n"); fflush(NULL); + printf("ETAG\n"); + fflush(NULL); surf_parse__delete_buffer(surf_input_buffer); fclose(surf_file_to_parse); - xbt_dynar_pop(surf_file_to_parse_stack,&surf_file_to_parse); - xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer); + xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse); + xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer); } void STag_surfxml_platform_description(void) { - double version=0.0; + double version = 0.0; - sscanf(A_surfxml_platform_description_version,"%lg",&version); + sscanf(A_surfxml_platform_description_version, "%lg", &version); - xbt_assert0((version>=1.0),"******* BIG FAT WARNING *********\n " - "You're using an old XML file. " - "Since SimGrid 3.0.2, units are Bytes, Flops, and seconds " + xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n " + "You're using an ancient XML file. " + "Since SimGrid 3.1, units are Bytes, Flops, and seconds " "instead of MBytes, MFlops and seconds. " - "A script (surfxml_update.pl )to help you convert your old " + "A script (surfxml_update.pl) to help you convert your old " "platform files " "is available in the contrib/platform_generation directory " "of the simgrid repository. Please check also out the " - "SURF section of the ChangeLog for the 3.0.2 version. " + "SURF section of the ChangeLog for the 3.1 version. " "Last, do not forget to also update your values for " - "the calls to MSG_task_create if any."); + "the calls to MSG_task_create (if any)."); + xbt_assert0((version >= 2.0), "******* BIG FAT WARNING *********\n " + "You're using an old XML file. " + "A script (surfxml_update.pl) to help you convert your old " + "platform files " + "is available in the contrib/platform_generation directory " + "of the simgrid repository."); - STag_surfxml_platform_description_fun(); + surfxml_call_cb_functions(STag_surfxml_platform_description_cb_list); } void ETag_surfxml_platform_description(void) { - ETag_surfxml_platform_description_fun(); + surfxml_call_cb_functions(ETag_surfxml_platform_description_cb_list); } -void STag_surfxml_cpu(void) +void STag_surfxml_host(void) { - STag_surfxml_cpu_fun(); + surfxml_call_cb_functions(STag_surfxml_host_cb_list); } -void ETag_surfxml_cpu(void) +void ETag_surfxml_host(void) { - ETag_surfxml_cpu_fun(); + surfxml_call_cb_functions(ETag_surfxml_host_cb_list); } -void STag_surfxml_network_link(void) +void STag_surfxml_router(void) { - STag_surfxml_network_link_fun(); + surfxml_call_cb_functions(STag_surfxml_router_cb_list); } -void ETag_surfxml_network_link(void) +void ETag_surfxml_router(void) { - ETag_surfxml_network_link_fun(); + surfxml_call_cb_functions(ETag_surfxml_router_cb_list); +} + +void STag_surfxml_link(void) +{ + surfxml_call_cb_functions(STag_surfxml_link_cb_list); +} + +void ETag_surfxml_link(void) +{ + surfxml_call_cb_functions(ETag_surfxml_link_cb_list); } void STag_surfxml_route(void) { - STag_surfxml_route_fun(); + surfxml_call_cb_functions(STag_surfxml_route_cb_list); } void ETag_surfxml_route(void) { - ETag_surfxml_route_fun(); + surfxml_call_cb_functions(ETag_surfxml_route_cb_list); } -void STag_surfxml_route_element(void) +void STag_surfxml_link_c_ctn(void) { - STag_surfxml_route_element_fun(); + surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list); } -void ETag_surfxml_route_element(void) +void ETag_surfxml_link_c_ctn(void) { - ETag_surfxml_route_element_fun(); + surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list); } void STag_surfxml_process(void) { - STag_surfxml_process_fun(); + surfxml_call_cb_functions(STag_surfxml_process_cb_list); } void ETag_surfxml_process(void) { - ETag_surfxml_process_fun(); + surfxml_call_cb_functions(ETag_surfxml_process_cb_list); } void STag_surfxml_argument(void) { - STag_surfxml_argument_fun(); + surfxml_call_cb_functions(STag_surfxml_argument_cb_list); } void ETag_surfxml_argument(void) { - ETag_surfxml_argument_fun(); + surfxml_call_cb_functions(ETag_surfxml_argument_cb_list); +} + +void STag_surfxml_prop(void) +{ + surfxml_call_cb_functions(STag_surfxml_prop_cb_list); +} +void ETag_surfxml_prop(void) +{ + surfxml_call_cb_functions(ETag_surfxml_prop_cb_list); } -void surf_parse_open(const char *file) { - if(!file) { - WARN0("I hope you know what you're doing... you just gave me a NULL pointer!"); + +void surf_parse_open(const char *file) +{ + static int warned = 0; /* warn only once */ + if (!file) { + if (!warned) { + WARN0 + ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code."); + warned = 1; + } return; } - if(!surf_input_buffer_stack) - surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL); - if(!surf_file_to_parse_stack) - surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL); - - surf_file_to_parse = surf_fopen(file,"r"); - xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file); - surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10); + if (!surf_input_buffer_stack) + surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL); + if (!surf_file_to_parse_stack) + surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL); + + surf_file_to_parse = surf_fopen(file, "r"); + xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file); + surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10); surf_parse__switch_to_buffer(surf_input_buffer); surf_parse_lineno = 1; } -void surf_parse_close(void) { - if(surf_input_buffer_stack) +void surf_parse_close(void) +{ + if (surf_input_buffer_stack) xbt_dynar_free(&surf_input_buffer_stack); - if(surf_file_to_parse_stack) + if (surf_file_to_parse_stack) xbt_dynar_free(&surf_file_to_parse_stack); - if(surf_file_to_parse) { + if (surf_file_to_parse) { surf_parse__delete_buffer(surf_input_buffer); fclose(surf_file_to_parse); } @@ -204,16 +254,16 @@ static int _surf_parse(void) int_f_void_t surf_parse = _surf_parse; -void surf_parse_get_double(double *value,const char *string) -{ +void surf_parse_get_double(double *value, const char *string) +{ int ret = 0; ret = sscanf(string, "%lg", value); - xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno, - string); + xbt_assert2((ret == 1), "Parse error line %d : %s not a number", + surf_parse_lineno, string); } -void surf_parse_get_trace(tmgr_trace_t *trace, const char *string) +void surf_parse_get_trace(tmgr_trace_t * trace, const char *string) { if ((!string) || (strcmp(string, "") == 0)) *trace = NULL; @@ -221,3 +271,33 @@ void surf_parse_get_trace(tmgr_trace_t *trace, const char *string) *trace = tmgr_trace_new(string); } +void parse_properties(void) +{ + char *value = NULL; + + if(!current_property_set) current_property_set = xbt_dict_new(); + + value = xbt_strdup(A_surfxml_prop_value); + xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free); + +} + +void free_string(void *d) +{ + free(*(void**)d); +} + +void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function) +{ + xbt_dynar_push(cb_list, &function); +} + +void surfxml_call_cb_functions(xbt_dynar_t cb_list) +{ + int iterator; + void_f_void_t fun; + xbt_dynar_foreach(cb_list, iterator, fun){ + DEBUG2("call %p %p",fun,*fun); + (*fun)(); + } +}