Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
One day ALNeM will be referenced here... :)
[simgrid.git] / src / simdag / sd_workstation.c
1 #include "private.h"
2 #include "simdag/simdag.h"
3 #include "xbt/dict.h"
4 #include "xbt/sysdep.h"
5
6 /* Creates a workstation and registers it in SG.
7  */
8 SG_workstation_t __SG_workstation_create(const char *name, void *surf_workstation, void *data) {
9   SG_workstation_data_t sgdata = xbt_new0(s_SG_workstation_data_t, 1); /* workstation private data */
10   sgdata->surf_workstation = surf_workstation;
11   
12   SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1);
13   workstation->name = xbt_strdup(name);
14   workstation->data = data; /* user data */
15   workstation->sgdata = sgdata; /* private data */
16   
17   xbt_dict_set(sg_global->workstations, name, workstation, free); /* add the workstation to the dictionary */
18
19   /* TODO: route */
20
21   return workstation;
22 }
23
24 /* Returns a workstation given its name, or NULL if there is no such workstation.
25  */
26 SG_workstation_t SG_workstation_get_by_name(const char *name) {
27   xbt_assert0(sg_global != NULL, "SG_init not called yet");
28   xbt_assert0(name != NULL, "Invalid parameter");
29
30   return xbt_dict_get_or_null(sg_global->workstations, name);
31 }
32
33 /* Returns a NULL-terminated array of existing workstations.
34  */
35 SG_workstation_t*  SG_workstation_get_list(void) {
36   xbt_assert0(sg_global != NULL, "SG_init not called yet");
37   SG_workstation_t* array = xbt_new0(SG_workstation_t, sg_global->workstation_count + 1);
38   
39   xbt_dict_cursor_t cursor;
40   char *key;
41   void *data;
42   int i=0;
43
44   xbt_dict_foreach(sg_global->workstations,cursor,key,data) {
45     array[i++] = (SG_workstation_t) data;
46   }
47   array[i] = NULL;
48
49   return array;
50 }
51
52 /* Returns the number or workstations.
53  */
54 int SG_workstation_get_number(void) {
55   xbt_assert0(sg_global != NULL, "SG_init not called yet");
56   return sg_global->workstation_count;
57 }
58
59 /* Sets the data of a workstation. The new data can be NULL. The old data should have been freed first if it was not NULL.
60  */
61 void SG_workstation_set_data(SG_workstation_t workstation, void *data) {
62   xbt_assert0(workstation != NULL, "Invalid parameter");
63   workstation->data = data;
64 }
65
66 /* Returns the data of a workstation. The user data can be NULL.
67  */
68 void* SG_workstation_get_data(SG_workstation_t workstation) {
69   xbt_assert0(workstation != NULL, "Invalid parameter");
70   return workstation->data;
71 }
72
73 /* Returns the name of a workstation.
74  */
75 const char* SG_workstation_get_name(SG_workstation_t workstation) {
76   xbt_assert0(workstation != NULL, "Invalid parameter");
77   return workstation->name;
78 }
79
80 SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) {
81   /* TODO */
82   return NULL;
83 }
84
85 int SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst) {
86   /* TODO */
87   return 0;
88 }
89
90 /* Returns the total power of a workstation.
91  */
92 double SG_workstation_get_power(SG_workstation_t workstation) {
93   xbt_assert0(workstation != NULL, "Invalid parameter");
94   /* TODO */
95   return 0;
96   /*  return workstation->power;*/
97 }
98
99 /* Return the available power of a workstation.
100  */
101 double SG_workstation_get_available_power(SG_workstation_t workstation) {
102   xbt_assert0(workstation != NULL, "Invalid parameter");
103   /* TODO */
104   return 0;
105   /*return workstation->available_power;*/
106 }
107
108 /* Destroys a workstation. The user data (if any) should have been destroyed first.
109  */
110 void __SG_workstation_destroy(SG_workstation_t workstation) {
111   xbt_assert0(workstation != NULL, "Invalid parameter");
112
113   if (workstation->sgdata != NULL) {
114     xbt_free(workstation->sgdata);
115   }
116   
117   if (workstation->name != NULL) {
118     xbt_free(workstation->name);
119   }
120   
121   /* TODO: route */
122
123   xbt_free(workstation);
124 }