Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
proper xbt_log_init function
[simgrid.git] / src / xbt / module.c
index 290488e..9dfed32 100644 (file)
@@ -2,73 +2,80 @@
 
 /* module handling                                                          */
 
-/* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003 the OURAGAN project.                                  */
+/* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
 
 /* This program is free software; you can redistribute it and/or modify it
  under the terms of the license (GNU LGPL) which comes with this package. */
* under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "gras_private.h"
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+#include "xbt/error.h"
+#include "xbt/dynar.h"
+#include "xbt/config.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(module,GRAS);
+#include "gras/process.h" /* FIXME: bad loop */
 
-extern void gras_log_exit(void);
+#include "xbt/module.h" /* this module */
 
-struct gras_module_ {
-  gras_dynar_t *deps;
-  gras_cfg_t *cfg;
+#include "xbt_modinter.h"  /* prototype of other module's init/exit in XBT */
+#include "gras_modinter.h" /* same in GRAS */
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module,xbt, "module handling");
+
+static int xbt_running_process = 0;
+
+struct xbt_module_ {
+  xbt_dynar_t *deps;
+  xbt_cfg_t *cfg;
   int ref;
-  gras_module_new_fct_t new;
-  gras_module_finalize_fct_t finalize;
+  xbt_module_new_fct_t new;
+  xbt_module_finalize_fct_t finalize;
 };
 
 void 
-gras_init(int argc, char **argv) {
-   gras_init_defaultlog(argc, argv, NULL);
+xbt_init(int *argc, char **argv) {
+  static short int first_run = 1;
+  if(first_run)
+    xbt_init_defaultlog(argc, argv, NULL);
+  first_run = 0;
 }
 
 /**
- * gras_init_defaultlog:
+ * xbt_init_defaultlog:
  * @argc:
  * @argv:
  *
  * Initialize the gras mecanisms.
  */
 void
-gras_init_defaultlog(int argc,char **argv, const char *defaultlog) {
-  int i;
-  char *opt;
-  gras_error_t errcode;
-  int found=0;
-
+xbt_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
   INFO0("Initialize GRAS");
   
-  /** Set logs and init log submodule */
-  for (i=1; i<argc; i++) {
-    if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
-      found = 1;
-      opt=strchr(argv[i],'=');
-      opt++;
-      TRYFAIL(gras_log_control_set(opt));
-    }
-  }
-  if (!found && defaultlog) {
-     TRYFAIL(gras_log_control_set(defaultlog));
-  }
+  xbt_log_init(argc,argv,defaultlog);
    
+  gras_process_init(); /* calls procdata_init, which calls dynar_new */
   /** init other submodules */
-  gras_trp_init();
-  gras_datadesc_init();
+  if (xbt_running_process++ == 0) {
+    gras_msg_init();
+    gras_trp_init();
+    gras_datadesc_init();
+  }
 }
 
 /**
- * gras_exit:
+ * xbt_exit:
  *
  * Finalize the gras mecanisms.
  */
 void 
-gras_exit(){
-  gras_trp_exit();
-  gras_datadesc_exit();
-  gras_log_exit();
+xbt_exit(){
+  INFO0("Exiting GRAS");
+  gras_process_exit();
+  if (--xbt_running_process == 0) {
+    gras_msg_exit();
+    gras_trp_exit();
+    gras_datadesc_exit();
+  }
+  xbt_log_exit();
+  DEBUG0("Exited GRAS");
 }