Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further parser cleanups
[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 #include "surf/surf_private.h"
13
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
15 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
16 xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t
17 xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
18
19 /** Module management function: creates all internal data structures */
20 void sg_platf_init(void) {
21   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
22   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
23   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(void_f_void_t),NULL);
24 }
25 /** Module management function: frees all internal data structures */
26 void sg_platf_exit(void) {
27   xbt_dynar_free(&sg_platf_host_cb_list);
28   xbt_dynar_free(&sg_platf_router_cb_list);
29   xbt_dynar_free(&sg_platf_postparse_cb_list);
30 }
31
32 void sg_platf_new_host(sg_platf_host_cbarg_t h){
33   unsigned int iterator;
34   sg_platf_host_cb_t fun;
35   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
36     (*fun) (h);
37   }
38 }
39 void sg_platf_new_router(sg_platf_router_cbarg_t router) {
40   unsigned int iterator;
41   sg_platf_router_cb_t fun;
42   xbt_dynar_foreach(sg_platf_router_cb_list, iterator, fun) {
43     (*fun) (router);
44   }
45 }
46 void sg_platf_open() { /* Do nothing: just for symmetry of user code */ }
47
48 void sg_platf_close() {
49   unsigned int iterator;
50   void_f_void_t fun;
51   xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
52     (*fun) ();
53   }
54 }
55
56
57 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
58   xbt_dynar_push(sg_platf_host_cb_list, &fct);
59 }
60 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
61   xbt_dynar_push(sg_platf_router_cb_list, &fct);
62 }
63 void sg_platf_postparse_add_cb(void_f_void_t fct) {
64   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
65 }
66