Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Removed a bunch of unused variables. Mostly some xbt_error_t errcode that
[simgrid.git] / src / xbt / module.c
1 /* $Id$ */
2
3 /* module handling                                                          */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "xbt/sysdep.h"
12 #include "xbt/log.h"
13 #include "xbt/error.h"
14 #include "xbt/dynar.h"
15 #include "xbt/config.h"
16
17 #include "gras/process.h" /* FIXME: bad loop */
18
19 #include "xbt/module.h" /* this module */
20
21 #include "xbt_modinter.h"  /* prototype of other module's init/exit in XBT */
22 #include "gras_modinter.h" /* same in GRAS */
23
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module,xbt, "module handling");
25
26 static int xbt_running_process = 0;
27
28 struct xbt_module_ {
29   xbt_dynar_t *deps;
30   xbt_cfg_t *cfg;
31   int ref;
32   xbt_module_new_fct_t new;
33   xbt_module_finalize_fct_t finalize;
34 };
35
36 void 
37 xbt_init(int *argc, char **argv) {
38    xbt_init_defaultlog(argc, argv, NULL);
39 }
40
41 /**
42  * xbt_init_defaultlog:
43  * @argc:
44  * @argv:
45  *
46  * Initialize the gras mecanisms.
47  */
48 void
49 xbt_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
50   int i,j;
51   char *opt;
52   int found=0;
53
54   INFO0("Initialize GRAS");
55   
56   /** Set logs and init log submodule */
57   for (i=1; i<*argc; i++) {
58     if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
59       found = 1;
60       opt=strchr(argv[i],'=');
61       opt++;
62       xbt_log_control_set(opt);
63       DEBUG1("Did apply '%s' as log setting",opt);
64       /*remove this from argv*/
65       for (j=i+1; j<*argc; j++) {
66         argv[j-1] = argv[j];
67       } 
68       argv[j-1] = NULL;
69       (*argc)--;
70       i--; /* compensate effect of next loop incrementation */
71     }
72   }
73   if (!found && defaultlog) {
74      xbt_log_control_set(defaultlog);
75   }
76    
77   gras_process_init(); /* calls procdata_init, which calls dynar_new */
78   /** init other submodules */
79   if (xbt_running_process++ == 0) {
80     gras_msg_init();
81     gras_trp_init();
82     gras_datadesc_init();
83   }
84 }
85
86 /**
87  * xbt_exit:
88  *
89  * Finalize the gras mecanisms.
90  */
91 void 
92 xbt_exit(){
93   INFO0("Exiting GRAS");
94   gras_process_exit();
95   if (--xbt_running_process == 0) {
96     gras_msg_exit();
97     gras_trp_exit();
98     gras_datadesc_exit();
99   }
100   xbt_log_exit();
101   DEBUG0("Exited GRAS");
102 }