Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further parser cleanups
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 7 Nov 2011 17:05:18 +0000 (18:05 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 7 Nov 2011 17:05:18 +0000 (18:05 +0100)
Properly integrate the begin and end of platform definition in sg_platf.

New public functions:
 - sg_platf_open()
 - sg_platf_close()
New internal callback:
 - sg_platf_postparse_add_cb(void_f_void_t)
 (nobody cares about sg_platf_open(), it's just here for cosmetics in
  user code)

14 files changed:
include/simgrid/platf.h
include/surf/surfxml_parse.h
src/include/simgrid/platf_interface.h
src/instr/instr_routing.c
src/surf/cpu.c
src/surf/cpu_im.c
src/surf/cpu_ti.c
src/surf/network.c
src/surf/network_im.c
src/surf/sg_platf.c
src/surf/surf_routing.c
src/surf/surfxml_parse.c
src/surf/surfxml_parseplatf.c
src/surf/workstation_ptask_L07.c

index fc3704c..5ad299f 100644 (file)
@@ -47,12 +47,14 @@ typedef struct {
   const char* V_router_coord;
 } s_sg_platf_router_cbarg_t, *sg_platf_router_cbarg_t;
 
   const char* V_router_coord;
 } s_sg_platf_router_cbarg_t, *sg_platf_router_cbarg_t;
 
+XBT_PUBLIC(void) sg_platf_open(void);  // Start a new platform
+XBT_PUBLIC(void) sg_platf_close(void); // Finish the creation of the platform
 
 
-XBT_PUBLIC(void) sg_platf_new_AS_open(const char *id, const char *mode);
-XBT_PUBLIC(void) sg_platf_new_AS_close(void);
+XBT_PUBLIC(void) sg_platf_new_AS_open(const char *id, const char *mode); // Begin description of new AS
+XBT_PUBLIC(void) sg_platf_new_AS_close(void);                            // That AS is fully described
 
 
-XBT_PUBLIC(void) sg_platf_new_host  (sg_platf_host_cbarg_t   host);
-XBT_PUBLIC(void) sg_platf_new_router(sg_platf_router_cbarg_t router);
+XBT_PUBLIC(void) sg_platf_new_host  (sg_platf_host_cbarg_t   host);   // Add an host  to the currently described AS
+XBT_PUBLIC(void) sg_platf_new_router(sg_platf_router_cbarg_t router); // Add a router to the currently described AS
 
 
 #endif                          /* SG_PLATF_H */
 
 
 #endif                          /* SG_PLATF_H */
index 65407b8..eaf8897 100644 (file)
@@ -15,8 +15,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 */
 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_link_cb_list;
 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_link_cb_list;
 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_route_cb_list;
 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_link_cb_list;
 XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_link_cb_list;
 XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_route_cb_list;
index 7e8eb3f..c17c0bc 100644 (file)
@@ -21,6 +21,7 @@ typedef void (*sg_platf_host_cb_t)(sg_platf_host_cbarg_t);
 typedef void (*sg_platf_router_cb_t)(sg_platf_router_cbarg_t);
 void sg_platf_host_add_cb(sg_platf_host_cb_t);
 void sg_platf_router_add_cb(sg_platf_router_cb_t);
 typedef void (*sg_platf_router_cb_t)(sg_platf_router_cbarg_t);
 void sg_platf_host_add_cb(sg_platf_host_cb_t);
 void sg_platf_router_add_cb(sg_platf_router_cb_t);
+void sg_platf_postparse_add_cb(void_f_void_t fct);
 
 
 
 
 
 
index 8f913c3..1388256 100644 (file)
@@ -294,7 +294,8 @@ void instr_routing_define_callbacks ()
   surfxml_add_callback(STag_surfxml_link_cb_list, &instr_routing_parse_start_link);
   sg_platf_host_add_cb(instr_routing_parse_start_host);
   sg_platf_router_add_cb(instr_routing_parse_start_router);
   surfxml_add_callback(STag_surfxml_link_cb_list, &instr_routing_parse_start_link);
   sg_platf_host_add_cb(instr_routing_parse_start_host);
   sg_platf_router_add_cb(instr_routing_parse_start_router);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &instr_routing_parse_end_platform);
