Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sanitize the way parsing callbacks of the routing submodule are registered
[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_ASopen_cb_list = NULL; //of sg_platf_ASopen_cb_t
19 xbt_dynar_t sg_platf_ASclose_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 /** Module management function: creates all internal data structures */
23 void sg_platf_init(void) {
24   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
25   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
26   sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
27   sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
28   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
29   sg_platf_ASopen_cb_list = xbt_dynar_new(sizeof(sg_platf_ASopen_cb_t),NULL);
30   sg_platf_ASclose_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
31 }
32 /** Module management function: frees all internal data structures */
33 void sg_platf_exit(void) {
34   xbt_dynar_free(&sg_platf_host_cb_list);
35   xbt_dynar_free(&sg_platf_router_cb_list);
36   xbt_dynar_free(&sg_platf_postparse_cb_list);
37   xbt_dynar_free(&sg_platf_peer_cb_list);
38   xbt_dynar_free(&sg_platf_ASopen_cb_list);
39   xbt_dynar_free(&sg_platf_ASclose_cb_list);
40 }
41
42 void sg_platf_new_host(sg_platf_host_cbarg_t h){
43   unsigned int iterator;
44   sg_platf_host_cb_t fun;
45   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
46     (*fun) (h);
47   }
48 }
49 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
50   unsigned int iterator;
51   sg_platf_router_cb_t fun;
52   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
53     (*fun) (router);
54   }
55 }
56 void sg_platf_new_link(sg_platf_link_cbarg_t link){
57   unsigned int iterator;
58   sg_platf_link_cb_t fun;
59   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
60     (*fun) (link);
61   }
62 }
63 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
64   unsigned int iterator;
65   sg_platf_peer_cb_t fun;
66   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
67     (*fun) (peer);
68   }
69 }
70
71 void sg_platf_open() { /* Do nothing: just for symmetry of user code */ }
72
73 void sg_platf_close() {
74   unsigned int iterator;
75   void_f_void_t fun;
76   xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
77     (*fun) ();
78   }
79 }
80
81 void sg_platf_new_AS_open(const char *id, const char *routing) {
82   unsigned int iterator;
83   sg_platf_ASopen_cb_t fun;
84   xbt_dynar_foreach(sg_platf_ASopen_cb_list, iterator, fun) {
85     (*fun) (id,routing);
86   }
87 }
88
89 void sg_platf_new_AS_close() {
90   unsigned int iterator;
91   void_f_void_t fun;
92   xbt_dynar_foreach(sg_platf_ASclose_cb_list, iterator, fun) {
93     (*fun) ();
94   }
95 }
96
97
98 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
99   xbt_dynar_push(sg_platf_host_cb_list, &fct);
100 }
101 void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
102   xbt_dynar_push(sg_platf_link_cb_list, &fct);
103 }
104 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
105   xbt_dynar_push(sg_platf_router_cb_list, &fct);
106 }
107 void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
108   xbt_dynar_push(sg_platf_peer_cb_list, &fct);
109 }
110 void sg_platf_postparse_add_cb(void_f_void_t fct) {
111   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
112 }
113 void sg_platf_ASopen_add_cb(sg_platf_ASopen_cb_t fct) {
114   xbt_dynar_push(sg_platf_ASopen_cb_list, &fct);
115 }
116 void sg_platf_ASclose_add_cb(void_f_void_t fct) {
117   xbt_dynar_push(sg_platf_ASclose_cb_list, &fct);
118 }
119