Logo AND Algorithmique Numérique Distribuée

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