+
+  sg_platf_postparse_add_cb(instr_routing_parse_end_platform);
 }
 
 /*
 }
 
 /*
index b7012df..d08b7e0 100644 (file)
@@ -124,7 +124,7 @@ static void add_traces_cpu(void)
 static void cpu_define_callbacks(void)
 {
   sg_platf_host_add_cb(parse_cpu_init);
 static void cpu_define_callbacks(void)
 {
   sg_platf_host_add_cb(parse_cpu_init);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces_cpu);
+  sg_platf_postparse_add_cb(add_traces_cpu);
 }
 
 static int cpu_resource_used(void *resource_id)
 }
 
 static int cpu_resource_used(void *resource_id)
index ada8774..d1c841e 100644 (file)
@@ -136,8 +136,7 @@ static void cpu_im_add_traces_cpu(void)
 static void cpu_im_define_callbacks()
 {
   sg_platf_host_add_cb(parse_cpu_im_init);
 static void cpu_im_define_callbacks()
 {
   sg_platf_host_add_cb(parse_cpu_im_init);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list,
-                       &cpu_im_add_traces_cpu);
+  sg_platf_postparse_add_cb(cpu_im_add_traces_cpu);
 }
 
 static int cpu_im_resource_used(void *resource)
 }
 
 static int cpu_im_resource_used(void *resource)
index 7c1a1a6..db57d05 100644 (file)
@@ -263,7 +263,7 @@ static void add_traces_cpu_ti(void)
 static void cpu_ti_define_callbacks()
 {
   sg_platf_host_add_cb(parse_cpu_ti_init);
 static void cpu_ti_define_callbacks()
 {
   sg_platf_host_add_cb(parse_cpu_ti_init);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces_cpu_ti);
+  sg_platf_postparse_add_cb(add_traces_cpu_ti);
 }
 
 static int cpu_ti_resource_used(void *resource_id)
 }
 
 static int cpu_ti_resource_used(void *resource_id)
index 2d4158c..166e928 100644 (file)
@@ -274,7 +274,7 @@ static void net_define_callbacks(void)
 {
   /* Figuring out the network links */
   surfxml_add_callback(STag_surfxml_link_cb_list, &net_parse_link_init);
 {
   /* Figuring out the network links */
   surfxml_add_callback(STag_surfxml_link_cb_list, &net_parse_link_init);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &net_add_traces);
+  sg_platf_postparse_add_cb(net_add_traces);
 }
 
 static int net_resource_used(void *resource_id)
 }
 
 static int net_resource_used(void *resource_id)
index 7a4887c..a31e8c2 100644 (file)
@@ -267,7 +267,7 @@ static void im_net_define_callbacks(void)
 {
   /* Figuring out the network links */
   surfxml_add_callback(STag_surfxml_link_cb_list, &im_net_parse_link_init);
 {
   /* Figuring out the network links */
   surfxml_add_callback(STag_surfxml_link_cb_list, &im_net_parse_link_init);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &im_net_add_traces);
+  sg_platf_postparse_add_cb(im_net_add_traces);
 }
 
 static int im_net_resource_used(void *resource_id)
 }
 
 static int im_net_resource_used(void *resource_id)
index 219a30a..773cc49 100644 (file)
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
 xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
 xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t
+xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
 
 /** Module management function: creates all internal data structures */
 void sg_platf_init(void) {
   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
 
 /** Module management function: creates all internal data structures */
 void sg_platf_init(void) {
   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
+  sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
 }
 /** Module management function: frees all internal data structures */
 void sg_platf_exit(void) {
   xbt_dynar_free(&sg_platf_host_cb_list);
   xbt_dynar_free(&sg_platf_router_cb_list);
 }
 /** Module management function: frees all internal data structures */
 void sg_platf_exit(void) {
   xbt_dynar_free(&sg_platf_host_cb_list);
   xbt_dynar_free(&sg_platf_router_cb_list);
+  xbt_dynar_free(&sg_platf_postparse_cb_list);
 }
 
 void sg_platf_new_host(sg_platf_host_cbarg_t h){
   unsigned int iterator;
   sg_platf_host_cb_t fun;
   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
 }
 
 void sg_platf_new_host(sg_platf_host_cbarg_t h){
   unsigned int iterator;
   sg_platf_host_cb_t fun;
   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
-    if (fun) (*fun) (h);
+    (*fun) (h);
   }
 }
 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
   unsigned int iterator;
   sg_platf_router_cb_t fun;
   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
   }
 }
 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
   unsigned int iterator;
   sg_platf_router_cb_t fun;
   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
