Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Starting the SimDag revolution: Easter trimming
[simgrid.git] / examples / simdag / properties / sd_prop.c
1 /* Copyright (c) 2007-2015. 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 "simgrid/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   SD_workstation_t w1;
20   SD_workstation_t w2;
21   const char *name1;
22   const char *name2;
23   xbt_dict_t props;
24   xbt_dict_cursor_t cursor = NULL;
25   char *key, *data;
26   char noexist[] = "NoProp";
27   const char *value;
28   char exist[] = "Hdd";
29
30   /* SD initialization */
31   SD_init(&argc, argv);
32   if (argc < 2) {
33     XBT_INFO("Usage: %s platform_file", argv[0]);
34     XBT_INFO("example: %s sd_platform.xml", argv[0]);
35     exit(1);
36   }
37   SD_create_environment(argv[1]);
38
39   /* init of platform elements */
40   w1 = SD_workstation_get_by_name("host1");
41   w2 = SD_workstation_get_by_name("host2");
42   name1 = SD_workstation_get_name(w1);
43   name2 = SD_workstation_get_name(w2);
44
45
46   /* The host properties can be retrived from all interfaces */
47
48   XBT_INFO("Property list for workstation %s", name1);
49   /* Get the property list of the workstation 1 */
50   props = SD_workstation_get_properties(w1);
51
52
53   /* Trying to set a new property */
54   xbt_dict_set(props, "NewProp", strdup("newValue"), xbt_free_f);
55
56   /* Print the properties of the workstation 1 */
57   xbt_dict_foreach(props, cursor, key, data) {
58     XBT_INFO("\tProperty: %s has value: %s", key, data);
59   }
60
61   /* Try to get a property that does not exist */
62
63   value = SD_workstation_get_property_value(w1, noexist);
64   if (value == NULL)
65     XBT_INFO("\tProperty: %s is undefined", noexist);
66   else
67     XBT_INFO("\tProperty: %s has value: %s", noexist, value);
68
69
70   XBT_INFO("Property list for workstation %s", name2);
71   /* Get the property list of the workstation 2 */
72   props = SD_workstation_get_properties(w2);
73   cursor = NULL;
74
75   /* Print the properties of the workstation 2 */
76   xbt_dict_foreach(props, cursor, key, data) {
77     XBT_INFO("\tProperty: %s on host: %s", key, data);
78   }
79
80   /* Modify an existing property test. First check it exists */
81   XBT_INFO("Modify an existing property");
82
83   value = SD_workstation_get_property_value(w2, exist);
84   if (value == NULL)
85     XBT_INFO("\tProperty: %s is undefined", exist);
86   else {
87     XBT_INFO("\tProperty: %s old value: %s", exist, value);
88     xbt_dict_set(props, exist, strdup("250"), xbt_free_f);
89   }
90
91   /* Test if we have changed the value */
92   value = SD_workstation_get_property_value(w2, exist);
93   if (value == NULL)
94     XBT_INFO("\tProperty: %s is undefined", exist);
95   else
96     XBT_INFO("\tProperty: %s new value: %s", exist, value);
97
98   /* Test if properties are displayed by SD_workstation_dump */
99   SD_workstation_dump(w2);
100
101   SD_exit();
102   return 0;
103 }