Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
119500052d1efa37bc1a9f914135a3e408671b87
[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   int i;
16   const SD_workstation_t *workstations;
17   SD_workstation_t w1;
18   SD_workstation_t w2;
19   const char *name1;
20   const char *name2;
21   xbt_dict_t props;
22   xbt_dict_cursor_t cursor = NULL;
23   char *key, *data;
24   char noexist[] = "NoProp";
25   const char *value;
26   char exist[] = "SG_TEST_Hdd";
27
28   const SD_link_t *route;
29   int route_size;
30
31   /* initialisation of SD */
32   SD_init(&argc, argv);
33   if (argc < 2) {
34     INFO1("Usage: %s platform_file", argv[0]);
35     INFO1("example: %s sd_platform.xml", argv[0]);
36     exit(1);
37   }
38   SD_create_environment(argv[1]);
39
40   /* init of platform elements */
41   workstations = SD_workstation_get_list();
42   w1 = workstations[0];
43   w2 = workstations[1];
44   SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
45   name1 = SD_workstation_get_name(w1);
46   name2 = SD_workstation_get_name(w2);
47
48
49   /* The host properties can be retrived from all interfaces */
50
51   INFO1("Property list for workstation %s", name1);
52   /* Get the property list of the workstation 1 */
53   props = SD_workstation_get_properties(w1);
54
55
56   /* Trying to set a new property */
57   xbt_dict_set(props, xbt_strdup("NewProp"), strdup("newValue"), free);
58
59   /* Print the properties of the workstation 1 */
60   xbt_dict_foreach(props, cursor, key, data) {
61     INFO2("\tProperty: %s has value: %s", key, data);
62   }
63
64   /* Try to get a property that does not exist */
65
66   value = SD_workstation_get_property_value(w1, noexist);
67   if (value == NULL)
68     INFO1("\tProperty: %s is undefined", noexist);
69   else
70     INFO2("\tProperty: %s has value: %s", noexist, value);
71
72
73   INFO1("Property list for workstation %s", name2);
74   /* Get the property list of the workstation 2 */
75   props = SD_workstation_get_properties(w2);
76   cursor = NULL;
77
78   /* Print the properties of the workstation 2 */
79   xbt_dict_foreach(props, cursor, key, data) {
80     INFO2("\tProperty: %s on host: %s", key, data);
81   }
82
83   /* Modify an existing property test. First check it exists */
84   INFO0("Modify an existing property");
85
86   value = SD_workstation_get_property_value(w2, exist);
87   if (value == NULL)
88     INFO1("\tProperty: %s is undefined", exist);
89   else {
90     INFO2("\tProperty: %s old value: %s", exist, value);
91     xbt_dict_set(props, exist, strdup("250"), free);
92   }
93
94   /* Test if we have changed the value */
95   value = SD_workstation_get_property_value(w2, exist);
96   if (value == NULL)
97     INFO1("\tProperty: %s is undefined", exist);
98   else
99     INFO2("\tProperty: %s new value: %s", exist, value);
100
101   /* NOTE: The link properties can be retrieved only from the SimDag interface */
102   route = SD_route_get_list(w1, w2);
103   route_size = SD_route_get_size(w1, w2);
104   for (i = 0; i < route_size; i++) {
105     xbt_dict_cursor_t cursor = NULL;
106     char *key, *data;
107     char noexist1[] = "Other";
108     props = SD_link_get_properties(route[i]);
109
110
111     /* Print the properties of the current link */
112     xbt_dict_foreach(props, cursor, key, data) {
113       INFO3("\tLink %s property: %s has value: %s",
114             SD_link_get_name(route[i]), key, data);
115
116       /* Try to get a property that does not exist */
117
118       value = SD_link_get_property_value(route[i], noexist1);
119       if (value == NULL)
120         INFO2("\tProperty: %s for link %s is undefined", noexist,
121               SD_link_get_name(route[i]));
122       else
123         INFO3("\tLink %s property: %s has value: %s",
124               SD_link_get_name(route[i]), noexist, value);
125     }
126
127   }
128
129   SD_exit();
130   return 0;
131 }