Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Test if the configuration into tag_config is already set by command line.
authornavarrop <navarrop@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 19 Jan 2011 16:37:13 +0000 (16:37 +0000)
committernavarrop <navarrop@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 19 Jan 2011 16:37:13 +0000 (16:37 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9441 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/config.h
src/surf/surf_config.c
src/surf/surf_routing.c
src/xbt/config.c
teshsuite/simdag/platforms/basic_parsing_test.tesh

index 6000dbb..c652fcc 100644 (file)
@@ -163,9 +163,32 @@ typedef enum {
   xbt_cfgelm_type_count
 } e_xbt_cfgelm_type_t;
 
   xbt_cfgelm_type_count
 } e_xbt_cfgelm_type_t;
 
-  /** \brief Callback types. They get the name of the modified entry, and the position of the changed value */
+/** \brief Callback types. They get the name of the modified entry, and the position of the changed value */
 typedef void (*xbt_cfg_cb_t) (const char *, int);
 
 typedef void (*xbt_cfg_cb_t) (const char *, int);
 
+/* xbt_cfgelm_t: the typedef corresponding to a config variable.
+
+   Both data and DTD are mixed, but fixing it now would prevent me to ever
+   defend my thesis. */
+
+typedef struct {
+  /* Description */
+  char *desc;
+
+  /* Allowed type of the variable */
+  e_xbt_cfgelm_type_t type;
+  int min, max;
+  int isdefault:1;
+
+  /* Callbacks */
+  xbt_cfg_cb_t cb_set;
+  xbt_cfg_cb_t cb_rm;
+
+  /* actual content
+     (cannot be an union because type peer uses both str and i) */
+  xbt_dynar_t content;
+} s_xbt_cfgelm_t, *xbt_cfgelm_t;
+
 XBT_PUBLIC(xbt_cfg_t) xbt_cfg_new(void);
 XBT_PUBLIC(void) xbt_cfg_cpy(xbt_cfg_t tocopy,  /* OUT */
                              xbt_cfg_t * whereto);
 XBT_PUBLIC(xbt_cfg_t) xbt_cfg_new(void);
 XBT_PUBLIC(void) xbt_cfg_cpy(xbt_cfg_t tocopy,  /* OUT */
                              xbt_cfg_t * whereto);
@@ -173,6 +196,9 @@ XBT_PUBLIC(void) xbt_cfg_free(xbt_cfg_t * cfg);
 XBT_PUBLIC(void) xbt_cfg_dump(const char *name, const char *indent,
                               xbt_cfg_t cfg);
 
 XBT_PUBLIC(void) xbt_cfg_dump(const char *name, const char *indent,
                               xbt_cfg_t cfg);
 
+/* Retrieve the variable we'll modify */
+XBT_PUBLIC(xbt_cfgelm_t) xbt_cfgelm_get(xbt_cfg_t cfg, const char *name,
+                                   e_xbt_cfgelm_type_t type);
  /** @} */
 
 /** @defgroup XBT_cfg_register  Registering stuff
  /** @} */
 
 /** @defgroup XBT_cfg_register  Registering stuff
index e54c58d..5cdd4c0 100644 (file)
@@ -285,12 +285,12 @@ void surf_config_init(int *argc, char **argv)
                      "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)",
                      xbt_cfgelm_double, NULL, 1, 1,
                      _surf_cfg_cb__tcp_gamma, NULL);
                      "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)",
                      xbt_cfgelm_double, NULL, 1, 1,
                      _surf_cfg_cb__tcp_gamma, NULL);
-    xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
+    xbt_cfg_setdefault_double(_surf_cfg_set, "TCP_gamma", 20000.0);
 
     xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
                      "Minimum retained action value when updating simulation",
                      xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
 
     xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
                      "Minimum retained action value when updating simulation",
                      xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
-    xbt_cfg_set_double(_surf_cfg_set, "maxmin/precision", 0.00001);
+    xbt_cfg_setdefault_double(_surf_cfg_set, "maxmin/precision", 0.00001); // FIXME use setdefault everywhere here!
 
     /* The parameters of network models */
 
 
     /* The parameters of network models */
 
