Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Current state. See changelog, sorry, I'm out of time
[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 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(module,xbt, "module handling");
25
26 static int gras_running_process = 0;
27
28 struct gras_module_ {
29   gras_dynar_t *deps;
30   gras_cfg_t *cfg;
31   int ref;
32   gras_module_new_fct_t new;
33   gras_module_finalize_fct_t finalize;
34 };
35
36 void 
37 gras_init(int *argc, char **argv) {
38    gras_init_defaultlog(argc, argv, NULL);
39 }
40
41 /**
42  * gras_init_defaultlog:
43  * @argc:
44  * @argv:
45  *
46  * Initialize the gras mecanisms.
47  */
48 void
49 gras_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
50   int i,j;
51   char *opt;
52   gras_error_t errcode;
53   int found=0;
54
55   INFO0("Initialize GRAS");
56   
57   /** Set logs and init log submodule */
58   for (i=1; i<*argc; i++) {
59     if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
60       found = 1;
61       opt=strchr(argv[i],'=');
62       opt++;
63       gras_log_control_set(opt);
64       DEBUG1("Did apply '%s' as log setting",opt);
65       /*remove this from argv*/
66       for (j=i+1; j<*argc; j++) {
67         argv[j-1] = argv[j];
68       } 
69       argv[j-1] = NULL;
70       (*argc)--;
71       i--; /* compensate effect of next loop incrementation */
72     }
73   }
74   if (!found && defaultlog) {
75      gras_log_control_set(defaultlog);
76   }
77    
78   gras_process_init(); /* calls procdata_init, which calls dynar_new */
79   /** init other submodules */
80   if (gras_running_process++ == 0) {
81     gras_msg_init();
82     gras_trp_init();
83     gras_datadesc_init();
84   }
85 }
86
87 /**
88  * gras_exit:
89  *
90  * Finalize the gras mecanisms.
91  */
92 void 
93 gras_exit(){
94   INFO0("Exiting GRAS");
95   gras_process_exit();
96   if (--gras_running_process == 0) {
97     gras_msg_exit();
98     gras_trp_exit();
99     gras_datadesc_exit();
100   }
101   gras_log_exit();
102   DEBUG0("Exited GRAS");
103 }