-    if (fun) (*fun) (router);
+    (*fun) (router);
+  }
+}
+void sg_platf_open() { /* Do nothing: just for symmetry of user code */ }
+
+void sg_platf_close() {
+  unsigned int iterator;
+  void_f_void_t fun;
+  xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
+    (*fun) ();
   }
 }
 
   }
 }
 
@@ -48,4 +60,7 @@ void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
   xbt_dynar_push(sg_platf_router_cb_list, &fct);
 }
 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
   xbt_dynar_push(sg_platf_router_cb_list, &fct);
 }
+void sg_platf_postparse_add_cb(void_f_void_t fct) {
+  xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
+}
 
 
index 935b858..25ffc1b 100644 (file)
@@ -53,7 +53,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 
 static void routing_parse_Speer(void);          /* peer bypass */
 static void routing_parse_Srandom(void);        /* random bypass */
 
 static void routing_parse_Speer(void);          /* peer bypass */
 static void routing_parse_Srandom(void);        /* random bypass */
-static void routing_parse_Erandom(void);        /* random bypass */
 
 static char* replace_random_parameter(char * chaine);
 static void clean_routing_after_parse(void);
 
 static char* replace_random_parameter(char * chaine);
 static void clean_routing_after_parse(void);
@@ -763,7 +762,6 @@ void surf_parse_models_setup()
   if (surf_parse_models_setup_already_called)
     return;
   surf_parse_models_setup_already_called=1;
   if (surf_parse_models_setup_already_called)
     return;
   surf_parse_models_setup_already_called=1;
-  routing_parse_Erandom();
   surf_config_models_setup();
 }
 
   surf_config_models_setup();
 }
 
@@ -912,8 +910,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_
   surfxml_add_callback(STag_surfxml_peer_cb_list,
                          &routing_parse_Speer);
 
   surfxml_add_callback(STag_surfxml_peer_cb_list,
                          &routing_parse_Speer);
 
-  surfxml_add_callback(ETag_surfxml_platform_cb_list,
-                                                 &clean_routing_after_parse);
+  sg_platf_postparse_add_cb(clean_routing_after_parse);
 
 #ifdef HAVE_TRACING
   instr_routing_define_callbacks();
 
 #ifdef HAVE_TRACING
   instr_routing_define_callbacks();
@@ -922,10 +919,10 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_
 
 void surf_parse_add_callback_config(void)
 {
 
 void surf_parse_add_callback_config(void)
 {
-       surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
-       surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
+  surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
 }
 
 }
 
+
 /* ************************************************** */
 /* ********** PATERN FOR NEW ROUTING **************** */
 
 /* ************************************************** */
 /* ********** PATERN FOR NEW ROUTING **************** */
 
