Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d3e3498cb11ebd67a7dd7253dbde12a20c8c0e2b
[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/log.h"
14 #include "gras_config.h"
15
16 int _msg_init_status = 0; /* 0: beginning of time; 
17                              1: pre-inited (cfg_set created); 
18                              2: inited (running) */
19 xbt_cfg_t _msg_cfg_set = NULL;
20
21 /* callback of the surf_workstation_model variable */
22 static void _msg_cfg_cb__surf_workstation_model(const char *name, int pos) {
23   char *val;
24
25   xbt_assert0(_msg_init_status<2, "Cannot change the model after the initialization");
26   
27   val = xbt_cfg_get_string (_msg_cfg_set, name);
28
29 #ifdef USE_GTNETS
30   xbt_assert1(!strcmp(val, "CLM03") ||
31               !strcmp(val, "KCCFLN05") ||
32               !strcmp(val, "GTNETS"),
33               "Unknown workstation model: %s (either 'CLM03', 'KCCFLN05', or 'GTNETS'",val);
34 #else
35   xbt_assert1(!strcmp(val, "CLM03") ||
36               !strcmp(val, "KCCFLN05"),
37               "Unknown workstation model: %s (either 'CLM03' or 'KCCFLN05'",val);
38 #endif
39
40 }
41
42 /* create the config set and register what should be */
43 void msg_config_init(void) {
44
45   if (_msg_init_status) 
46     return; /* Already inited, nothing to do */
47
48   _msg_init_status = 1;
49   _msg_cfg_set = xbt_cfg_new();
50   
51   xbt_cfg_register (_msg_cfg_set, 
52                     "surf_workstation_model", xbt_cfgelm_string, 1,1,
53                     &_msg_cfg_cb__surf_workstation_model,NULL);
54                     
55   xbt_cfg_set_string(_msg_cfg_set,"surf_workstation_model", "KCCFLN05");
56 }
57
58 void msg_config_finalize(void) {
59
60   if (!_msg_init_status) 
61     return; /* Not initialized yet. Nothing to do */
62
63   xbt_cfg_free(&_msg_cfg_set);
64   _msg_init_status = 0;
65 }
66
67 /** \brief set a configuration variable
68  * 
69  * Currently existing configuation variable:
70  *   - surf_workstation_model (string): Model of workstation to use.  
71  *     Possible values (defaults to "KCCFLN05"):
72  *     - "CLM03": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + support for parallel tasks
73  *     - "KCCFLN05": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + failure handling + interference between communications and computations if precised in the platform file.
74  * 
75  * Example:
76  * MSG_config("surf_workstation_model","KCCFLN05");
77  */
78 void
79 MSG_config(const char *name, ...) {
80   va_list pa;
81     
82   if (!_msg_init_status) {
83     msg_config_init();
84   }
85   /*  xbt_cfg_dump("msg_cfg_set","",_msg_cfg_set);*/
86   va_start(pa,name);
87   xbt_cfg_set_vargs(_msg_cfg_set,name,pa);
88   va_end(pa);
89
90 }