1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
2 * All rights reserved. */
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. */
11 #include "simgrid/platf_interface.h"
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_cluster_cb_list = NULL; // of sg_platf_cluster_cb_t
19 xbt_dynar_t sg_platf_AS_begin_cb_list = NULL; //of sg_platf_AS_begin_cb_t
20 xbt_dynar_t sg_platf_AS_end_cb_list = NULL; //of void_f_void_t
21 xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
22 xbt_dynar_t sg_platf_storage_cb_list = NULL; // of sg_platf_storage_cb_t
24 static int surf_parse_models_setup_already_called;
27 /** Module management function: creates all internal data structures */
28 void sg_platf_init(void) {
29 sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
30 sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
31 sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
32 sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
33 sg_platf_cluster_cb_list = xbt_dynar_new(sizeof(sg_platf_cluster_cb_t), NULL);
34 sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
35 sg_platf_AS_begin_cb_list = xbt_dynar_new(sizeof(sg_platf_AS_begin_cb_t),NULL);
36 sg_platf_AS_end_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
37 sg_platf_storage_cb_list = xbt_dynar_new(sizeof(sg_platf_storage_cb_t), NULL);
39 /** Module management function: frees all internal data structures */
40 void sg_platf_exit(void) {
41 xbt_dynar_free(&sg_platf_host_cb_list);
42 xbt_dynar_free(&sg_platf_router_cb_list);
43 xbt_dynar_free(&sg_platf_link_cb_list);
44 xbt_dynar_free(&sg_platf_postparse_cb_list);
45 xbt_dynar_free(&sg_platf_peer_cb_list);
46 xbt_dynar_free(&sg_platf_cluster_cb_list);
47 xbt_dynar_free(&sg_platf_AS_begin_cb_list);
48 xbt_dynar_free(&sg_platf_AS_end_cb_list);
49 xbt_dynar_free(&sg_platf_storage_cb_list);
51 /* make sure that we will reinit the models while loading the platf once reinited */
52 surf_parse_models_setup_already_called = 0;
55 void sg_platf_new_host(sg_platf_host_cbarg_t h){
56 unsigned int iterator;
57 sg_platf_host_cb_t fun;
58 xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
62 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
63 unsigned int iterator;
64 sg_platf_router_cb_t fun;
65 xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
69 void sg_platf_new_link(sg_platf_link_cbarg_t link){
70 unsigned int iterator;
71 sg_platf_link_cb_t fun;
72 xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
76 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
77 unsigned int iterator;
78 sg_platf_peer_cb_t fun;
79 xbt_dynar_foreach(sg_platf_peer_cb_list, iterator, fun) {
83 void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster){
84 unsigned int iterator;
85 sg_platf_cluster_cb_t fun;
86 xbt_dynar_foreach(sg_platf_cluster_cb_list, iterator, fun) {
90 void sg_platf_new_storage(sg_platf_storage_cbarg_t storage){
91 unsigned int iterator;
92 sg_platf_storage_cb_t fun;
93 xbt_dynar_foreach(sg_platf_storage_cb_list, iterator, fun) {
98 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
100 void sg_platf_end() {
101 unsigned int iterator;
103 xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
108 static int surf_parse_models_setup_already_called = 0;
110 void sg_platf_new_AS_begin(const char *id, const char *routing) {
111 unsigned int iterator;
112 sg_platf_AS_begin_cb_t fun;
114 if (!surf_parse_models_setup_already_called && !xbt_dynar_is_empty(sg_platf_AS_begin_cb_list)) {
115 /* Initialize the surf models. That must be done after we got all config, and before we need the models.
116 * That is, after the last <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
118 * I'm not sure for <trace> and <trace_connect>, there may be a bug here
119 * (FIXME: check it out by creating a file beginning with one of these tags)
120 * but cluster and peer create ASes internally, so putting the code in there is ok.
122 * We are also guarding against xbt_dynar_length(sg_platf_AS_begin_cb_list) because we don't
123 * want to initialize the models if we are parsing the file to get the deployment. That could happen if
124 * the same file would be used for platf and deploy: it'd contain AS tags even during the deploy parsing.
125 * Removing that guard would result of the models to get re-inited when parsing for deploy.
127 surf_parse_models_setup_already_called = 1;
128 surf_config_models_setup();
131 xbt_dynar_foreach(sg_platf_AS_begin_cb_list, iterator, fun) {
136 void sg_platf_new_AS_end() {
137 unsigned int iterator;
139 xbt_dynar_foreach(sg_platf_AS_end_cb_list, iterator, fun) {
145 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
146 xbt_dynar_push(sg_platf_host_cb_list, &fct);
148 void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
149 xbt_dynar_push(sg_platf_link_cb_list, &fct);
151 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
152 xbt_dynar_push(sg_platf_router_cb_list, &fct);
154 void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
155 xbt_dynar_push(sg_platf_peer_cb_list, &fct);
157 void sg_platf_cluster_add_cb(sg_platf_cluster_cb_t fct) {
158 xbt_dynar_push(sg_platf_cluster_cb_list, &fct);
160 void sg_platf_postparse_add_cb(void_f_void_t fct) {
161 xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
163 void sg_platf_AS_begin_add_cb(sg_platf_AS_begin_cb_t fct) {
164 xbt_dynar_push(sg_platf_AS_begin_cb_list, &fct);
166 void sg_platf_AS_end_add_cb(void_f_void_t fct) {
167 xbt_dynar_push(sg_platf_AS_end_cb_list, &fct);
169 void sg_platf_storage_add_cb(sg_platf_storage_cb_t fct) {
170 xbt_dynar_push(sg_platf_storage_cb_list, &fct);