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_t workstation = xbt_new0(s_SD_workstation_t, 1);
14 workstation->surf_workstation = surf_workstation;
15 workstation->data = data; /* user data */
17 const char *name = SD_workstation_get_name(workstation);
18 xbt_dict_set(sd_global->workstations, name, workstation, __SD_workstation_destroy); /* add the workstation to the dictionary */
19 sd_global->workstation_count++;
24 /* Returns a workstation given its name, or NULL if there is no such workstation.
26 SD_workstation_t SD_workstation_get_by_name(const char *name) {
29 xbt_assert0(name != NULL, "Invalid parameter");
31 return xbt_dict_get_or_null(sd_global->workstations, name);
34 /* Returns a NULL-terminated array of existing workstations.
36 SD_workstation_t* SD_workstation_get_list(void) {
39 SD_workstation_t* array = xbt_new0(SD_workstation_t, sd_global->workstation_count + 1);
41 xbt_dict_cursor_t cursor;
46 xbt_dict_foreach(sd_global->workstations, cursor, key, data) {
47 array[i++] = (SD_workstation_t) data;
54 /* Returns the number or workstations.
56 int SD_workstation_get_number(void) {
58 return sd_global->workstation_count;
61 /* 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.
63 void SD_workstation_set_data(SD_workstation_t workstation, void *data) {
65 xbt_assert0(workstation != NULL, "Invalid parameter");
66 workstation->data = data;
69 /* Returns the data of a workstation. The user data can be NULL.
71 void* SD_workstation_get_data(SD_workstation_t workstation) {
73 xbt_assert0(workstation != NULL, "Invalid parameter");
74 return workstation->data;
77 /* Returns the name of a workstation.
79 const char* SD_workstation_get_name(SD_workstation_t workstation) {
81 xbt_assert0(workstation != NULL, "Invalid parameter");
82 return surf_workstation_resource->common_public->get_resource_name(workstation->surf_workstation);
85 /* Returns an new array of links representating the route between two workstations.
87 SD_link_t* SD_workstation_route_get_list(SD_workstation_t src, SD_workstation_t dst) {
90 void *surf_src = src->surf_workstation;
91 void *surf_dst = dst->surf_workstation;
93 const void **surf_route = surf_workstation_resource->extension_public->get_route(surf_src, surf_dst);
94 int route_size = surf_workstation_resource->extension_public->get_route_size(surf_src, surf_dst);
96 SD_link_t* route = xbt_new0(SD_link_t, route_size);
97 const char *link_name;
99 for (i = 0; i < route_size; i++) {
100 link_name = surf_workstation_resource->extension_public->get_link_name(surf_route[i]);
101 route[i] = xbt_dict_get(sd_global->links, link_name);
107 /* Returns the number of links on the route between two workstations.
109 int SD_workstation_route_get_size(SD_workstation_t src, SD_workstation_t dst) {
110 SD_CHECK_INIT_DONE();
111 return surf_workstation_resource->extension_public->
112 get_route_size(src->surf_workstation, dst->surf_workstation);
115 /* Returns the total power of a workstation.
117 double SD_workstation_get_power(SD_workstation_t workstation) {
118 SD_CHECK_INIT_DONE();
119 xbt_assert0(workstation != NULL, "Invalid parameter");
120 return surf_workstation_resource->extension_public->get_speed(workstation->surf_workstation, 1.0);
123 /* Returns the proportion of available power in a workstation (normally a number between 0 and 1).
125 double SD_workstation_get_available_power(SD_workstation_t workstation) {
126 SD_CHECK_INIT_DONE();
127 xbt_assert0(workstation != NULL, "Invalid parameter");
128 return surf_workstation_resource->extension_public->get_available_speed(workstation->surf_workstation);
131 /* Destroys a workstation. The user data (if any) should have been destroyed first.
133 void __SD_workstation_destroy(void *workstation) {
134 SD_CHECK_INIT_DONE();
135 xbt_assert0(workstation != NULL, "Invalid parameter");
136 /* workstation->surf_workstation is freed by surf_exit and workstation->data is freed by the user */
137 xbt_free(workstation);