Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Tasks must be initialized.
[simgrid.git] / examples / simdag / properties / sd_prop.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "simdag/simdag.h"
10 #include "xbt/ex.h"
11 #include "xbt/log.h"
12 #include "xbt/dynar.h"
13 #include "xbt/dict.h"
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
16
17 int main(int argc, char **argv)
18 {
19   const SD_workstation_t *workstations;
20   SD_workstation_t w1;
21   SD_workstation_t w2;
22   const char *name1;
23   const char *name2;
24   xbt_dict_t props;
25   xbt_dict_cursor_t cursor = NULL;
26   char *key, *data;
27   char noexist[] = "NoProp";
28   const char *value;
29   char exist[] = "SG_TEST_Hdd";
30
31   /* initialisation of SD */
32   SD_init(&argc, argv);
33   if (argc < 2) {
34     XBT_INFO("Usage: %s platform_file", argv[0]);
35     XBT_INFO("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   XBT_INFO("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, "NewProp", strdup("newValue"), free);
58
59   /* Print the properties of the workstation 1 */
60   xbt_dict_foreach(props, cursor, key, data) {
61     XBT_INFO("\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     XBT_INFO("\tProperty: %s is undefined", noexist);
69   else
70     XBT_INFO("\tProperty: %s has value: %s", noexist, value);
71
72
73   XBT_INFO("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     XBT_INFO("\tProperty: %s on host: %s", key, data);
81   }
82
83   /* Modify an existing property test. First check it exists */
84   XBT_INFO("Modify an existing property");
85
86   value = SD_workstation_get_property_value(w2, exist);
87   if (value == NULL)
88     XBT_INFO("\tProperty: %s is undefined", exist);
89   else {
90     XBT_INFO("\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     XBT_INFO("\tProperty: %s is undefined", exist);
98   else
99     XBT_INFO("\tProperty: %s new value: %s", exist, value);
100
101   SD_exit();
102   return 0;
103 }