Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do connect all log channel manually to parent using XBT_LOG_CONNECT() too, so that...
[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 /** @brief Initialize the xbt mechanisms. */
27 void 
28 xbt_init(int *argc, char **argv) {
29   xbt_initialized++;
30
31   if (xbt_initialized!=1)
32     return;
33
34   /* Connect our log channels: that must be done manually under windows */
35   XBT_LOG_CONNECT(graphxml_parse, xbt);
36   XBT_LOG_CONNECT(log, xbt);
37   XBT_LOG_CONNECT(module, xbt);
38   XBT_LOG_CONNECT(peer, xbt);
39   XBT_LOG_CONNECT(strbuff, xbt);
40   XBT_LOG_CONNECT(xbt_cfg, xbt);
41   XBT_LOG_CONNECT(xbt_dict_add, xbt_dict);
42   XBT_LOG_CONNECT(xbt_dict_collapse, xbt_dict);
43   XBT_LOG_CONNECT(xbt_dict_cursor, xbt_dict);
44   XBT_LOG_CONNECT(xbt_dict_elm, xbt_dict);
45   XBT_LOG_CONNECT(xbt_dict_multi, xbt_dict);
46   XBT_LOG_CONNECT(xbt_dict_remove, xbt_dict);
47   XBT_LOG_CONNECT(xbt_dict_search, xbt_dict);
48   XBT_LOG_CONNECT(xbt_dict, xbt);
49   XBT_LOG_CONNECT(xbt_dyn, xbt);
50   XBT_LOG_CONNECT(xbt_ex, xbt);
51   XBT_LOG_CONNECT(xbt_fifo, xbt);
52   XBT_LOG_CONNECT(xbt_graph, xbt);
53   XBT_LOG_CONNECT(xbt_matrix, xbt);
54   XBT_LOG_CONNECT(xbt_queue, xbt);
55   XBT_LOG_CONNECT(xbt_set, xbt);
56   XBT_LOG_CONNECT(xbt_sync_os, xbt);
57   XBT_LOG_CONNECT(xbt_sync_rl, xbt);
58    
59   xbt_binary_name = xbt_strdup(argv[0]);
60   srand((unsigned int)time(NULL));
61   VERB0("Initialize XBT");
62   
63   xbt_backtrace_init();
64   xbt_log_init(argc,argv);
65   xbt_os_thread_mod_init();
66   xbt_context_mod_init();
67 }
68
69 /** @brief Finalize the xbt mechanisms. */
70 void 
71 xbt_exit(){
72   xbt_initialized--;
73   if (xbt_initialized == 0) {
74     xbt_fifo_exit();
75     xbt_dict_exit();
76     xbt_context_mod_exit();
77     xbt_os_thread_mod_exit();
78     xbt_log_exit();
79     xbt_backtrace_exit();
80   }
81    
82   if (xbt_initialized == 0)
83     free(xbt_binary_name);
84 }
85