@@ -1844,121 +1841,109 @@ static void routing_parse_Speer(void)
 
 static void routing_parse_Srandom(void)
 {
 
 static void routing_parse_Srandom(void)
 {
-         double mean, std, min, max, seed;
-         char *random_id = A_surfxml_random_id;
-         char *random_radical = A_surfxml_random_radical;
-         char *rd_name = NULL;
-         char *rd_value;
-         mean = surf_parse_get_double(A_surfxml_random_mean);
-         std  = surf_parse_get_double(A_surfxml_random_std_deviation);
-         min  = surf_parse_get_double(A_surfxml_random_min);
-         max  = surf_parse_get_double(A_surfxml_random_max);
-         seed = surf_parse_get_double(A_surfxml_random_seed);
-
-         double res = 0;
-         int i = 0;
-         random_data_t random = xbt_new0(s_random_data_t, 1);
+    double mean, std, min, max, seed;
+    char *random_id = A_surfxml_random_id;
+    char *random_radical = A_surfxml_random_radical;
+    char *rd_name = NULL;
+    char *rd_value;
+    mean = surf_parse_get_double(A_surfxml_random_mean);
+    std  = surf_parse_get_double(A_surfxml_random_std_deviation);
+    min  = surf_parse_get_double(A_surfxml_random_min);
+    max  = surf_parse_get_double(A_surfxml_random_max);
+    seed = surf_parse_get_double(A_surfxml_random_seed);
+
+    double res = 0;
+    int i = 0;
+    random_data_t random = xbt_new0(s_random_data_t, 1);
           char *tmpbuf;
 
           char *tmpbuf;
 
-         xbt_dynar_t radical_elements;
-         unsigned int iter;
-         char *groups;
-         int start, end;
-         xbt_dynar_t radical_ends;
-
-         random->generator = A_surfxml_random_generator;
-         random->seed = seed;
-         random->min = min;
-         random->max = max;
-
-         /* Check user stupidities */
-         if (max < min)
-           THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
-         if (mean < min)
-           THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
-                  min);
-         if (mean > max)
-           THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
-                  max);
-
-         /* normalize the mean and standard deviation before storing */
-         random->mean = (mean - min) / (max - min);
-         random->std = std / (max - min);
-
-         if (random->mean * (1 - random->mean) < random->std * random->std)
-           THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
-                  random->mean, random->std);
-
-         XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
-         random_id,
-         random->min,
-         random->max,
-         random->mean,
-         random->std,
-         random->generator,
-         random->seed,
-         random_radical);
-
-         if(xbt_dict_size(random_value)==0)
-                 random_value = xbt_dict_new();
-
-         if(!strcmp(random_radical,""))
-         {
-                 res = random_generate(random);
-                 rd_value = bprintf("%f",res);
-                 xbt_dict_set(random_value, random_id, rd_value, free);
-         }
-         else
-         {
-                 radical_elements = xbt_str_split(random_radical, ",");
-                 xbt_dynar_foreach(radical_elements, iter, groups) {
-                       radical_ends = xbt_str_split(groups, "-");
-                       switch (xbt_dynar_length(radical_ends)) {
-                       case 1:
-                                         xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
-                                         res = random_generate(random);
+    xbt_dynar_t radical_elements;
+    unsigned int iter;
+    char *groups;
+    int start, end;
+    xbt_dynar_t radical_ends;
+
+    random->generator = A_surfxml_random_generator;
+    random->seed = seed;
+    random->min = min;
+    random->max = max;
+
+    /* Check user stupidities */
+    if (max < min)
+      THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min);
+    if (mean < min)
+      THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean,
+       min);
+    if (mean > max)
+      THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean,
+       max);
+
+    /* normalize the mean and standard deviation before storing */
+    random->mean = (mean - min) / (max - min);
+    random->std = std / (max - min);
+
+    if (random->mean * (1 - random->mean) < random->std * random->std)
+      THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)",
+       random->mean, random->std);
+
+    XBT_DEBUG("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'",
+    random_id,
+    random->min,
+    random->max,
+    random->mean,
+    random->std,
+    random->generator,
+    random->seed,
+    random_radical);
+
+    if(xbt_dict_size(random_value)==0)
+      random_value = xbt_dict_new();
+
+    if(!strcmp(random_radical,""))
+    {
+      res = random_generate(random);
+      rd_value = bprintf("%f",res);
+      xbt_dict_set(random_value, random_id, rd_value, free);
+    }
+    else
+    {
+      radical_elements = xbt_str_split(random_radical, ",");
+      xbt_dynar_foreach(radical_elements, iter, groups) {
+      radical_ends = xbt_str_split(groups, "-");
+      switch (xbt_dynar_length(radical_ends)) {
+      case 1:
+            xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",random_id);
+            res = random_generate(random);
                                           tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
                                           xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
                                           xbt_free(tmpbuf);
                                           tmpbuf = bprintf("%s%d",random_id,atoi(xbt_dynar_getfirst_as(radical_ends,char *)));
                                           xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
                                           xbt_free(tmpbuf);
-                                         break;
-
-                       case 2:
-                             start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
-                             end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
-                                         for (i = start; i <= end; i++) {
-                                                 xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
-                                                 res = random_generate(random);
+            break;
+
+      case 2:
+            start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
+            end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
+            for (i = start; i <= end; i++) {
+              xbt_assert(!xbt_dict_get_or_null(random_value,random_id),"Custom Random '%s' already exists !",bprintf("%s%d",random_id,i));
+              res = random_generate(random);
                           tmpbuf = bprintf("%s%d",random_id,i);
                           tmpbuf = bprintf("%s%d",random_id,i);
-                                                 xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
+              xbt_dict_set(random_value, tmpbuf, bprintf("%f",res), free);
                           xbt_free(tmpbuf);
                           xbt_free(tmpbuf);
-                                         }
-                                         break;
-                       default:
-                               XBT_INFO("Malformed radical");
-                               break;
-                       }
-                       res = random_generate(random);
-                       rd_name  = bprintf("%s_router",random_id);
-                       rd_value = bprintf("%f",res);
-                       xbt_dict_set(random_value, rd_name, rd_value, free);
-
-                       xbt_dynar_free(&radical_ends);
-                 }
-                 free(rd_name);
-                 xbt_dynar_free(&radical_elements);
-         }
-}
-
-static void routing_parse_Erandom(void)
-{
-       /*xbt_dict_cursor_t cursor = NULL;
-       char *key;
-       char *elem;
+            }
+            break;
+      default:
+        XBT_INFO("Malformed radical");
+        break;
+      }
+      res = random_generate(random);
+      rd_name  = bprintf("%s_router",random_id);
+      rd_value = bprintf("%f",res);
+      xbt_dict_set(random_value, rd_name, rd_value, free);
 
 
-       xbt_dict_foreach(random_value, cursor, key, elem) {
-         XBT_DEBUG("%s = %s",key,elem);
-       }
-*/
+      xbt_dynar_free(&radical_ends);
+      }
+      free(rd_name);
+      xbt_dynar_free(&radical_elements);
+    }
 }
 
 /*
 }
 
 /*
index 2a39d39..9760b4e 100644 (file)
@@ -49,8 +49,6 @@ int surf_parse_get_int(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;
 
 /* 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 STag_surfxml_platform_cb_list = NULL;
-xbt_dynar_t ETag_surfxml_platform_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 STag_surfxml_link_cb_list = NULL;
 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
@@ -153,12 +151,8 @@ int ETag_surfxml_include_state(void)
 
 void surf_parse_init_callbacks(void)
 {
 
 void surf_parse_init_callbacks(void)
 {
-         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);
+         sg_platf_init(); // FIXME: move to a proper place?
 
 
-         sg_platf_init();
          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);
          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);
@@ -217,10 +211,8 @@ void surf_parse_reset_callbacks(void)
 
 void surf_parse_free_callbacks(void)
 {
 
 void surf_parse_free_callbacks(void)
 {
-  sg_platf_exit();
+  sg_platf_exit(); // FIXME: better place?
 
 
-  xbt_dynar_free(&STag_surfxml_platform_cb_list);
-  xbt_dynar_free(&ETag_surfxml_platform_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(&STag_surfxml_link_cb_list);
   xbt_dynar_free(&ETag_surfxml_link_cb_list);
   xbt_dynar_free(&STag_surfxml_route_cb_list);
@@ -254,11 +246,9 @@ void surf_parse_free_callbacks(void)
 }
 
 /* Stag and Etag parse functions */
 }
 
 /* Stag and Etag parse functions */
