2 #include "simdag/simdag.h"
4 #include "xbt/sysdep.h"
7 /* Creates a workstation and registers it in SD.
9 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) {
11 xbt_assert0(surf_workstation != NULL, "surf_workstation is NULL !");
13 SD_workstation_data_t sd_data = xbt_new0(s_SD_workstation_data_t, 1); /* workstation private data */
14 sd_data->surf_workstation = surf_workstation;
16 SD_workstation_t workstation = xbt_new0(s_SD_workstation_t, 1);
17 workstation->data = data; /* user data */
18 workstation->sd_data = sd_data; /* private data */
20 const char *name = SD_workstation_get_name(workstation);
21 xbt_dict_set(sd_global->workstations, name, workstation, __SD_workstation_destroy); /* add the workstation to the dictionary */
26 /* Returns a workstation given its name, or NULL if there is no such workstation.
28 SD_workstation_t SD_workstation_get_by_name(const char *name) {
31 xbt_assert0(name != NULL, "Invalid parameter");
33 return xbt_dict_get_or_null(sd_global->workstations, name);
36 /* Returns a NULL-terminated array of existing workstations.
38 SD_workstation_t* SD_workstation_get_list(void) {
41 SD_workstation_t* array = xbt_new0(SD_workstation_t, sd_global->workstation_count + 1);
43 xbt_dict_cursor_t cursor;
48 xbt_dict_foreach(sd_global->workstations,cursor,key,data) {
49 array[i++] = (SD_workstation_t) data;
56 /* Returns the number or workstations.
58 int SD_workstation_get_number(void) {
60 return sd_global->workstation_count;
63 /* 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.
65 void SD_workstation_set_data(SD_workstation_t workstation, void *data) {
67 xbt_assert0(workstation != NULL, "Invalid parameter");
68 workstation->data = data;
71 /* Returns the data of a workstation. The user data can be NULL.
73 void* SD_workstation_get_data(SD_workstation_t workstation) {
75 xbt_assert0(workstation != NULL, "Invalid parameter");
76 return workstation->data;
79 /* Returns the name of a workstation.
81 const char* SD_workstation_get_name(SD_workstation_t workstation) {
83 xbt_assert0(workstation != NULL, "Invalid parameter");
84 return surf_workstation_resource->common_public->get_resource_name(workstation->sd_data->surf_workstation);
87 /* Returns an new array of links representating the route between two workstations.
89 SD_link_t* SD_workstation_route_get_list(SD_workstation_t src, SD_workstation_t dst) {
92 void *surf_src = src->sd_data->surf_workstation;
93 void *surf_dst = dst->sd_data->surf_workstation;
95 const void **surf_route = surf_workstation_resource->extension_public->get_route(surf_src, surf_dst);
96 int route_size = surf_workstation_resource->extension_public->get_route_size(surf_src, surf_dst);
98 SD_link_t* route = xbt_new0(SD_link_t, route_size);
99 const char *link_name;
101 for (i = 0; i < route_size; i++) {
102 link_name = surf_workstation_resource->extension_public->get_link_name(surf_route[i]);
103 route[i] = xbt_dict_get(sd_global->links, link_name);
109 /* Returns the number of links on the route between two workstations.
111 int SD_workstation_route_get_size(SD_workstation_t src, SD_workstation_t dst) {
112 SD_CHECK_INIT_DONE();
113 return surf_workstation_resource->extension_public->
114 get_route_size(src->sd_data->surf_workstation, dst->sd_data->surf_workstation);
117 /* Returns the total power of a workstation.
119 double SD_workstation_get_power(SD_workstation_t workstation) {
120 SD_CHECK_INIT_DONE();
121 xbt_assert0(workstation != NULL, "Invalid parameter");
122 return surf_workstation_resource->extension_public->get_speed(workstation->sd_data->surf_workstation, 1.0);
125 /* Returns the proportion of available power in a workstation (normally a number between 0 and 1).
127 double SD_workstation_get_available_power(SD_workstation_t workstation) {
128 SD_CHECK_INIT_DONE();
129 xbt_assert0(workstation != NULL, "Invalid parameter");
130 return surf_workstation_resource->extension_public->get_available_speed(workstation->sd_data->surf_workstation);
133 /* Destroys a workstation. The user data (if any) should have been destroyed first.
135 void __SD_workstation_destroy(void *workstation) {
136 SD_CHECK_INIT_DONE();
137 xbt_assert0(workstation != NULL, "Invalid parameter");
139 if (((SD_workstation_t) workstation)->sd_data != NULL) {
140 xbt_free(((SD_workstation_t) workstation)->sd_data);
143 xbt_free(workstation);