Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move the callback lists to the public headers
[simgrid.git] / src / surf / surfxml_parse.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "xbt/misc.h"
9 #include "xbt/log.h"
10 #include "xbt/dict.h"
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf,
14                                 "Logging specific to the SURF  module");
15
16 #undef CLEANUP
17 #include "surfxml.c"
18
19 static xbt_dynar_t surf_input_buffer_stack = NULL;
20 static xbt_dynar_t surf_file_to_parse_stack = NULL;
21
22 void surfxml_call_cb_functions(xbt_dynar_t);
23
24 void nil_function(void);
25 void nil_function(void)
26 {
27   return;
28 }
29
30 YY_BUFFER_STATE surf_input_buffer;
31 FILE *surf_file_to_parse;
32
33 void surf_parse_reset_parser(void)
34 {
35
36   STag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
37   ETag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
38   STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
39   ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
40   STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
41   ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
42   STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
43   ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
44   STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
45   ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
46   STag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
47   ETag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
48   STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
49   ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
50   STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
51   ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
52   STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
53   ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
54
55 }
56
57 void STag_surfxml_include(void)
58 {
59   xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
60   xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
61
62   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
63   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
64               A_surfxml_include_file);
65   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
66   surf_parse__switch_to_buffer(surf_input_buffer);
67   printf("STAG\n");
68   fflush(NULL);
69 }
70
71 void ETag_surfxml_include(void)
72 {
73   printf("ETAG\n");
74   fflush(NULL);
75   surf_parse__delete_buffer(surf_input_buffer);
76   fclose(surf_file_to_parse);
77   xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
78   xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
79 }
80
81 void STag_surfxml_platform_description(void)
82 {
83   double version = 0.0;
84
85   sscanf(A_surfxml_platform_description_version, "%lg", &version);
86
87   xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
88               "You're using an old XML file. "
89               "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
90               "instead of MBytes, MFlops and seconds. "
91               "A script (surfxml_update.pl) to help you convert your old "
92               "platform files "
93               "is available in the contrib/platform_generation directory "
94               "of the simgrid repository. Please check also out the "
95               "SURF section of the ChangeLog for the 3.1 version. "
96               "Last, do not forget to also update your values for "
97               "the calls to MSG_task_create (if any).");
98
99   surfxml_call_cb_functions(STag_surfxml_platform_description_cb_list);
100 }
101
102 void ETag_surfxml_platform_description(void)
103 {
104   surfxml_call_cb_functions(ETag_surfxml_platform_description_cb_list);
105 }
106
107 void STag_surfxml_host(void)
108 {
109   surfxml_call_cb_functions(STag_surfxml_host_cb_list);
110 }
111
112 void ETag_surfxml_host(void)
113 {
114   surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
115 }
116
117 void STag_surfxml_router(void)
118 {
119   surfxml_call_cb_functions(STag_surfxml_router_cb_list);
120 }
121
122 void ETag_surfxml_router(void)
123 {
124   surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
125 }
126
127 void STag_surfxml_link(void)
128 {
129   surfxml_call_cb_functions(STag_surfxml_link_cb_list);
130 }
131
132 void ETag_surfxml_link(void)
133 {
134   surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
135 }
136
137 void STag_surfxml_route(void)
138 {
139   surfxml_call_cb_functions(STag_surfxml_route_cb_list);
140 }
141
142 void ETag_surfxml_route(void)
143 {
144   surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
145 }
146
147 void STag_surfxml_link_c_ctn(void)
148 {
149   surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
150 }
151
152 void ETag_surfxml_link_c_ctn(void)
153 {
154   surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
155 }
156
157 void STag_surfxml_process(void)
158 {
159   surfxml_call_cb_functions(STag_surfxml_process_cb_list);
160 }
161
162 void ETag_surfxml_process(void)
163 {
164   surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
165 }
166
167 void STag_surfxml_argument(void)
168 {
169   surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
170 }
171
172 void ETag_surfxml_argument(void)
173 {
174   surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
175 }
176
177 void STag_surfxml_prop(void)
178 {
179   surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
180 }
181 void ETag_surfxml_prop(void)
182 {
183   surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
184 }
185
186
187 void surf_parse_open(const char *file)
188 {
189   static int warned = 0;        /* warn only once */
190   if (!file) {
191     if (!warned) {
192       WARN0
193           ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
194       warned = 1;
195     }
196     return;
197   }
198   if (!surf_input_buffer_stack)
199     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
200   if (!surf_file_to_parse_stack)
201     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
202
203   surf_file_to_parse = surf_fopen(file, "r");
204   xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
205   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
206   surf_parse__switch_to_buffer(surf_input_buffer);
207   surf_parse_lineno = 1;
208 }
209
210 void surf_parse_close(void)
211 {
212   if (surf_input_buffer_stack)
213     xbt_dynar_free(&surf_input_buffer_stack);
214   if (surf_file_to_parse_stack)
215     xbt_dynar_free(&surf_file_to_parse_stack);
216
217   if (surf_file_to_parse) {
218     surf_parse__delete_buffer(surf_input_buffer);
219     fclose(surf_file_to_parse);
220   }
221 }
222
223
224 static int _surf_parse(void)
225 {
226   return surf_parse_lex();
227 }
228
229 int_f_void_t surf_parse = _surf_parse;
230
231 void surf_parse_get_double(double *value, const char *string)
232 {
233   int ret = 0;
234
235   ret = sscanf(string, "%lg", value);
236   xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
237               surf_parse_lineno, string);
238 }
239
240 void surf_parse_get_trace(tmgr_trace_t * trace, const char *string)
241 {
242   if ((!string) || (strcmp(string, "") == 0))
243     *trace = NULL;
244   else
245     *trace = tmgr_trace_new(string);
246 }
247
248 void parse_properties(void)
249 {
250   char *value = NULL;
251
252   if(!current_property_set) current_property_set = xbt_dict_new();
253
254    value = xbt_strdup(A_surfxml_prop_value);  
255    xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
256
257 }
258
259 void free_string(void *d)
260 {
261   free(*(void**)d);
262 }
263
264 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
265 {
266   xbt_dynar_push(cb_list, &function);
267 }
268
269 void surfxml_call_cb_functions(xbt_dynar_t cb_list)
270 {
271   int iterator;
272   void_f_void_t data;
273   xbt_dynar_foreach(cb_list, iterator, data){
274        (*data)();
275     }
276 }