X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/504b4d20dd2db9ea1eaa9c4b390b2a412d7c9779..8c35a4b9957c7e0efe6816f03e11e91608005858:/src/surf/surfxml_parse.c diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 7956cd942d..b0803d57a9 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -10,47 +10,107 @@ #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(surf_parse, surf, + "Logging specific to the SURF parsing module"); #undef CLEANUP #include "surfxml.c" +/* 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_cb_list = NULL; +xbt_dynar_t ETag_surfxml_platform_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; + +xbt_dict_t current_property_set = NULL; + +xbt_dict_t route_table = NULL; +xbt_dynar_t route_link_list = NULL; +xbt_dynar_t links = NULL; +xbt_dynar_t keys = 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); +static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t); + +YY_BUFFER_STATE surf_input_buffer; +FILE *surf_file_to_parse = NULL; -void nil_function(void); -void nil_function(void) +void make_route_table(void) { - return; + xbt_dict_cursor_t cursor = NULL; + char *key,*data; + const char *sep = "##"; + + xbt_dict_foreach(route_table, cursor, key, data) { + links = (xbt_dynar_t)data; + keys = xbt_str_split_str(key, sep); + surfxml_call_cb_functions(ETag_surfxml_platform_cb_list); + } + + xbt_dict_free(&route_table); + xbt_dynar_free(&links); + } -YY_BUFFER_STATE surf_input_buffer; -FILE *surf_file_to_parse; +void surf_parse_free_callbacks(void) +{ + xbt_dynar_free(&STag_surfxml_platform_cb_list); + xbt_dynar_free(&ETag_surfxml_platform_cb_list); + xbt_dynar_free(&STag_surfxml_host_cb_list); + xbt_dynar_free(&ETag_surfxml_host_cb_list); + xbt_dynar_free(&STag_surfxml_router_cb_list); + xbt_dynar_free(&ETag_surfxml_router_cb_list); + xbt_dynar_free(&STag_surfxml_link_cb_list); + xbt_dynar_free(&ETag_surfxml_link_cb_list); + xbt_dynar_free(&STag_surfxml_route_cb_list); + xbt_dynar_free(&ETag_surfxml_route_cb_list); + xbt_dynar_free(&STag_surfxml_link_c_ctn_cb_list); + xbt_dynar_free(&ETag_surfxml_link_c_ctn_cb_list); + xbt_dynar_free(&STag_surfxml_process_cb_list); + xbt_dynar_free(&ETag_surfxml_process_cb_list); + xbt_dynar_free(&STag_surfxml_argument_cb_list); + xbt_dynar_free(&ETag_surfxml_argument_cb_list); + xbt_dynar_free(&STag_surfxml_prop_cb_list); + xbt_dynar_free(&ETag_surfxml_prop_cb_list); +} void surf_parse_reset_parser(void) { - - 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); + surf_parse_free_callbacks(); + STag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); + ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL); } @@ -78,14 +138,14 @@ void ETag_surfxml_include(void) xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer); } -void STag_surfxml_platform_description(void) +void STag_surfxml_platform(void) { double version = 0.0; - sscanf(A_surfxml_platform_description_version, "%lg", &version); + sscanf(A_surfxml_platform_version, "%lg", &version); xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n " - "You're using an old XML file. " + "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 " @@ -95,13 +155,19 @@ void STag_surfxml_platform_description(void) "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)."); + 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."); - surfxml_call_cb_functions(STag_surfxml_platform_description_cb_list); + surfxml_call_cb_functions(STag_surfxml_platform_cb_list); } -void ETag_surfxml_platform_description(void) +void ETag_surfxml_platform(void) { - surfxml_call_cb_functions(ETag_surfxml_platform_description_cb_list); + if (route_table != NULL) make_route_table(); } void STag_surfxml_host(void) @@ -266,11 +332,33 @@ 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) +static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list) { - int iterator; - void_f_void_t data; - xbt_dynar_foreach(cb_list, iterator, data){ - (*data)(); + unsigned int iterator; + void_f_void_t fun; + xbt_dynar_foreach(cb_list, iterator, fun){ + DEBUG2("call %p %p",fun,*fun); + (*fun)(); } } + +void init_route_table(void) +{ + xbt_dict_free(&route_table); + xbt_dynar_free(&route_link_list); + route_table = xbt_dict_new(); +} + +void parse_route_elem(void) +{ + char *val; + val = xbt_strdup(A_surfxml_link_c_ctn_id); + xbt_dynar_push(route_link_list, &val); +} + +void parse_platform_file(const char* file) +{ + surf_parse_open(file); + xbt_assert1((!(*surf_parse)()), "Parse error in %s", file); + surf_parse_close(); +}