Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add private structures and functions + wrapping for Surf links and workstations
[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.
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.
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 NULL;
78   /*  return workstation->name;*/
79 }
80
81 SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) {
82   /* TODO */
83   return NULL;
84 }
85
86 int SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst) {
87   /* TODO */
88   return 0;
89 }
90
91 /* Returns the total power of a workstation.
92  */
93 double SG_workstation_get_power(SG_workstation_t workstation) {
94   xbt_assert0(workstation != NULL, "Invalid parameter");
95   /* TODO */
96   return 0;
97   /*  return workstation->power;*/
98 }
99
100 /* Return the available power of a workstation.
101  */
102 double SG_workstation_get_available_power(SG_workstation_t workstation) {
103   xbt_assert0(workstation != NULL, "Invalid parameter");
104   /* TODO */
105   return 0;
106   /*return workstation->available_power;*/
107 }
108
109 /* Destroys a workstation. The user data (if any) should have been destroyed first.
110  */
111 void __SG_workstation_destroy(SG_workstation_t workstation) {
112   xbt_assert0(workstation != NULL, "Invalid parameter");
113
114   SG_workstation_data_t sgdata = workstation->sgdata;
115   if (sgdata != NULL) {
116     xbt_free(sgdata);
117   }
118   
119   /* TODO: route */
120
121   xbt_free(workstation);
122 }