Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5391c310b0ee060a74dddeb1b1e011f91bfd376c
[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
17 struct gras_module_ {
18   gras_dynar_t *deps;
19   gras_cfg_t *cfg;
20   int ref;
21   gras_module_new_fct_t new;
22   gras_module_finalize_fct_t finalize;
23 };
24
25 void 
26 gras_init(int *argc, char **argv) {
27    gras_init_defaultlog(argc, argv, NULL);
28 }
29
30 /**
31  * gras_init_defaultlog:
32  * @argc:
33  * @argv:
34  *
35  * Initialize the gras mecanisms.
36  */
37 void
38 gras_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
39   int i,j;
40   char *opt;
41   gras_error_t errcode;
42   int found=0;
43
44   INFO0("Initialize GRAS");
45   
46   /** Set logs and init log submodule */
47   for (i=1; i<*argc; i++) {
48     if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
49       found = 1;
50       opt=strchr(argv[i],'=');
51       opt++;
52       TRYFAIL(gras_log_control_set(opt));
53       /*remove this from argv*/
54       for (j=i+1; j<*argc; j++) {
55         argv[j-1] = argv[j];
56       } 
57       argv[j-1] = NULL;
58       (*argc)--;
59       i--; /* compensate effect of next loop incrementation */
60       WARN1("argc %d",*argc);
61     }
62   }
63   if (!found && defaultlog) {
64      TRYFAIL(gras_log_control_set(defaultlog));
65   }
66    
67   /** init other submodules */
68   gras_msg_init();
69   gras_trp_init();
70   gras_datadesc_init();
71 }
72
73 /**
74  * gras_exit:
75  *
76  * Finalize the gras mecanisms.
77  */
78 void 
79 gras_exit(){
80   gras_msg_exit();
81   gras_trp_exit();
82   gras_datadesc_exit();
83   gras_log_exit();
84 }