-void ETag_surfxml_host(void)  { /* ignored -- do not add content here */ }
-void ETag_surfxml_router(void){ /* ignored -- do not add content here */ }
+void ETag_surfxml_router(void)  { /* ignored -- do not add content here */ }
 
 
-void STag_surfxml_platform(void)
-{
+void STag_surfxml_platform(void) {
   _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
 
   xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
   _XBT_GNUC_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
 
   xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
@@ -281,7 +271,10 @@ void STag_surfxml_platform(void)
       "This program is installed automatically with SimGrid, or "
       "available in the tools/ directory of the source archive.");
 
       "This program is installed automatically with SimGrid, or "
       "available in the tools/ directory of the source archive.");
 
-  surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
+  sg_platf_open();
+}
+void ETag_surfxml_platform(void){
+  sg_platf_close();
 }
 
 void STag_surfxml_host(void){
 }
 
 void STag_surfxml_host(void){
@@ -306,7 +299,8 @@ void STag_surfxml_host(void){
        host.V_host_coord = A_surfxml_host_coordinates;
 
        sg_platf_new_host(&host);
        host.V_host_coord = A_surfxml_host_coordinates;
 
        sg_platf_new_host(&host);
-
+}
+void ETag_surfxml_host(void)    {
   current_property_set = NULL;
 }
 
   current_property_set = NULL;
 }
 
