Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9b7d4244d2587f0f16dd4e39191576ce2c023c55
[simgrid.git] / examples / simdag / properties / sd_prop.c
1 /*      $Id$     */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include "simdag/simdag.h"
6 #include "xbt/ex.h"
7 #include "xbt/log.h"
8 #include "xbt/dynar.h"
9 #include "xbt/dict.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
12
13 int main(int argc, char **argv)
14 {
15   const SD_workstation_t *workstations;
16   SD_workstation_t w1;
17   SD_workstation_t w2;
18   const char *name1;
19   const char *name2;
20   xbt_dict_t props;
21   xbt_dict_cursor_t cursor = NULL;
22   char *key, *data;
23   char noexist[] = "NoProp";
24   const char *value;
25   char exist[] = "SG_TEST_Hdd";
26
27   /* initialisation of SD */
28   SD_init(&argc, argv);
29   if (argc < 2) {
30     INFO1("Usage: %s platform_file", argv[0]);
31     INFO1("example: %s sd_platform.xml", argv[0]);
32     exit(1);
33   }
34   SD_create_environment(argv[1]);
35
36   /* init of platform elements */
37   workstations = SD_workstation_get_list();
38   w1 = workstations[0];
39   w2 = workstations[1];
40   SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
41   name1 = SD_workstation_get_name(w1);
42   name2 = SD_workstation_get_name(w2);
43
44
45   /* The host properties can be retrived from all interfaces */
46
47   INFO1("Property list for workstation %s", name1);
48   /* Get the property list of the workstation 1 */
49   props = SD_workstation_get_properties(w1);
50
51
52   /* Trying to set a new property */
53   xbt_dict_set(props, xbt_strdup("NewProp"), strdup("newValue"), free);
54
55   /* Print the properties of the workstation 1 */
56   xbt_dict_foreach(props, cursor, key, data) {
57     INFO2("\tProperty: %s has value: %s", key, data);
58   }
59
60   /* Try to get a property that does not exist */
61
62   value = SD_workstation_get_property_value(w1, noexist);
63   if (value == NULL)
64     INFO1("\tProperty: %s is undefined", noexist);
65   else
66     INFO2("\tProperty: %s has value: %s", noexist, value);
67
68
69   INFO1("Property list for workstation %s", name2);
70   /* Get the property list of the workstation 2 */
71   props = SD_workstation_get_properties(w2);
72   cursor = NULL;
73
74   /* Print the properties of the workstation 2 */
75   xbt_dict_foreach(props, cursor, key, data) {
76     INFO2("\tProperty: %s on host: %s", key, data);
77   }
78
79   /* Modify an existing property test. First check it exists */
80   INFO0("Modify an existing property");
81
82   value = SD_workstation_get_property_value(w2, exist);
83   if (value == NULL)
84     INFO1("\tProperty: %s is undefined", exist);
85   else {
86     INFO2("\tProperty: %s old value: %s", exist, value);
87     xbt_dict_set(props, exist, strdup("250"), free);
88   }
89
90   /* Test if we have changed the value */
91   value = SD_workstation_get_property_value(w2, exist);
92   if (value == NULL)
93     INFO1("\tProperty: %s is undefined", exist);
94   else
95     INFO2("\tProperty: %s new value: %s", exist, value);
96
97   SD_exit();
98   return 0;
99 }