Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid
[simgrid.git] / examples / simdag / properties / sd_prop.c
1 /* Copyright (c) 2007-2014. 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   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   /* initialisation of SD */
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   SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
43   name1 = SD_workstation_get_name(w1);
44   name2 = SD_workstation_get_name(w2);
45
46
47   /* The host properties can be retrived from all interfaces */
48
49   XBT_INFO("Property list for workstation %s", name1);
50   /* Get the property list of the workstation 1 */
51   props = SD_workstation_get_properties(w1);
52
53
54   /* Trying to set a new property */
55   xbt_dict_set(props, "NewProp", strdup("newValue"), xbt_free_f);
56
57   /* Print the properties of the workstation 1 */
58   xbt_dict_foreach(props, cursor, key, data) {
59     XBT_INFO("\tProperty: %s has value: %s", key, data);
60   }
61
62   /* Try to get a property that does not exist */
63
64   value = SD_workstation_get_property_value(w1, noexist);
65   if (value == NULL)
66     XBT_INFO("\tProperty: %s is undefined", noexist);
67   else
68     XBT_INFO("\tProperty: %s has value: %s", noexist, value);
69
70
71   XBT_INFO("Property list for workstation %s", name2);
72   /* Get the property list of the workstation 2 */
73   props = SD_workstation_get_properties(w2);
74   cursor = NULL;
75
76   /* Print the properties of the workstation 2 */
77   xbt_dict_foreach(props, cursor, key, data) {
78     XBT_INFO("\tProperty: %s on host: %s", key, data);
79   }
80
81   /* Modify an existing property test. First check it exists */
82   XBT_INFO("Modify an existing property");
83
84   value = SD_workstation_get_property_value(w2, exist);
85   if (value == NULL)
86     XBT_INFO("\tProperty: %s is undefined", exist);
87   else {
88     XBT_INFO("\tProperty: %s old value: %s", exist, value);
89     xbt_dict_set(props, exist, strdup("250"), xbt_free_f);
90   }
91
92   /* Test if we have changed the value */
93   value = SD_workstation_get_property_value(w2, exist);
94   if (value == NULL)
95     XBT_INFO("\tProperty: %s is undefined", exist);
96   else
97     XBT_INFO("\tProperty: %s new value: %s", exist, value);
98
99   /* Test if properties are displayed by SD_workstation_dump */
100   SD_workstation_dump(w2);
101
102   SD_exit();
103   return 0;
104 }