Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics: variable&fields renaming
[simgrid.git] / src / surf / sg_platf.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_interface.h"
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
14 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
15 xbt_dynar_t sg_platf_link_cb_list = NULL;   // of sg_platf_link_cb_t
16 xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t
17 xbt_dynar_t sg_platf_peer_cb_list = NULL; // of sg_platf_peer_cb_t
18 xbt_dynar_t sg_platf_AS_begin_cb_list = NULL; //of sg_platf_AS_begin_cb_t
19 xbt_dynar_t sg_platf_AS_end_cb_list = NULL; //of void_f_void_t
20 xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
21
22 static int surf_parse_models_setup_already_called;
23
24
25 /** Module management function: creates all internal data structures */
26 void sg_platf_init(void) {
27   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
28   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
29   sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
30   sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
31   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
32   sg_platf_AS_begin_cb_list = xbt_dynar_new(sizeof(sg_platf_AS_begin_cb_t),NULL);
33   sg_platf_AS_end_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
34 }
35 /** Module management function: frees all internal data structures */
36 void sg_platf_exit(void) {
37   xbt_dynar_free(&sg_platf_host_cb_list);
38   xbt_dynar_free(&sg_platf_router_cb_list);
39   xbt_dynar_free(&sg_platf_link_cb_list);
40   xbt_dynar_free(&sg_platf_postparse_cb_list);
41   xbt_dynar_free(&sg_platf_peer_cb_list);
42   xbt_dynar_free(&sg_platf_AS_begin_cb_list);
43   xbt_dynar_free(&sg_platf_AS_end_cb_list);
44
45   /* make sure that we will reinit the models while loading the platf once reinited */
46   surf_parse_models_setup_already_called = 0;
47 }
48
49 void sg_platf_new_host(sg_platf_host_cbarg_t h){
50   unsigned int iterator;
51   sg_platf_host_cb_t fun;
52   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
53     (*fun) (h);
54   }
55 }
56 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
57   unsigned int iterator;
58   sg_platf_router_cb_t fun;
59   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
60     (*fun) (router);
61   }
62 }
63 void sg_platf_new_link(sg_platf_link_cbarg_t link){
64   unsigned int iterator;
65   sg_platf_link_cb_t fun;
66   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
67     (*fun) (link);
68   }
69 }
70 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
71   unsigned int iterator;
72   sg_platf_peer_cb_t fun;
73   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
74     (*fun) (peer);
75   }
76 }
77
78 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
79
80 void sg_platf_end() {
81   unsigned int iterator;
82   void_f_void_t fun;
83   xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
84     (*fun) ();
85   }
86 }
87
88 static int surf_parse_models_setup_already_called = 0;
89
90 void sg_platf_new_AS_begin(const char *id, const char *routing) {
91   unsigned int iterator;
92   sg_platf_AS_begin_cb_t fun;
93
94   if (!surf_parse_models_setup_already_called && xbt_dynar_length(sg_platf_AS_begin_cb_list)) {
95     /* Initialize the surf models. That must be done after we got all config, and before we need the models.
96      * That is, after the last <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
97      *
98      * I'm not sure for <trace> and <trace_connect>, there may be a bug here
99      * (FIXME: check it out by creating a file beginning with one of these tags)
100      * but cluster and peer create ASes internally, so putting the code in there is ok.
101      *
102      * We are also guarding against xbt_dynar_length(sg_platf_AS_begin_cb_list) because we don't
103      * want to initialize the models if we are parsing the file to get the deployment. That could happen if
104      * the same file would be used for platf and deploy: it'd contain AS tags even during the deploy parsing.
105      * Removing that guard would result of the models to get re-inited when parsing for deploy.
106      */
107     surf_parse_models_setup_already_called = 1;
108     surf_config_models_setup();
109   }
110
111   xbt_dynar_foreach(sg_platf_AS_begin_cb_list, iterator, fun) {
112     (*fun) (id,routing);
113   }
114 }
115
116 void sg_platf_new_AS_end() {
117   unsigned int iterator;
118   void_f_void_t fun;
119   xbt_dynar_foreach(sg_platf_AS_end_cb_list, iterator, fun) {
120     (*fun) ();
121   }
122 }
123
124
125 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
126   xbt_dynar_push(sg_platf_host_cb_list, &fct);
127 }
128 void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
129   xbt_dynar_push(sg_platf_link_cb_list, &fct);
130 }
131 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
132   xbt_dynar_push(sg_platf_router_cb_list, &fct);
133 }
134 void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
135   xbt_dynar_push(sg_platf_peer_cb_list, &fct);
136 }
137 void sg_platf_postparse_add_cb(void_f_void_t fct) {
138   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
139 }
140 void sg_platf_AS_begin_add_cb(sg_platf_AS_begin_cb_t fct) {
141   xbt_dynar_push(sg_platf_AS_begin_cb_list, &fct);
142 }
143 void sg_platf_AS_end_add_cb(void_f_void_t fct) {
144   xbt_dynar_push(sg_platf_AS_end_cb_list, &fct);
145 }
146