+/*
+ * Stuff relative to storage
+ */
+void STag_surfxml_storage(void)
+{
+ XBT_DEBUG("STag_surfxml_storage");
+}
+void ETag_surfxml_storage(void)
+{
+ s_sg_platf_storage_cbarg_t storage;
+ memset(&storage,0,sizeof(storage));
+
+ storage.id = A_surfxml_storage_id;
+ storage.type_id = A_surfxml_storage_typeId;
+ sg_platf_new_storage(&storage);
+}
+void STag_surfxml_storage_type(void)
+{
+ XBT_DEBUG("STag_surfxml_storage_type");
+ xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
+}
+void ETag_surfxml_storage_type(void)
+{
+ s_sg_platf_storage_type_cbarg_t storage_type;
+ memset(&storage_type,0,sizeof(storage_type));
+
+ storage_type.content = A_surfxml_storage_type_content;
+ storage_type.id = A_surfxml_storage_type_id;
+ storage_type.model = A_surfxml_storage_type_model;
+ storage_type.properties = current_property_set;
+ storage_type.size = surf_parse_get_int(A_surfxml_storage_type_size);
+ sg_platf_new_storage_type(&storage_type);
+ current_property_set = NULL;
+}
+void STag_surfxml_mstorage(void)
+{
+ XBT_DEBUG("STag_surfxml_mstorage");
+}
+void ETag_surfxml_mstorage(void)
+{
+ s_sg_platf_mstorage_cbarg_t mstorage;
+ memset(&mstorage,0,sizeof(mstorage));
+
+ mstorage.name = A_surfxml_mstorage_name;
+ mstorage.type_id = A_surfxml_mstorage_typeId;
+ sg_platf_new_mstorage(&mstorage);
+}
+void STag_surfxml_mount(void)
+{
+ XBT_DEBUG("STag_surfxml_mount");
+}
+void ETag_surfxml_mount(void)
+{
+ s_sg_platf_mount_cbarg_t mount;
+ memset(&mount,0,sizeof(mount));
+
+ mount.name = A_surfxml_mount_name;
+ mount.id = A_surfxml_mount_id;
+ sg_platf_new_mount(&mount);
+}
+
+/*
+ * Stuff relative to the <include> tag
+ */
+static xbt_dynar_t surf_input_buffer_stack = NULL;
+static xbt_dynar_t surf_file_to_parse_stack = NULL;
+static xbt_dynar_t surf_parsed_filename_stack = NULL;
+
+void STag_surfxml_include(void)
+{
+ XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
+ xbt_dynar_push(surf_parsed_filename_stack,&surf_parsed_filename); // save old file name
+ surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
+
+ xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor
+
+ surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
+ xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
+ A_surfxml_include_file);
+ xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
+ surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
+ surf_parse_push_buffer_state(surf_input_buffer);
+
+ fflush(NULL);
+}
+
+void ETag_surfxml_include(void) {
+/* Nothing to do when done with reading the include tag.
+ * Instead, the handling should be deferred until the EOF of current buffer -- see below */
+}
+
+/** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
+ *
+ * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
+ * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
+ * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
+ * error message in that case.
+ *
+ * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
+ * directly: a command line flag could instruct it to do the correct thing when #include is encountered
+ * on a line. One day maybe, if the maya allow it.
+ */
+int ETag_surfxml_include_state(void)
+{
+ fflush(NULL);
+ XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
+
+ if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
+ return 0;
+
+ // Yeah, we were in an <include> Restore state and proceed.
+ fclose(surf_file_to_parse);
+ xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
+ surf_parse_pop_buffer_state();
+ xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
+
+ // Restore the filename for error messages
+ free(surf_parsed_filename);
+ xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);
+
+ return 1;
+}
+
+
+void surf_parse_init_callbacks(void)
+{
+ sg_platf_init(); // FIXME: move to a proper place?
+
+ 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_ctn_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_link_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);
+ STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_trace_connect_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_trace_connect_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_ASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_ASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_bypassRoute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_bypassRoute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_bypassASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_bypassASroute_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_peer_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_peer_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_include_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_include_cb_list =
+ xbt_dynar_new(sizeof(void_f_void_t), NULL);
+
+ STag_surfxml_storage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_storage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_storage_type_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_storage_type_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_mount_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_mount_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ STag_surfxml_mstorage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+ ETag_surfxml_mstorage_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
+}
+
+void surf_parse_reset_callbacks(void)
+{
+ surf_parse_free_callbacks();
+ surf_parse_init_callbacks();
+}
+