Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Put a header to a function
[simgrid.git] / src / gras / gras.c
1 /* $Id$ */
2
3 /* gras.c -- generic functions not fitting anywhere else                    */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson.                                 */
6 /* All rights reserved.                                                     */
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/log.h"
12 #include "xbt/module.h" /* xbt_init/exit */
13
14 #include "gras_modinter.h"   /* module init/exit */
15 #include "xbt_modinter.h"   /* module init/exit */
16
17 #include "gras/core.h"
18 #include "gras/process.h" /* FIXME: killme and put process_init in modinter */
19
20 /* FIXME: move it to some random header */
21 void hexa_print(const char*name, unsigned char *data, int size);
22
23
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories (cf. section \ref GRAS_API)");
25 static int gras_running_process = 0;
26
27 void gras_init(int *argc,char **argv, const char *defaultlog) {
28
29   INFO0("Initialize GRAS");
30   
31   /* First initialize the XBT */
32   xbt_init_defaultlog(argc,argv,defaultlog);
33    
34   /* module registrations: 
35    *    - declare process specific data we need (without creating them) 
36    */
37   if (gras_running_process == 0) {
38      gras_trp_register();
39      gras_msg_register();
40   }
41    
42   /*
43    * Initialize the process specific stuff
44    */
45   gras_process_init(); /* calls procdata_init, which creates process specific data for each module */
46   
47   /*
48    * Initialize the global stuff if it's not the first process created
49    */
50   if (gras_running_process++ == 0) {
51     gras_emul_init();
52     gras_msg_init();
53     gras_trp_init();
54     gras_datadesc_init();
55   }
56 }
57
58 void gras_exit(void) {
59   INFO0("Exiting GRAS");
60   gras_process_exit();
61   if (--gras_running_process == 0) {
62     gras_msg_exit();
63     gras_trp_exit();
64     gras_datadesc_exit();
65     gras_emul_exit();
66   }
67   xbt_exit();
68 }
69
70 void hexa_print(const char*name, unsigned char *data, int size) {
71    int i;
72    printf("%s: ", name);
73    for (i=0;i<size;i++)  {
74       if (data[i]<32)// || data[i]>'9')
75         printf("'\\%d'",data[i]);
76       else
77         printf("%c",data[i]);
78    }
79    printf("\n");
80 }
81