Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
* Cleanup the DTD by renaming:
[simgrid.git] / src / surf / surfxml_parse.c
index 6dfa95e..7956cd9 100644 (file)
@@ -7,15 +7,19 @@
 
 #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;
+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,157 +27,194 @@ void nil_function(void)
   return;
 }
 
-void_f_void_t STag_platform_description_fun = nil_function;
-void_f_void_t ETag_platform_description_fun = nil_function;
-void_f_void_t STag_cpu_fun = nil_function;
-void_f_void_t ETag_cpu_fun = nil_function;
-void_f_void_t STag_network_link_fun = nil_function;
-void_f_void_t ETag_network_link_fun = nil_function;
-void_f_void_t STag_route_fun = nil_function;
-void_f_void_t ETag_route_fun = nil_function;
-void_f_void_t STag_route_element_fun = nil_function;
-void_f_void_t ETag_route_element_fun = nil_function;
-void_f_void_t STag_process_fun = nil_function;
-void_f_void_t ETag_process_fun = nil_function;
-void_f_void_t STag_argument_fun = nil_function;
-void_f_void_t ETag_argument_fun = nil_function;
-
 YY_BUFFER_STATE surf_input_buffer;
 FILE *surf_file_to_parse;
 
 void surf_parse_reset_parser(void)
 {
-  STag_platform_description_fun = nil_function;
-  ETag_platform_description_fun = nil_function;
-  STag_cpu_fun = nil_function;
-  ETag_cpu_fun = nil_function;
-  STag_network_link_fun = nil_function;
-  ETag_network_link_fun = nil_function;
-  STag_route_fun = nil_function;
-  ETag_route_fun = nil_function;
-  STag_route_element_fun = nil_function;
-  ETag_route_element_fun = nil_function;
-  STag_process_fun = nil_function;
-  ETag_process_fun = nil_function;
-  STag_argument_fun = nil_function;
-  ETag_argument_fun = nil_function;
-}
-
-void STag_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_include_file,"r");
-  xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",A_include_file);
-  surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
+
+  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_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_parse__switch_to_buffer(surf_input_buffer);
-  printf("STAG\n"); fflush(NULL);
+  printf("STAG\n");
+  fflush(NULL);
 }
 
-void ETag_include(void)
+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_platform_description(void)
+void STag_surfxml_platform_description(void)
 {
-  STag_platform_description_fun();
+  double version = 0.0;
+
+  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.1, units are Bytes, Flops, and seconds "
+             "instead of MBytes, MFlops and seconds. "
+             "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.1 version. "
+             "Last, do not forget to also update your values for "
+             "the calls to MSG_task_create (if any).");
+
+  surfxml_call_cb_functions(STag_surfxml_platform_description_cb_list);
 }
 
-void ETag_platform_description(void)
+void ETag_surfxml_platform_description(void)
 {
-  ETag_platform_description_fun();
+  surfxml_call_cb_functions(ETag_surfxml_platform_description_cb_list);
 }
 
-void STag_cpu(void)
+void STag_surfxml_host(void)
 {
-  STag_cpu_fun();
+  surfxml_call_cb_functions(STag_surfxml_host_cb_list);
 }
 
-void ETag_cpu(void)
+void ETag_surfxml_host(void)
 {
-  ETag_cpu_fun();
+  surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
 }
 
-void STag_network_link(void)
+void STag_surfxml_router(void)
 {
-  STag_network_link_fun();
+  surfxml_call_cb_functions(STag_surfxml_router_cb_list);
 }
 
-void ETag_network_link(void)
+void ETag_surfxml_router(void)
 {
-  ETag_network_link_fun();
+  surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
 }
 
-void STag_route(void)
+void STag_surfxml_link(void)
 {
-  STag_route_fun();
+  surfxml_call_cb_functions(STag_surfxml_link_cb_list);
 }
 
-void ETag_route(void)
+void ETag_surfxml_link(void)
 {
-  ETag_route_fun();
+  surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
 }
 
-void STag_route_element(void)
+void STag_surfxml_route(void)
 {
-  STag_route_element_fun();
+  surfxml_call_cb_functions(STag_surfxml_route_cb_list);
 }
 
-void ETag_route_element(void)
+void ETag_surfxml_route(void)
 {
-  ETag_route_element_fun();
+  surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
 }
 
-void STag_process(void)
+void STag_surfxml_link_c_ctn(void)
 {
-  STag_process_fun();
+  surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
 }
 
-void ETag_process(void)
+void ETag_surfxml_link_c_ctn(void)
 {
-  ETag_process_fun();
+  surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
 }
 
-void STag_argument(void)
+void STag_surfxml_process(void)
 {
-  STag_argument_fun();
+  surfxml_call_cb_functions(STag_surfxml_process_cb_list);
 }
 
-void ETag_argument(void)
+void ETag_surfxml_process(void)
+{
+  surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
+}
+
+void STag_surfxml_argument(void)
+{
+  surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
+}
+
+void ETag_surfxml_argument(void)
+{
+  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)
 {
-  ETag_argument_fun();
+  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);
   }
@@ -187,16 +228,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;
@@ -204,3 +245,32 @@ 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 data;
+  xbt_dynar_foreach(cb_list, iterator, data){
+       (*data)();
+    }
+}