Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove field name from strucure SD_link_t.
[simgrid.git] / src / simdag / sd_workstation.c
index f2c7afe..3d842ef 100644 (file)
@@ -8,6 +8,7 @@
  */
 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) {
   CHECK_INIT_DONE();
+  xbt_assert0(surf_workstation != NULL, "surf_workstation is NULL !");
 
   SD_workstation_data_t sd_data = xbt_new0(s_SD_workstation_data_t, 1); /* workstation private data */
   sd_data->surf_workstation = surf_workstation;
@@ -17,9 +18,8 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) {
   workstation->sd_data = sd_data; /* private data */
   
   const char *name = SD_workstation_get_name(workstation);
-  xbt_dict_set(sd_global->workstations, name, workstation, free); /* add the workstation to the dictionary */
+  xbt_dict_set(sd_global->workstations, name, workstation, __SD_workstation_destroy); /* add the workstation to the dictionary */
 
-  /* TODO: route */
   return workstation;
 }
 
@@ -84,16 +84,34 @@ const char* SD_workstation_get_name(SD_workstation_t workstation) {
   return surf_workstation_resource->common_public->get_resource_name(workstation->sd_data->surf_workstation);
 }
 
+/* Returns an new array of links representating the route between two workstations.
+ */
 SD_link_t* SD_workstation_route_get_list(SD_workstation_t src, SD_workstation_t dst) {
   CHECK_INIT_DONE();
-  /* TODO */
-  return NULL;
+
+  void *surf_src = src->sd_data->surf_workstation;
+  void *surf_dst = dst->sd_data->surf_workstation;
+
+  const void **surf_route = surf_workstation_resource->extension_public->get_route(surf_src, surf_dst);
+  int route_size = surf_workstation_resource->extension_public->get_route_size(surf_src, surf_dst);
+
+  SD_link_t* route = xbt_new0(SD_link_t, route_size);
+  const char *link_name;
+  int i;
+  for (i = 0; i < route_size; i++) {
+    link_name = surf_workstation_resource->extension_public->get_link_name(surf_route[i]);
+    route[i] = xbt_dict_get(sd_global->links, link_name);
+  }
+
+  return route;
 }
 
+/* Returns the number of links on the route between two workstations.
+ */
 int SD_workstation_route_get_size(SD_workstation_t src, SD_workstation_t dst) {
   CHECK_INIT_DONE();
-  /* TODO */
-  return 0;
+  return surf_workstation_resource->extension_public->
+    get_route_size(src->sd_data->surf_workstation, dst->sd_data->surf_workstation);
 }
 
 /* Returns the total power of a workstation.
@@ -109,22 +127,18 @@ double SD_workstation_get_power(SD_workstation_t workstation) {
 double SD_workstation_get_available_power(SD_workstation_t workstation) {
   CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
-  /* TODO */
-  return 0;
-  /*return workstation->available_power;*/
+  return surf_workstation_resource->extension_public->get_available_speed(workstation->sd_data->surf_workstation);
 }
 
 /* Destroys a workstation. The user data (if any) should have been destroyed first.
  */
-void __SD_workstation_destroy(SD_workstation_t workstation) {
+void __SD_workstation_destroy(void *workstation) {
   CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
 
-  if (workstation->sd_data != NULL) {
-    xbt_free(workstation->sd_data);
+  if (((SD_workstation_t) workstation)->sd_data != NULL) {
+    xbt_free(((SD_workstation_t) workstation)->sd_data);
   }
   
-  /* TODO: route */
-
   xbt_free(workstation);
 }