Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
integrate the peer creation in sg_platf properly
[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_postparse_cb_list = NULL; // of void_f_void_t
19
20 /** Module management function: creates all internal data structures */
21 void sg_platf_init(void) {
22   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
23   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
24   sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
25   sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
26   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
27 }
28 /** Module management function: frees all internal data structures */
29 void sg_platf_exit(void) {
30   xbt_dynar_free(&sg_platf_host_cb_list);
31   xbt_dynar_free(&sg_platf_router_cb_list);
32   xbt_dynar_free(&sg_platf_postparse_cb_list);
33   xbt_dynar_free(&sg_platf_peer_cb_list);
34 }
35
36 void sg_platf_new_host(sg_platf_host_cbarg_t h){
37   unsigned int iterator;
38   sg_platf_host_cb_t fun;
39   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
40     (*fun) (h);
41   }
42 }
43 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
44   unsigned int iterator;
45   sg_platf_router_cb_t fun;
46   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
47     (*fun) (router);
48   }
49 }
50 void sg_platf_new_link(sg_platf_link_cbarg_t link){
51   unsigned int iterator;
52   sg_platf_link_cb_t fun;
53   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
54     (*fun) (link);
55   }
56 }
57 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
58   unsigned int iterator;
59   sg_platf_peer_cb_t fun;
60   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
61     (*fun) (peer);
62   }
63 }
64
65 void sg_platf_open() { /* Do nothing: just for symmetry of user code */ }
66
67 void sg_platf_close() {
68   unsigned int iterator;
69   void_f_void_t fun;
70   xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
71     (*fun) ();
72   }
73 }
74
75
76 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
77   xbt_dynar_push(sg_platf_host_cb_list, &fct);
78 }
79 void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
80   xbt_dynar_push(sg_platf_link_cb_list, &fct);
81 }
82 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
83   xbt_dynar_push(sg_platf_router_cb_list, &fct);
84 }
85 void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
86   xbt_dynar_push(sg_platf_peer_cb_list, &fct);
87 }
88 void sg_platf_postparse_add_cb(void_f_void_t fct) {
89   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
90 }
91