Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[simgrid.git] / src / msg / msg_config.c
1 /* $Id$ */
2
3 /* msg_config.c - support for MSG user configuration                        */
4
5 /* Copyright (c) 2005 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 "private.h"
12 #include "xbt/sysdep.h"
13 #include "xbt/error.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_cfg, msg,
16                                 "Configuration support in \ref MSG");
17
18
19 int _msg_init_status = 0; /* 0: beginning of time; 
20                              1: pre-inited (cfg_set created); 
21                              2: inited (running) */
22 xbt_cfg_t _msg_cfg_set = NULL;
23
24 /* callback of the surf_workstation_model variable */
25 static void _msg_cfg_cb__surf_workstation_model(const char *name, int pos) {
26   xbt_error_t errcode;
27   char *val;
28
29   xbt_assert0(_msg_init_status<2, "Cannot change the model after the initialization");
30   
31   TRYFAIL(xbt_cfg_get_string (_msg_cfg_set, name, &val));
32   
33   xbt_assert1(!strcmp(val, "CLM03") ||
34               !strcmp(val, "KCCFLN05"),
35               "Unknown workstation model: %s (either 'CLM03' or 'KCCFLN05'",val);
36 }
37
38 /* create the config set and register what should be */
39 void msg_config_init(void) {
40   xbt_error_t errcode;
41
42   if (_msg_init_status) 
43     return; /* Already inited, nothing to do */
44
45   _msg_init_status = 1;
46   _msg_cfg_set = xbt_cfg_new();
47   
48   xbt_cfg_register (_msg_cfg_set, 
49                     "surf_workstation_model", xbt_cfgelm_string, 1,1,
50                     &_msg_cfg_cb__surf_workstation_model,NULL);
51                     
52   TRYFAIL(xbt_cfg_set_string(_msg_cfg_set,"surf_workstation_model", "CLM03"));
53 }
54
55 /** \brief set a configuration variable
56  * 
57  * Currently existing configuation variable:
58  *   - surf_workstation_model (string): Model of workstation to use.  
59  *     Possible values (defaults to "CLM03"):
60  *     - "CLM03": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03])
61  *     - "KCCFLN05": simple network model (no latency) but interference 
62  *       between computations and communications (UNSTABLE, DONT USE)
63  * 
64  * Example:
65  * MSG_config("surf_workstation_model","CLM03");
66  */
67 xbt_error_t
68 MSG_config(const char *name, ...) {
69   va_list pa;
70   xbt_error_t errcode;
71     
72   if (!_msg_init_status) {
73     msg_config_init();
74   }
75 xbt_cfg_dump("msg_cfg_set","",_msg_cfg_set);
76   va_start(pa,name);
77   errcode=xbt_cfg_set_vargs(_msg_cfg_set,name,pa);
78   va_end(pa);
79   
80   return errcode;
81 }