@@ -358,14 +358,14 @@ void surf_config_init(int *argc, char **argv)
                      "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM03)",
                      xbt_cfgelm_int, &default_value_int, 0, 1,
                      _surf_cfg_cb__surf_network_fullduplex, NULL);
                      "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM03)",
                      xbt_cfgelm_int, &default_value_int, 0, 1,
                      _surf_cfg_cb__surf_network_fullduplex, NULL);
-    xbt_cfg_set_int(_surf_cfg_set, "fullduplex", default_value_int);
+    xbt_cfg_setdefault_int(_surf_cfg_set, "fullduplex", default_value_int);
 
 #ifdef HAVE_GTNETS
     xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
                      "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
                      xbt_cfgelm_double, NULL, 1, 1,
                      _surf_cfg_cb__gtnets_jitter, NULL);
 
 #ifdef HAVE_GTNETS
     xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
                      "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
                      xbt_cfgelm_double, NULL, 1, 1,
                      _surf_cfg_cb__gtnets_jitter, NULL);
-    xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
+    xbt_cfg_setdefault_double(_surf_cfg_set, "gtnets_jitter", 0.0);
 
     default_value_int = 10;
     xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
 
     default_value_int = 10;
     xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
@@ -381,7 +381,7 @@ void surf_config_init(int *argc, char **argv)
                   "__surf_get_initial_path() failed! Can't resolves current Windows directory");
 
       surf_path = xbt_dynar_new(sizeof(char *), NULL);
                   "__surf_get_initial_path() failed! Can't resolves current Windows directory");
 
       surf_path = xbt_dynar_new(sizeof(char *), NULL);
-      xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
+      xbt_cfg_setdefault_string(_surf_cfg_set, "path", initial_path);
     }
 
 
     }
 
 
index 632b140..b053b28 100644 (file)
@@ -3251,12 +3251,17 @@ static void routing_parse_Sconfig(void)
 static void routing_parse_Econfig(void)
 {
   xbt_dict_cursor_t cursor = NULL;
 static void routing_parse_Econfig(void)
 {
   xbt_dict_cursor_t cursor = NULL;
+  xbt_cfgelm_t variable;
   char *key;
   char *elem;
   char *cfg;
   xbt_dict_foreach(current_property_set, cursor, key, elem) {
          cfg = bprintf("%s:%s",key,elem);
   char *key;
   char *elem;
   char *cfg;
   xbt_dict_foreach(current_property_set, cursor, key, elem) {
          cfg = bprintf("%s:%s",key,elem);
-         xbt_cfg_set_parse(_surf_cfg_set, cfg);
+         variable = xbt_cfgelm_get(_surf_cfg_set, key, xbt_cfgelm_any);
+         if(variable->isdefault)
+                 xbt_cfg_set_parse(_surf_cfg_set, cfg);
+         else
+                 INFO1("The custom configuration '%s' is already define by user!",key);
        }
   DEBUG1("End configuration name = %s",A_surfxml_config_id);
 }
        }
   DEBUG1("End configuration name = %s",A_surfxml_config_id);
 }
index 7377b0c..56213d5 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
-/* xbt_cfgelm_t: the typedef corresponding to a config variable.
-
-   Both data and DTD are mixed, but fixing it now would prevent me to ever
-   defend my thesis. */
-
-typedef struct {
-  /* Description */
-  char *desc;
-
-  /* Allowed type of the variable */
-  e_xbt_cfgelm_type_t type;
-  int min, max;
-  int isdefault:1;
-
-  /* Callbacks */
-  xbt_cfg_cb_t cb_set;
-  xbt_cfg_cb_t cb_rm;
-
-  /* actual content
-     (cannot be an union because type peer uses both str and i) */
-  xbt_dynar_t content;
-} s_xbt_cfgelm_t, *xbt_cfgelm_t;
-
 static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count] =
     { "int", "double", "string", "peer", "any" };
 
 /* Internal stuff used in cache to free a variable */
 static void xbt_cfgelm_free(void *data);
 
 static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count] =
     { "int", "double", "string", "peer", "any" };
 
 /* Internal stuff used in cache to free a variable */
 static void xbt_cfgelm_free(void *data);
 
