Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename xbt/module.c into xbt/xbt_main.c since this file does not do any module manage...
[simgrid.git] / src / xbt / xbt_main.c
1 /* $Id$ */
2
3 /* module handling                                                          */
4
5 /* Copyright (c) 2003, 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 "time.h" /* to seed the random generator */
11
12 #include "xbt/sysdep.h"
13 #include "xbt/log.h"
14 #include "xbt/dynar.h"
15 #include "xbt/config.h"
16
17 #include "xbt/module.h" /* this module */
18
19 #include "xbt_modinter.h"  /* prototype of other module's init/exit in XBT */
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module,xbt, "module handling");
22
23 char *xbt_binary_name=NULL; /* Mandatory to retrieve neat backtraces */
24 int xbt_initialized=0;
25
26 struct xbt_module_ {
27   xbt_dynar_t *deps;
28   xbt_cfg_t *cfg;
29   int ref;
30   xbt_module_new_fct_t new;
31   xbt_module_finalize_fct_t finalize;
32 };
33
34 /** @brief Initialize the xbt mechanisms. */
35 void 
36 xbt_init(int *argc, char **argv) {
37   xbt_initialized++;
38
39   if (xbt_initialized!=1)
40     return;
41
42   xbt_binary_name = strdup(argv[0]);
43   srand((unsigned int)time(NULL));
44   VERB0("Initialize XBT");
45   
46   xbt_log_init(argc,argv);
47 }
48
49 /** @brief Finalize the xbt mechanisms. */
50 void 
51 xbt_exit(){
52   xbt_initialized--;
53   if (xbt_initialized == 0)
54      free(xbt_binary_name);
55   xbt_log_exit();
56 }
57