From: Martin Quinson Date: Fri, 4 Nov 2011 20:33:29 +0000 (+0100) Subject: Clean callbacks for the host parsing. X-Git-Tag: exp_20120216~485 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/70388188c97f56fbe2b645c9b00dcb05d0b86509?hp=04cb6e6a844ba34246d7ba001452f8aeaed9a6f9 Clean callbacks for the host parsing. - do not rely on global field, but pass the parameter to the callbacks - do not show the dynar containing the callbacks to the public, but provide a specific function to add a callback not needing to see the dynar This breaks some tests, but I need to split my changes to see when I improve the situation, and revert stuff when I degrade the situation. I start to fix the tests right away. --- diff --git a/include/surf/surfxml_parse.h b/include/surf/surfxml_parse.h index ef751eb5eb..63bdca1b1e 100644 --- a/include/surf/surfxml_parse.h +++ b/include/surf/surfxml_parse.h @@ -17,7 +17,6 @@ SG_BEGIN_DECL() /* Hook for the different tags. All the functions which pointer to are push into here are run when the tag is encountered */ XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_platform_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_platform_cb_list; -XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_host_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_host_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_router_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_router_cb_list; diff --git a/src/include/surf/surfxml_parse_values.h b/src/include/surf/surfxml_parse_values.h index 8a25ca11d7..70cbc24a26 100644 --- a/src/include/surf/surfxml_parse_values.h +++ b/src/include/surf/surfxml_parse_values.h @@ -59,29 +59,32 @@ typedef struct s_surf_parsing_router_arg { typedef struct s_surf_parsing_host_arg *surf_parsing_host_arg_t; typedef struct s_surf_parsing_host_arg { - char* V_host_id; //id - double V_host_power_peak; //power - int V_host_core; //core - double V_host_power_scale; //availability - tmgr_trace_t V_host_power_trace; //availability file - e_surf_resource_state_t V_host_state_initial; //state - tmgr_trace_t V_host_state_trace; //state file + char* V_host_id; //id + double V_host_power_peak; //power + int V_host_core; //core + double V_host_power_scale; //availability + tmgr_trace_t V_host_power_trace; //availability file + e_surf_resource_state_t V_host_state_initial; //state + tmgr_trace_t V_host_state_trace; //state file const char* V_host_coord; } s_surf_parsing_host_arg_t; -extern surf_parsing_host_arg_t struct_host; -extern surf_parsing_router_arg_t struct_router; -extern surf_parsing_cluster_arg_t struct_cluster; -extern surf_parsing_peer_arg_t struct_peer; -extern surf_parsing_link_arg_t struct_lnk; - typedef struct s_surf_parsing_link_up_down *surf_parsing_link_up_down_t; typedef struct s_surf_parsing_link_up_down { void* link_up; void* link_down; } s_surf_parsing_link_up_down_t; -void surf_parse_host(void); + +typedef void (*surf_parse_host_fct_t)(surf_parsing_host_arg_t); +void surf_parse_host_add_cb(surf_parse_host_fct_t); + +extern surf_parsing_router_arg_t struct_router; +extern surf_parsing_cluster_arg_t struct_cluster; +extern surf_parsing_peer_arg_t struct_peer; +extern surf_parsing_link_arg_t struct_lnk; + +void surf_parse_host(surf_parsing_host_arg_t h); void surf_parse_link(void); #endif /* SURFXML_PARSE_VALUES_H_ */ diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index ae3ea4b285..9d7488c32b 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -225,14 +225,14 @@ static void instr_routing_parse_start_link () xbt_dynar_free (&links_to_create); } -static void instr_routing_parse_start_host () +static void instr_routing_parse_start_host (surf_parsing_host_arg_t host) { container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1); - container_t new = newContainer (struct_host->V_host_id, INSTR_HOST, father); + container_t new = newContainer (host->V_host_id, INSTR_HOST, father); if (TRACE_categorized() || TRACE_uncategorized()) { type_t power = getVariableType ("power", NULL, new->type); - new_pajeSetVariable (0, new, power, struct_host->V_host_power_peak); + new_pajeSetVariable (0, new, power, host->V_host_power_peak); } if (TRACE_uncategorized()){ getVariableType ("power_used", "0.5 0.5 0.5", new->type); @@ -292,7 +292,7 @@ void instr_routing_define_callbacks () surfxml_add_callback(ETag_surfxml_AS_cb_list, &instr_routing_parse_end_AS); if (!TRACE_needs_platform()) return; surfxml_add_callback(STag_surfxml_link_cb_list, &instr_routing_parse_start_link); - surfxml_add_callback(STag_surfxml_host_cb_list, &instr_routing_parse_start_host); + surf_parse_host_add_cb(instr_routing_parse_start_host); surfxml_add_callback(STag_surfxml_router_cb_list, &instr_routing_parse_start_router); surfxml_add_callback(ETag_surfxml_platform_cb_list, &instr_routing_parse_end_platform); } diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 2124426359..1bbeb9ff1a 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -71,17 +71,17 @@ static void* cpu_create_resource(const char *name, double power_peak, } -static void parse_cpu_init(void) +static void parse_cpu_init(surf_parsing_host_arg_t host) { - if(strcmp(struct_host->V_host_coord,"")) xbt_die("Coordinates not implemented yet!"); - - cpu_create_resource(struct_host->V_host_id, - struct_host->V_host_power_peak, - struct_host->V_host_power_scale, - struct_host->V_host_power_trace, - struct_host->V_host_core, - struct_host->V_host_state_initial, - struct_host->V_host_state_trace, + if(strcmp(host->V_host_coord,"")) xbt_die("Coordinates not implemented yet!"); + + cpu_create_resource(host->V_host_id, + host->V_host_power_peak, + host->V_host_power_scale, + host->V_host_power_trace, + host->V_host_core, + host->V_host_state_initial, + host->V_host_state_trace, current_property_set); current_property_set = NULL; } @@ -124,7 +124,7 @@ static void add_traces_cpu(void) static void cpu_define_callbacks(void) { - surfxml_add_callback(ETag_surfxml_host_cb_list, parse_cpu_init); + surf_parse_host_add_cb(parse_cpu_init); surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces_cpu); } diff --git a/src/surf/cpu_im.c b/src/surf/cpu_im.c index caa3a9d284..14c9cfb4ca 100644 --- a/src/surf/cpu_im.c +++ b/src/surf/cpu_im.c @@ -88,15 +88,15 @@ static void* cpu_im_create_resource(const char *name, double power_peak, } -static void parse_cpu_im_init(void) +static void parse_cpu_im_init(surf_parsing_host_arg_t host) { - cpu_im_create_resource(struct_host->V_host_id, - struct_host->V_host_power_peak, - struct_host->V_host_power_scale, - struct_host->V_host_power_trace, - struct_host->V_host_core, - struct_host->V_host_state_initial, - struct_host->V_host_state_trace, + cpu_im_create_resource(host->V_host_id, + host->V_host_power_peak, + host->V_host_power_scale, + host->V_host_power_trace, + host->V_host_core, + host->V_host_state_initial, + host->V_host_state_trace, current_property_set); current_property_set = NULL; } @@ -136,7 +136,7 @@ static void cpu_im_add_traces_cpu(void) static void cpu_im_define_callbacks() { - surfxml_add_callback(ETag_surfxml_host_cb_list, parse_cpu_im_init); + surf_parse_host_add_cb(parse_cpu_im_init); surfxml_add_callback(ETag_surfxml_platform_cb_list, &cpu_im_add_traces_cpu); } diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c index b18b735c25..fe6e4f446e 100644 --- a/src/surf/cpu_ti.c +++ b/src/surf/cpu_ti.c @@ -190,15 +190,15 @@ static void* cpu_ti_create_resource(const char *name, double power_peak, } -static void parse_cpu_ti_init(void) +static void parse_cpu_ti_init(surf_parsing_host_arg_t host) { - cpu_ti_create_resource(struct_host->V_host_id, - struct_host->V_host_power_peak, - struct_host->V_host_power_scale, - struct_host->V_host_power_trace, - struct_host->V_host_core, - struct_host->V_host_state_initial, - struct_host->V_host_state_trace, + cpu_ti_create_resource(host->V_host_id, + host->V_host_power_peak, + host->V_host_power_scale, + host->V_host_power_trace, + host->V_host_core, + host->V_host_state_initial, + host->V_host_state_trace, current_property_set); current_property_set = NULL; @@ -263,7 +263,7 @@ static void add_traces_cpu_ti(void) static void cpu_ti_define_callbacks() { - surfxml_add_callback(ETag_surfxml_host_cb_list, parse_cpu_ti_init); + surf_parse_host_add_cb(parse_cpu_ti_init); surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces_cpu_ti); } diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 4c9db111f3..f4251f081d 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -21,14 +21,14 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); static random_data_t random_latency = NULL; static int host_number_int = 0; -static void netcste_count_hosts(void) +static void netcste_count_hosts(surf_parsing_host_arg_t h) { host_number_int++; } static void netcste_define_callbacks(void) { - surfxml_add_callback(STag_surfxml_host_cb_list, &netcste_count_hosts); + surf_parse_host_add_cb(netcste_count_hosts); } static int netcste_resource_used(void *resource_id) diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index c9fb2c5516..e5e66a034b 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -186,11 +186,9 @@ static void parse_E_host(void) /* * \brief Add a host to the network element list from XML */ -static void parse_S_host_XML(void) +static void parse_S_host_XML(surf_parsing_host_arg_t h) { -// XBT_INFO("parse_S_host_XML"); -// XBT_INFO("'%s' '%s'",struct_host->V_host_id, struct_host->V_host_coord); - parse_S_host(struct_host->V_host_id, struct_host->V_host_coord); + parse_S_host(h->V_host_id, h->V_host_coord); } static void parse_E_host_XML(void) { @@ -972,7 +970,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_ current_routing = NULL; /* parse generic elements */ - surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML); + surf_parse_host_add_cb(parse_S_host_XML); surfxml_add_callback(ETag_surfxml_host_cb_list, &parse_E_host_XML); surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router_XML); @@ -1504,6 +1502,8 @@ static void routing_parse_Econfig(void) static void parse_create_host_link(int i) { char *host_id, *link_id = NULL; + s_surf_parsing_host_arg_t host; + memset(&host,0,sizeof(host)); host_id = bprintf("%s%d%s", struct_cluster->V_cluster_prefix, i, struct_cluster->V_cluster_suffix); link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, i); @@ -1511,14 +1511,13 @@ static void parse_create_host_link(int i) A_surfxml_host_state = A_surfxml_host_state_ON; XBT_DEBUG("", host_id, struct_cluster->S_cluster_power); - struct_host = xbt_new0(s_surf_parsing_host_arg_t, 1); - struct_host->V_host_id = xbt_strdup(host_id); + host.V_host_id = xbt_strdup(host_id); if(strcmp(struct_cluster->V_cluster_availability_file,"")){ xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free); char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file); xbt_str_varsubst(tmp_availability_file,patterns); XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file); - struct_host->V_host_power_trace = tmgr_trace_new(tmp_availability_file); + host.V_host_power_trace = tmgr_trace_new(tmp_availability_file); xbt_free(tmp_availability_file); } else @@ -1529,7 +1528,7 @@ static void parse_create_host_link(int i) char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file); xbt_str_varsubst(tmp_state_file,patterns); XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file); - struct_host->V_host_state_trace = tmgr_trace_new(tmp_state_file); + host.V_host_state_trace = tmgr_trace_new(tmp_state_file); xbt_free(tmp_state_file); } else @@ -1537,12 +1536,12 @@ static void parse_create_host_link(int i) XBT_DEBUG("\tstate_file=\"\""); } - struct_host->V_host_power_peak = struct_cluster->S_cluster_power; - struct_host->V_host_power_scale = 1.0; - struct_host->V_host_core = struct_cluster->S_cluster_core; - struct_host->V_host_state_initial = SURF_RESOURCE_ON; - struct_host->V_host_coord = ""; - surf_parse_host(); + host.V_host_power_peak = struct_cluster->S_cluster_power; + host.V_host_power_scale = 1.0; + host.V_host_core = struct_cluster->S_cluster_core; + host.V_host_state_initial = SURF_RESOURCE_ON; + host.V_host_coord = ""; + surf_parse_host(&host); XBT_DEBUG(""); A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; @@ -1604,6 +1603,8 @@ void routing_parse_Scluster(void) static int AX_ptr = 0; char *host_id, *groups, *link_id = NULL; + s_surf_parsing_host_arg_t host; + if( strcmp(struct_cluster->V_cluster_availability_file,"") || strcmp(struct_cluster->V_cluster_state_file,"") ) { @@ -1633,6 +1634,8 @@ void routing_parse_Scluster(void) //Make all hosts radical_elements = xbt_str_split(struct_cluster->V_cluster_radical, ","); xbt_dynar_foreach(radical_elements, iter, groups) { + memset(&host,0,sizeof(host)); + radical_ends = xbt_str_split(groups, "-"); switch (xbt_dynar_length(radical_ends)) { case 1: @@ -1641,14 +1644,13 @@ void routing_parse_Scluster(void) link_id = bprintf("%s_link_%d", struct_cluster->V_cluster_id, start); XBT_DEBUG("", host_id, struct_cluster->S_cluster_power); - struct_host = xbt_new0(s_surf_parsing_host_arg_t, 1); - struct_host->V_host_id = host_id; + host.V_host_id = host_id; if(strcmp(struct_cluster->V_cluster_availability_file,"")){ xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free); char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file); xbt_str_varsubst(tmp_availability_file,patterns); XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file); - struct_host->V_host_power_trace = tmgr_trace_new(tmp_availability_file); + host.V_host_power_trace = tmgr_trace_new(tmp_availability_file); xbt_free(tmp_availability_file); } else @@ -1659,7 +1661,7 @@ void routing_parse_Scluster(void) char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file); xbt_str_varsubst(tmp_state_file,patterns); XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file); - struct_host->V_host_state_trace = tmgr_trace_new(tmp_state_file); + host.V_host_state_trace = tmgr_trace_new(tmp_state_file); xbt_free(tmp_state_file); } else @@ -1667,12 +1669,12 @@ void routing_parse_Scluster(void) XBT_DEBUG("\tstate_file=\"\""); } - struct_host->V_host_power_peak = struct_cluster->S_cluster_power; - struct_host->V_host_power_scale = 1.0; - struct_host->V_host_core = struct_cluster->S_cluster_core; - struct_host->V_host_state_initial = SURF_RESOURCE_ON; - struct_host->V_host_coord = ""; - surf_parse_host(); + host.V_host_power_peak = struct_cluster->S_cluster_power; + host.V_host_power_scale = 1.0; + host.V_host_core = struct_cluster->S_cluster_core; + host.V_host_state_initial = SURF_RESOURCE_ON; + host.V_host_coord = ""; + surf_parse_host(&host); XBT_DEBUG(""); A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; @@ -1723,14 +1725,13 @@ void routing_parse_Scluster(void) A_surfxml_host_state = A_surfxml_host_state_ON; XBT_DEBUG("", host_id, struct_cluster->S_cluster_power); - struct_host = xbt_new0(s_surf_parsing_host_arg_t, 1); - struct_host->V_host_id = host_id; + host.V_host_id = host_id; if(strcmp(struct_cluster->V_cluster_availability_file,"")){ xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free); char* tmp_availability_file = xbt_strdup(struct_cluster->V_cluster_availability_file); xbt_str_varsubst(tmp_availability_file,patterns); XBT_DEBUG("\tavailability_file=\"%s\"",tmp_availability_file); - struct_host->V_host_power_trace = tmgr_trace_new(tmp_availability_file); + host.V_host_power_trace = tmgr_trace_new(tmp_availability_file); xbt_free(tmp_availability_file); } else @@ -1741,7 +1742,7 @@ void routing_parse_Scluster(void) char *tmp_state_file = xbt_strdup(struct_cluster->V_cluster_state_file); xbt_str_varsubst(tmp_state_file,patterns); XBT_DEBUG("\tstate_file=\"%s\"",tmp_state_file); - struct_host->V_host_state_trace = tmgr_trace_new(tmp_state_file); + host.V_host_state_trace = tmgr_trace_new(tmp_state_file); xbt_free(tmp_state_file); } else @@ -1749,12 +1750,12 @@ void routing_parse_Scluster(void) XBT_DEBUG("\tstate_file=\"\""); } - struct_host->V_host_power_peak = struct_cluster->S_cluster_power; - struct_host->V_host_power_scale = 1.0; - struct_host->V_host_core = struct_cluster->S_cluster_core; - struct_host->V_host_state_initial = SURF_RESOURCE_ON; - struct_host->V_host_coord = ""; - surf_parse_host(); + host.V_host_power_peak = struct_cluster->S_cluster_power; + host.V_host_power_scale = 1.0; + host.V_host_core = struct_cluster->S_cluster_core; + host.V_host_state_initial = SURF_RESOURCE_ON; + host.V_host_coord = ""; + surf_parse_host(&host); XBT_DEBUG(""); A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; diff --git a/src/surf/surf_routing_cluster.c b/src/surf/surf_routing_cluster.c index f5d0d0db0a..5236ef762c 100644 --- a/src/surf/surf_routing_cluster.c +++ b/src/surf/surf_routing_cluster.c @@ -41,7 +41,6 @@ static route_extended_t cluster_get_route(routing_component_t rc, xbt_dynar_t links_list = xbt_dynar_new(global_routing->size_of_link, NULL); - char *link_src,*link_bb,*link_dst,*link_src_up,*link_dst_down; surf_parsing_link_up_down_t info; info = xbt_dict_get_or_null(cluster_host_link,src); diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index b6a745fb8a..4db9fccd9a 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -44,9 +44,10 @@ void surf_parse_get_int(int *value, const char *string) { */ /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */ +//xbt_dynar_t STag_surfxml_host_cb_list = NULL; +xbt_dynar_t surf_parse_host_cb_list = NULL; // of functions of type: surf_parsing_host_arg_t -> void 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; @@ -158,7 +159,9 @@ void surf_parse_init_callbacks(void) 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); + + surf_parse_host_cb_list = xbt_dynar_new(sizeof(surf_parse_host_fct_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); @@ -224,9 +227,10 @@ void surf_parse_reset_callbacks(void) void surf_parse_free_callbacks(void) { + xbt_dynar_free(&surf_parse_host_cb_list); + 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); @@ -297,32 +301,40 @@ void STag_surfxml_platform(void) void STag_surfxml_host(void){ // XBT_INFO("STag_surfxml_host [%s]",A_surfxml_host_id); - struct_host = xbt_new0(s_surf_parsing_host_arg_t, 1); - struct_host->V_host_id = xbt_strdup(A_surfxml_host_id); - struct_host->V_host_power_peak = get_cpu_power(A_surfxml_host_power); - surf_parse_get_double(&(struct_host->V_host_power_scale), A_surfxml_host_availability); - surf_parse_get_int(&(struct_host->V_host_core),A_surfxml_host_core); - struct_host->V_host_power_trace = tmgr_trace_new(A_surfxml_host_availability_file); - struct_host->V_host_state_trace = tmgr_trace_new(A_surfxml_host_state_file); + s_surf_parsing_host_arg_t host; + memset(&host,0,sizeof(host)); + + host.V_host_id = xbt_strdup(A_surfxml_host_id); + host.V_host_power_peak = get_cpu_power(A_surfxml_host_power); + surf_parse_get_double(&(host.V_host_power_scale), A_surfxml_host_availability); + surf_parse_get_int(&(host.V_host_core),A_surfxml_host_core); + host.V_host_power_trace = tmgr_trace_new(A_surfxml_host_availability_file); + host.V_host_state_trace = tmgr_trace_new(A_surfxml_host_state_file); xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) || (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state"); if (A_surfxml_host_state == A_surfxml_host_state_ON) - struct_host->V_host_state_initial = SURF_RESOURCE_ON; + host.V_host_state_initial = SURF_RESOURCE_ON; if (A_surfxml_host_state == A_surfxml_host_state_OFF) - struct_host->V_host_state_initial = SURF_RESOURCE_OFF; - struct_host->V_host_coord = xbt_strdup(A_surfxml_host_coordinates); + host.V_host_state_initial = SURF_RESOURCE_OFF; + host.V_host_coord = xbt_strdup(A_surfxml_host_coordinates); - surf_parse_host(); + surf_parse_host(&host); } -void surf_parse_host(void){ - surfxml_call_cb_functions(STag_surfxml_host_cb_list); +void surf_parse_host(surf_parsing_host_arg_t h){ + unsigned int iterator; + surf_parse_host_fct_t fun; + xbt_dynar_foreach(surf_parse_host_cb_list, iterator, fun) { + if (fun) (*fun) (h); + } +} +void surf_parse_host_add_cb(surf_parse_host_fct_t fct) { + xbt_dynar_push(surf_parse_host_cb_list, &fct); } void ETag_surfxml_host(void){ surfxml_call_cb_functions(ETag_surfxml_host_cb_list); - xbt_free(struct_host->V_host_id); - xbt_free(struct_host); } + void STag_surfxml_router(void){ struct_router = xbt_new0(s_surf_parsing_router_arg_t, 1); struct_router->V_router_id = xbt_strdup(A_surfxml_router_id); diff --git a/src/surf/surfxml_parseplatf.c b/src/surf/surfxml_parseplatf.c index 202fbe1b6c..d37459aa28 100644 --- a/src/surf/surfxml_parseplatf.c +++ b/src/surf/surfxml_parseplatf.c @@ -52,7 +52,6 @@ void surfxml_bufferstack_pop(int new) * Pass arguments to parsing callback as structures to save some time (and allow callbacks to ignore some) */ -surf_parsing_host_arg_t struct_host = NULL; surf_parsing_router_arg_t struct_router = NULL; surf_parsing_cluster_arg_t struct_cluster = NULL; surf_parsing_peer_arg_t struct_peer = NULL; diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 1878ea44c2..726ecb5db7 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -654,16 +654,16 @@ static void* ptask_cpu_create_resource(const char *name, double power_scale, return cpu; } -static void ptask_parse_cpu_init(void) +static void ptask_parse_cpu_init(surf_parsing_host_arg_t host) { ptask_cpu_create_resource( - struct_host->V_host_id, - struct_host->V_host_power_peak, - struct_host->V_host_power_scale, - struct_host->V_host_power_trace, - struct_host->V_host_state_initial, - struct_host->V_host_state_trace, - current_property_set); + host->V_host_id, + host->V_host_power_peak, + host->V_host_power_scale, + host->V_host_power_trace, + host->V_host_state_initial, + host->V_host_state_trace, + current_property_set); current_property_set=NULL; } @@ -802,7 +802,7 @@ static void ptask_add_traces(void) static void ptask_define_callbacks() { /* Adding callback functions */ - surfxml_add_callback(ETag_surfxml_host_cb_list, &ptask_parse_cpu_init); + surf_parse_host_add_cb(ptask_parse_cpu_init); surfxml_add_callback(ETag_surfxml_link_cb_list, &ptask_parse_link_init); surfxml_add_callback(ETag_surfxml_platform_cb_list, &ptask_add_traces); }