Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make MSG_config public, document it, and implement it properly, not through a crude...
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 20 Dec 2012 15:08:57 +0000 (16:08 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 20 Dec 2012 15:17:16 +0000 (16:17 +0100)
ChangeLog
buildtools/Cmake/DefinePackages.cmake
examples/msg/parallel_task/parallel_task.tesh
include/msg/msg.h
include/xbt/config.h
src/msg/msg_config.c [deleted file]
src/msg/msg_global.c
src/xbt/config.c

index c5d13c9..5828d0c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@ SimGrid (3.9) NOT RELEASED; urgency=low
 
  MSG:
  * New function: MSG_process_get_number()
+ * Old function documented: MSG_config()
 
  SURF:
  * Change the default value of the TCP_gamma constant (maximal size of TCP
index cf19942..985e9a9 100644 (file)
@@ -241,7 +241,6 @@ set(MSG_SRC
   src/msg/instr_msg_process.c
   src/msg/instr_msg_task.c
   src/msg/msg_actions.c
-  src/msg/msg_config.c
   src/msg/msg_deployment.c
   src/msg/msg_environment.c
   src/msg/msg_global.c
index ead9710..2f85e28 100644 (file)
@@ -4,14 +4,12 @@ p Testing a simple master/slave example application
 
 ! output sort
 $ $SG_TEST_EXENV parallel_task/parallel_task$EXEEXT ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) type in variable = 2
 > [  0.000000] (0:@) surf_workstation_model_init_ptask_L07
 > [  0.009378] (0:@) Simulation time 0.00937836
 > [  0.009378] (1:test@Fafard) Goodbye now!
 
 ! output sort
 $ $SG_TEST_EXENV parallel_task/test_ptask$EXEEXT ${srcdir:=.}/parallel_task/test_ptask_platform.xml ${srcdir:=.}/parallel_task/test_ptask_deployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) type in variable = 2
 > [  0.000000] (0:@) surf_workstation_model_init_ptask_L07
 > [  1.000300] (1:execute@Ginette) execution_time=1.0003 
 > [  6.000900] (0:@) Simulation time 6.0009
index 3d92365..5d993b0 100644 (file)
@@ -32,7 +32,7 @@ typedef enum {
 /** @} */
 
 /************************** Global ******************************************/
-XBT_PUBLIC(void) MSG_config(const char *name, ...);
+XBT_PUBLIC(void) MSG_config(const char *key, const char *value);
 /** \ingroup msg_simulation
  *  \brief Initialize the MSG internal data.
  *  \hideinitializer
index 023f70a..67c25bc 100644 (file)
@@ -105,6 +105,7 @@ XBT_PUBLIC(void) xbt_cfg_set_string(xbt_cfg_t cfg, const char *name,
                                     const char *val);
 XBT_PUBLIC(void) xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name,
                                   const char *peer, int port);
+XBT_PUBLIC(void*) xbt_cfg_set_as_string(xbt_cfg_t cfg, const char *name, const char *val);
 
 /*
   Set the default value of the cell \a name in \a cfg with the provided value.
diff --git a/src/msg/msg_config.c b/src/msg/msg_config.c
deleted file mode 100644 (file)
index e45bb5f..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright (c) 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
- * 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. */
-
-#include "msg_private.h"
-#include "simgrid/sg_config.h"
-#include "xbt/sysdep.h"
-#include "xbt/log.h"
-
-/** \brief set a configuration variable
- *
- * Do --help on any simgrid binary to see the list of currently existing configuration variables
- *
- * Example:
- * MSG_config("workstation/model","KCCFLN05");
- */
-void MSG_config(const char *name, ...)
-{
-  va_list pa;
-
-  if (!msg_global) {
-    fprintf(stderr,
-            "ERROR: Please call MSG_init() before using MSG_config()\n");
-    xbt_abort();
-  }
-  va_start(pa, name);
-  xbt_cfg_set_vargs(_sg_cfg_set, name, pa);
-  va_end(pa);
-  return;
-}
index b7cfb42..f40bf21 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2012. The SimGrid Team.  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. */
@@ -13,6 +12,8 @@
 #include "xbt/virtu.h"
 #include "xbt/ex.h"             /* ex_backtrace_display */
 #include "xbt/replay.h"
+#include "simgrid/sg_config.h" /* Configuration mechanism of SimGrid */
+
 
 XBT_LOG_NEW_CATEGORY(msg, "All MSG categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_kernel, msg,
@@ -128,6 +129,20 @@ msg_error_t MSG_main(void)
   return MSG_OK;
 }
 
+/** \ingroup msg_simulation
+ * \brief set a configuration variable
+ *
+ * Do --help on any simgrid binary to see the list of currently existing configuration variables, and see Section @ref options.
+ *
+ * Example:
+ * MSG_config("workstation/model","KCCFLN05");
+ */
+void MSG_config(const char *key, const char *value){
+  xbt_assert(msg_global,"ERROR: Please call MSG_init() before using MSG_config()");
+  xbt_cfg_set_as_string(_sg_cfg_set, key, value);
+}
+
+
 /** \ingroup msg_simulation
  * \brief Kill all running process
 
index 87418cd..8199a94 100644 (file)
@@ -581,15 +581,8 @@ void xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...)
  * @todo This is a crude manual parser, it should be a proper lexer.
  */
 
-void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
-{
-  xbt_ex_t e;
-
-  int i;
-  double d;
-  char *str;
+void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options) {
 
-  volatile xbt_cfgelm_t variable = NULL;
   char *optionlist_cpy;
   char *option, *name, *val;
 
@@ -655,85 +648,93 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
       XBT_INFO("Configuration change: Set '%s' to '%s'", name, val);
 
     TRY {
-      variable = xbt_dict_get((xbt_dict_t) cfg, name);
-    }
-    CATCH(e) {
-      if (e.category == not_found_error) {
-        xbt_ex_free(e);
-        TRY {
-          THROWF(not_found_error, 0,
-                 "No registered variable corresponding to '%s'.", name);
-        }
-        TRY_CLEANUP {
-          /* name points into optionlist_cpy, it cannot be freed before */
-          free(optionlist_cpy);
-        }
-        CATCH_ANONYMOUS {
-          RETHROW;
-        }
-      }
+      xbt_cfg_set_as_string(cfg,name,val);
+    } CATCH_ANONYMOUS {
       free(optionlist_cpy);
       RETHROW;
     }
+  }
+  free(optionlist_cpy);
+}
 
-    TRY {
-      switch (variable->type) {
-      case xbt_cfgelm_string:
-        xbt_cfg_set_string(cfg, name, val);     /* throws */
-        break;
-
-      case xbt_cfgelm_int:
-        i = strtol(val, &val, 0);
-        if (val == NULL) {
-          free(optionlist_cpy);
-          xbt_die("Value of option %s not valid. Should be an integer", name);
-        }
-
-        xbt_cfg_set_int(cfg, name, i);  /* throws */
-        break;
-
-      case xbt_cfgelm_double:
-        d = strtod(val, &val);
-        if (val == NULL) {
-          free(optionlist_cpy);
-          xbt_die("Value of option %s not valid. Should be a double", name);
-        }
-
-        xbt_cfg_set_double(cfg, name, d);       /* throws */
-        break;
-
-      case xbt_cfgelm_peer:
-        str = val;
-        val = strchr(val, ':');
-        if (!val) {
-          free(optionlist_cpy);
-          xbt_die("Value of option %s not valid. Should be an peer (machine:port)",
-                  name);
-        }
-
-        *(val++) = '\0';
-        i = strtol(val, &val, 0);
-        if (val == NULL) {
-          free(optionlist_cpy);
-          xbt_die("Value of option %s not valid. Should be an peer (machine:port)",
-                  name);
-        }
-
-        xbt_cfg_set_peer(cfg, name, str, i);    /* throws */
-        break;
-
-      default:
-        THROWF(unknown_error, 0, "Type of config element %s is not valid.",
-               name);
-      }
+/** @brief Set the value of a variable, using the string representation of that value
+ *
+ * @arg cfg config set to modify
+ * @arg key name of the variable to modify
+ * @arg value string representation of the value to set
+ *
+ * @return the first char after the parsed value in val
+ */
+
+void *xbt_cfg_set_as_string(xbt_cfg_t cfg, const char *key, const char *value) {
+  xbt_ex_t e;
+
+  char *ret;
+  volatile xbt_cfgelm_t variable = NULL;
+  int i;
+  double d;
+  char *str, *val;
+
+
+  TRY {
+    variable = xbt_dict_get((xbt_dict_t) cfg, key);
+  }
+  CATCH(e) {
+    if (e.category == not_found_error) {
+      xbt_ex_free(e);
+      THROWF(not_found_error, 0,
+          "No registered variable corresponding to '%s'.", key);
     }
-    CATCH_ANONYMOUS {
-      free(optionlist_cpy);
-      RETHROW;
+    RETHROW;
+  }
+
+  switch (variable->type) {
+  case xbt_cfgelm_string:
+    xbt_cfg_set_string(cfg, key, value);     /* throws */
+    break;
+
+  case xbt_cfgelm_int:
+    i = strtol(value, &ret, 0);
+    if (value == NULL) {
+      xbt_die("Value of option %s not valid. Should be an integer", key);
+    }
+
+    xbt_cfg_set_int(cfg, key, i);  /* throws */
+    break;
+
+  case xbt_cfgelm_double:
+    d = strtod(value, &ret);
+    if (value == NULL) {
+      xbt_die("Value of option %s not valid. Should be a double", key);
     }
+
+    xbt_cfg_set_double(cfg, key, d);       /* throws */
+    break;
+
+  case xbt_cfgelm_peer:
+    val = xbt_strdup(value);
+    str = val;
+    val = strchr(val, ':');
+    if (!val) {
+      xbt_die("Value of option %s not valid. Should be an peer (machine:port)", key);
+    }
+
+    *(val++) = '\0';
+    i = strtol(val, &ret, 0);
+    if (val == NULL) {
+      xbt_die("Value of option %s not valid. Should be an peer (machine:port)", key);
+    }
+
+    xbt_cfg_set_peer(cfg, key, str, i);    /* throws */
+    free(val);
+    break;
+
+  default:
+    THROWF(unknown_error, 0, "Type of config element %s is not valid.", key);
+    break;
   }
-  free(optionlist_cpy);
 
+  return ret;
 }
 
 /** @brief Set an integer value to \a name within \a cfg if it wasn't changed yet