Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fa74db454e542d376182fd2c0d7879994345fa19
[simgrid.git] / examples / gras / properties / gras_prop.c
1 /*      $Id$     */
2
3 #include "gras.h"
4
5 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Simple Property example");
6
7
8 int client(int argc, char *argv[]) {
9   gras_init(&argc,argv);
10
11   /* Get the properties */
12   xbt_dict_t props = gras_process_properties();
13   xbt_dict_cursor_t cursor = NULL;
14   char *key,*data;
15
16   /* Print the properties of the workstation 1 */
17   xbt_dict_foreach(props,cursor,key,data) {
18     INFO2("Process property: %s has value: %s",key,data);
19   }
20  
21   /* Try to get a property that does not exist */
22   char *noexist="Nonexisent";
23   const char *value = gras_process_property_value(noexist);
24   if ( value == NULL) 
25     INFO1("Process property: %s is undefined", noexist);
26   else
27     INFO2("Process property: %s has value: %s", noexist, value);
28  
29    /* Modify an existing property. First check it exists */\
30     INFO0("Trying to modify a process property");
31     char *exist="otherprop";
32     value = gras_process_property_value(exist);
33     if ( value == NULL) 
34       INFO1("\tProperty: %s is undefined", exist);
35     else {
36       INFO2("\tProperty: %s old value: %s", exist, value);
37       xbt_dict_set(props, exist, strdup("newValue"), free);  
38     }
39  
40     /* Test if we have changed the value */
41     value = gras_process_property_value(exist);
42     if ( value == NULL) 
43       INFO1("\tProperty: %s is undefined", exist);
44     else
45       INFO2("\tProperty: %s new value: %s", exist, value);
46  
47   gras_exit();
48   return 0;
49 }
50
51 int server(int argc, char *argv[]) {
52   gras_init(&argc,argv);
53
54   /* Get the properties */
55   xbt_dict_t props = gras_os_host_properties();
56   xbt_dict_cursor_t cursor = NULL;
57   char *key,*data;
58
59   /* Print the properties of the workstation 1 */
60   xbt_dict_foreach(props,cursor,key,data) {
61     INFO2("Host property: %s has value: %s",key,data);
62   }
63  
64   /* Try to get a property that does not exist */
65   char *noexist="Nonexisent";
66   const char *value = gras_os_host_property_value(noexist);
67   if ( value == NULL) 
68     INFO1("Host property: %s is undefined", noexist);
69   else
70     INFO2("Host property: %s has value: %s", noexist, value);
71   
72   gras_exit();
73   return 0;
74 }