@@ -316,6 +310,7 @@ void STag_surfxml_router(void){
 
        router.V_router_id = A_surfxml_router_id;
        router.V_router_coord = A_surfxml_router_coordinates;
 
        router.V_router_id = A_surfxml_router_id;
        router.V_router_coord = A_surfxml_router_coordinates;
+
        sg_platf_new_router(&router);
 }
 
        sg_platf_new_router(&router);
 }
 
@@ -468,7 +463,7 @@ void ETag_surfxml_config(void){
     free(cfg);
   }
   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
     free(cfg);
   }
   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
-  current_property_set = NULL;
+  xbt_dict_free(&current_property_set);
 }
 void STag_surfxml_random(void){
        surfxml_call_cb_functions(STag_surfxml_random_cb_list);
 }
 void STag_surfxml_random(void){
        surfxml_call_cb_functions(STag_surfxml_random_cb_list);
@@ -477,7 +472,6 @@ void STag_surfxml_random(void){
 #define parse_method(type,name) \
 void type##Tag_surfxml_##name(void) \
 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
 #define parse_method(type,name) \
 void type##Tag_surfxml_##name(void) \
 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
-parse_method(E, platform);
 parse_method(E, route);
 parse_method(E, link_ctn);
 parse_method(E, process);
 parse_method(E, route);
 parse_method(E, link_ctn);
 parse_method(E, process);
@@ -580,7 +574,6 @@ static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
 
 void parse_properties(const char* prop_id, const char* prop_value)
 {
 
 void parse_properties(const char* prop_id, const char* prop_value)
 {
-    char *value = NULL;
        if (!current_property_set)
            current_property_set = xbt_dict_new();      // Maybe, it should raise an error
        if(!strcmp(prop_id,"coordinates")){
        if (!current_property_set)
            current_property_set = xbt_dict_new();      // Maybe, it should raise an error
        if(!strcmp(prop_id,"coordinates")){
@@ -594,8 +587,7 @@ void parse_properties(const char* prop_id, const char* prop_value)
                          xbt_die("Setting XML prop coordinates must be \"yes\"");
          }
        else{
                          xbt_die("Setting XML prop coordinates must be \"yes\"");
          }
        else{
-                 value = xbt_strdup(prop_value);
-                 xbt_dict_set(current_property_set, prop_id, value, free);
+                 xbt_dict_set(current_property_set, prop_id, xbt_strdup(prop_value), free);
         }
 }
 
         }
 }
 
index 4d6945f..894dc9e 100644 (file)
@@ -148,7 +148,6 @@ static void parse_E_AS(void) {
   sg_platf_new_AS_close();
 }
 
   sg_platf_new_AS_close();
 }
 
-
 /* Init and free parse data */
 
 static void init_data(void)
 /* Init and free parse data */
 
 static void init_data(void)
@@ -191,6 +190,9 @@ void parse_platform_file(const char *file)
   int parse_status;
 
   surf_parse_reset_callbacks();
   int parse_status;
 
   surf_parse_reset_callbacks();
+
+  /* Register classical callbacks */
+  surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties_XML);
   surf_parse_add_callback_config();
 
   surfxml_buffer_stack_stack_ptr = 1;
   surf_parse_add_callback_config();
 
   surfxml_buffer_stack_stack_ptr = 1;
index 087e1a7..4ed016c 100644 (file)
@@ -803,7 +803,7 @@ static void ptask_define_callbacks()
   /* Adding callback functions */
   sg_platf_host_add_cb(ptask_parse_cpu_init);
   surfxml_add_callback(ETag_surfxml_link_cb_list, &ptask_parse_link_init);
   /* Adding callback functions */
   sg_platf_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);
+  sg_platf_postparse_add_cb(ptask_add_traces);
 }
 
 /**************************************/
 }
 
 /**************************************/