Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
proper xbt_log_init function
[simgrid.git] / src / xbt / module.c
1 /* $Id$ */
2
3 /* module handling                                                          */
4
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "xbt/sysdep.h"
11 #include "xbt/log.h"
12 #include "xbt/error.h"
13 #include "xbt/dynar.h"
14 #include "xbt/config.h"
15
16 #include "gras/process.h" /* FIXME: bad loop */
17
18 #include "xbt/module.h" /* this module */
19
20 #include "xbt_modinter.h"  /* prototype of other module's init/exit in XBT */
21 #include "gras_modinter.h" /* same in GRAS */
22
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module,xbt, "module handling");
24
25 static int xbt_running_process = 0;
26
27 struct xbt_module_ {
28   xbt_dynar_t *deps;
29   xbt_cfg_t *cfg;
30   int ref;
31   xbt_module_new_fct_t new;
32   xbt_module_finalize_fct_t finalize;
33 };
34
35 void 
36 xbt_init(int *argc, char **argv) {
37   static short int first_run = 1;
38   if(first_run)
39     xbt_init_defaultlog(argc, argv, NULL);
40   first_run = 0;
41 }
42
43 /**
44  * xbt_init_defaultlog:
45  * @argc:
46  * @argv:
47  *
48  * Initialize the gras mecanisms.
49  */
50 void
51 xbt_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
52   INFO0("Initialize GRAS");
53   
54   xbt_log_init(argc,argv,defaultlog);
55    
56   gras_process_init(); /* calls procdata_init, which calls dynar_new */
57   /** init other submodules */
58   if (xbt_running_process++ == 0) {
59     gras_msg_init();
60     gras_trp_init();
61     gras_datadesc_init();
62   }
63 }
64
65 /**
66  * xbt_exit:
67  *
68  * Finalize the gras mecanisms.
69  */
70 void 
71 xbt_exit(){
72   INFO0("Exiting GRAS");
73   gras_process_exit();
74   if (--xbt_running_process == 0) {
75     gras_msg_exit();
76     gras_trp_exit();
77     gras_datadesc_exit();
78   }
79   xbt_log_exit();
80   DEBUG0("Exited GRAS");
81 }