3 /* gras.c -- generic functions not fitting anywhere else */
5 /* Copyright (c) 2003, 2004 Martin Quinson. */
6 /* All rights reserved. */
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. */
12 #include "xbt/module.h" /* xbt_init/exit */
14 #include "gras_modinter.h" /* module init/exit */
15 #include "xbt_modinter.h" /* module init/exit */
18 #include "gras/process.h" /* FIXME: killme and put process_init in modinter */
20 #include "portable.h" /* hexa_*() */
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories (cf. section \ref GRAS_API)");
23 static int gras_running_process = 0;
25 void gras_init(int *argc,char **argv) {
27 VERB0("Initialize GRAS");
29 /* First initialize the XBT */
32 /* module registrations:
33 * - declare process specific data we need (without creating them)
35 if (gras_running_process == 0) {
41 * Initialize the process specific stuff
43 gras_process_init(); /* calls procdata_init, which creates process specific data for each module */
46 * Initialize the global stuff if it's not the first process created
48 if (gras_running_process++ == 0) {
56 void gras_exit(void) {
57 INFO0("Exiting GRAS");
58 if (--gras_running_process == 0) {
68 const char *hexa_str(unsigned char *data, int size) {
69 static char*buff=NULL;
70 static int buffsize=0;
73 if (buffsize<5*(size+1)) {
77 buff=xbt_malloc(buffsize);
79 for (i=0;i<size;i++) {
80 if (data[i]<32 || data[i]>126)
81 sprintf(buff+pos,".(%02x)",data[i]);
83 sprintf(buff+pos,"%c(%02x)",data[i],data[i]);
89 void hexa_print(const char*name, unsigned char *data, int size) {
90 printf("%s: %s\n", name,hexa_str(data,size));