-/* Retrieve the variable we'll modify */
-static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name,
-                                   e_xbt_cfgelm_type_t type);
-
 /*----[ Memory management ]-----------------------------------------------*/
 
 /** @brief Constructor
 /*----[ Memory management ]-----------------------------------------------*/
 
 /** @brief Constructor
@@ -434,7 +407,7 @@ void xbt_cfg_check(xbt_cfg_t cfg)
   xbt_dict_cursor_free(&cursor);
 }
 
   xbt_dict_cursor_free(&cursor);
 }
 
-static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg,
+xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg,
                                    const char *name,
                                    e_xbt_cfgelm_type_t type)
 {
                                    const char *name,
                                    e_xbt_cfgelm_type_t type)
 {
@@ -729,9 +702,11 @@ void xbt_cfg_setdefault_int(xbt_cfg_t cfg, const char *name, int val)
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
 
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
 
-  if (variable->isdefault)
+  if (variable->isdefault){
     xbt_cfg_set_int(cfg, name, val);
     xbt_cfg_set_int(cfg, name, val);
-  else
+    variable->isdefault = 1;
+  }
+   else
     DEBUG2
         ("Do not override configuration variable '%s' with value '%d' because it was already set.",
          name, val);
     DEBUG2
         ("Do not override configuration variable '%s' with value '%d' because it was already set.",
          name, val);
@@ -746,8 +721,10 @@ void xbt_cfg_setdefault_double(xbt_cfg_t cfg, const char *name, double val)
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
 
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
 
-  if (variable->isdefault)
+  if (variable->isdefault) {
     xbt_cfg_set_double(cfg, name, val);
     xbt_cfg_set_double(cfg, name, val);
+    variable->isdefault = 1;
+  }
   else
     DEBUG2
         ("Do not override configuration variable '%s' with value '%lf' because it was already set.",
   else
     DEBUG2
         ("Do not override configuration variable '%s' with value '%lf' because it was already set.",
@@ -764,8 +741,10 @@ void xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name,
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
 
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
 
-  if (variable->isdefault)
+  if (variable->isdefault){
     xbt_cfg_set_string(cfg, name, val);
     xbt_cfg_set_string(cfg, name, val);
+    variable->isdefault = 1;
+  }
   else
     DEBUG2
         ("Do not override configuration variable '%s' with value '%s' because it was already set.",
   else
     DEBUG2
         ("Do not override configuration variable '%s' with value '%s' because it was already set.",
@@ -782,8 +761,10 @@ void xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name,
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
 
 {
   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
 
-  if (variable->isdefault)
+  if (variable->isdefault){
     xbt_cfg_set_peer(cfg, name, host, port);
     xbt_cfg_set_peer(cfg, name, host, port);
+    variable->isdefault = 1;
+  }
   else
     DEBUG3
         ("Do not override configuration variable '%s' with value '%s:%d' because it was already set.",
   else
     DEBUG3
         ("Do not override configuration variable '%s' with value '%s:%d' because it was already set.",
index 14102d8..7c910f4 100644 (file)
@@ -82,6 +82,15 @@ $ ${bindir:=.}/basic_parsing_test ./properties.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'path' to '~/'
 > Workstation number: 1, link number: 1
 
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'path' to '~/'
 > Workstation number: 1, link number: 1
 
+$ ${bindir:=.}/basic_parsing_test ./properties.xml --cfg=cpu/model:CpuTI
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'cpu/model' to 'CpuTI'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'maxmin/precision' to '0.000010'
+> [0.000000] [surf_route/INFO] The custom configuration 'cpu/model' is already define by user!
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'workstation/model' to 'compound'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'Vegas'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'path' to '~/'
+> Workstation number: 1, link number: 1
+
 $ ${bindir:=.}/basic_parsing_test ./one_cluster_file.xml
 > [0.000000] [surf_workstation/INFO] surf_workstation_model_init_ptask_L07
 > Workstation number: 2, link number: 5
\ No newline at end of file
 $ ${bindir:=.}/basic_parsing_test ./one_cluster_file.xml
 > [0.000000] [surf_workstation/INFO] surf_workstation_model_init_ptask_L07
 > Workstation number: 2, link number: 5
\ No newline at end of file