Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve behavior of SD_application_reinit. Now, you can schedule tasks
[simgrid.git] / src / surf / surfxml_parseplatf.c
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "simgrid/platf.h"
12 #include "surf/surfxml_parse.h"
13 #include "surf/surf_private.h"
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
16
17 /*
18  *  Allow the cluster tag to mess with the parsing buffer.
19  * (this will probably become obsolete once the cluster tag do not mess with the parsing callbacks directly)
20  */
21
22 /* This buffer is used to store the original buffer before substituting it by out own buffer. Useful for the cluster tag */
23 static xbt_dynar_t surfxml_bufferstack_stack = NULL;
24 int surfxml_bufferstack_size = 2048;
25
26 static char *old_buff = NULL;
27
28 XBT_IMPORT_NO_EXPORT(unsigned int) surfxml_buffer_stack_stack_ptr;
29 XBT_IMPORT_NO_EXPORT(unsigned int) surfxml_buffer_stack_stack[1024];
30
31
32 void surfxml_bufferstack_push(int new)
33 {
34   if (!new)
35     old_buff = surfxml_bufferstack;
36   else {
37     xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
38     surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
39   }
40 }
41
42 void surfxml_bufferstack_pop(int new)
43 {
44   if (!new)
45     surfxml_bufferstack = old_buff;
46   else {
47     free(surfxml_bufferstack);
48     xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
49   }
50 }
51
52 /*
53  * Trace related stuff
54  */
55
56 xbt_dict_t traces_set_list = NULL;
57 xbt_dict_t trace_connect_list_host_avail = NULL;
58 xbt_dict_t trace_connect_list_power = NULL;
59 xbt_dict_t trace_connect_list_link_avail = NULL;
60 xbt_dict_t trace_connect_list_bandwidth = NULL;
61 xbt_dict_t trace_connect_list_latency = NULL;
62
63 /* ********************************************* */
64 /* TUTORIAL: New TAG                             */
65 /* This function should be in gpu.c              */
66 /* because sg_platf_gpu_add_cb take a staic fct  */
67 XBT_PUBLIC(void) gpu_register_callbacks(void){
68   sg_platf_gpu_add_cb(NULL);
69 }
70 /* ***************************************** */
71
72
73 /* This function acts as a main in the parsing area. */
74 void parse_platform_file(const char *file)
75 {
76   int parse_status;
77
78   surf_parse_init_callbacks();
79
80   /* Register classical callbacks */
81   storage_register_callbacks();
82   routing_register_callbacks();
83
84   /* ***************************************** */
85   /* TUTORIAL: New TAG                         */
86   gpu_register_callbacks();
87   /* ***************************************** */
88
89   /* init the flex parser */
90   surfxml_buffer_stack_stack_ptr = 1;
91   surfxml_buffer_stack_stack[0] = 0;
92
93   surf_parse_open(file);
94
95   /* Init my data */
96   if (!surfxml_bufferstack_stack)
97     surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
98
99   traces_set_list = xbt_dict_new_homogeneous(NULL);
100   trace_connect_list_host_avail = xbt_dict_new_homogeneous(free);
101   trace_connect_list_power = xbt_dict_new_homogeneous(free);
102   trace_connect_list_link_avail = xbt_dict_new_homogeneous(free);
103   trace_connect_list_bandwidth = xbt_dict_new_homogeneous(free);
104   trace_connect_list_latency = xbt_dict_new_homogeneous(free);
105
106   /* Do the actual parsing */
107   parse_status = surf_parse();
108
109   /* Free my data */
110   xbt_dict_free(&trace_connect_list_host_avail);
111   xbt_dict_free(&trace_connect_list_power);
112   xbt_dict_free(&trace_connect_list_link_avail);
113   xbt_dict_free(&trace_connect_list_bandwidth);
114   xbt_dict_free(&trace_connect_list_latency);
115   xbt_dict_free(&traces_set_list);
116   xbt_dict_free(&random_data_list);
117   xbt_dynar_free(&surfxml_bufferstack_stack);
118
119   /* Stop the flex parser */
120   surf_parse_close();
121   if (parse_status)
122     xbt_die("Parse error in %s", file);
123 }
124