X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/62be96c324e33952038493a0aef1bb4a518766c3..bea6786798593b78e0d62a2308eacad3284d4537:/src/surf/surfxml_parse.c diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index 0698fede72..49fd6ac65e 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -17,8 +17,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, #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_description_cb_list = NULL; -xbt_dynar_t ETag_surfxml_platform_description_cb_list = NULL; +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; @@ -37,36 +37,80 @@ 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; -static inline 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; -void surf_parse_reset_parser(void) +void make_route_table(void) { + xbt_dict_cursor_t cursor = NULL; + char *key,*data; + const char *sep = "##"; - 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); + 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); + +} + +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) +{ + 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); } @@ -94,11 +138,11 @@ 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 ancient XML file. " @@ -118,12 +162,12 @@ void STag_surfxml_platform_description(void) "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) @@ -288,12 +332,33 @@ void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function) xbt_dynar_push(cb_list, &function); } -static inline 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; + 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(); +}