Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Missing LOG 9 and LOG10 when XBT_LOG_MAYDAY is defined
[simgrid.git] / src / simdag / sd_workstation.c
1 #include "simdag/simdag.h"
2 #include "xbt/dict.h"
3 #include "xbt/sysdep.h"
4 /*#include "private.h"*/
5
6 static xbt_dict_t workstations;  /* workstation list */
7 static int workstation_count; /* number of workstations */
8
9   void *data;
10   char *name;
11   double power;
12   double available_power;
13   /* TODO: route */
14
15 /* Creates a workstation.
16  */
17 SG_workstation_t SG_workstation_create(void *data, const char *name, double power,
18                                       double available_power) {
19   xbt_assert0(power >= 0 && available_power >= 0, "Invalid parameter"); /* or > 0 ? */
20
21   SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1);
22   
23   workstation->data = data;
24   workstation->name = xbt_strdup(name);
25   workstation->power = power;
26   workstation->available_power = power;
27   /* TODO: route */
28
29   return workstation;
30 }
31
32 /* Returns a workstation given its name, or NULL if there is no such workstation.
33  */
34 SG_workstation_t SG_workstation_get_by_name(const char *name) {
35   xbt_assert0(name, "Invalid parameter");
36
37   return xbt_dict_get_or_null(workstations, name);
38 }
39
40 /* Returns a NULL-terminated array of existing workstations.
41  */
42 SG_workstation_t*  SG_workstation_get_list(void) {
43   SG_workstation_t* array = xbt_new0(SG_workstation_t, workstation_count + 1);
44   
45   xbt_dict_cursor_t cursor;
46   char *key;
47   void *data;
48   int i=0;
49
50   xbt_dict_foreach(workstations,cursor,key,data) {
51     array[i++] = (SG_workstation_t) data;
52   }
53   array[i] = NULL;
54
55   return array;
56 }
57
58 /* Returns the number or workstations.
59  */
60 int SG_workstation_get_number(void) {
61   return workstation_count;
62 }
63
64 /* Sets the data of a workstation.
65  */
66 void SG_workstation_set_data(SG_workstation_t workstation, void *data) {
67   xbt_assert0(workstation, "Invalid parameter");
68   workstation->data = data;
69 }
70
71 /* Returns the data of a workstation.
72  */
73 void* SG_workstation_get_data(SG_workstation_t workstation) {
74   xbt_assert0(workstation, "Invalid parameter");
75   return workstation->data;
76 }
77
78 /* Returns the name of a workstation.
79  */
80 const char* SG_workstation_get_name(SG_workstation_t workstation) {
81   xbt_assert0(workstation, "Invalid parameter");
82   return workstation->name;
83 }
84
85 SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) {
86   /* TODO */
87   return NULL;
88 }
89
90 int SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst) {
91   /* TODO */
92   return 0;
93 }
94
95 /* Returns the total power of a workstation.
96  */
97 double SG_workstation_get_power(SG_workstation_t workstation) {
98   xbt_assert0(workstation, "Invalid parameter");
99   return workstation->power;
100 }
101
102 /* Return the available power of a workstation.
103  */
104 double SG_workstation_get_available_power(SG_workstation_t workstation) {
105   xbt_assert0(workstation, "Invalid parameter");
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, "Invalid parameter");
113
114   if (workstation->name)
115     free(workstation->name);
116
117   /* TODO: route */
118
119   free(workstation);
120 }