Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update workstation handling in SimDag. Change the prefix of SimDag functions with...
[simgrid.git] / src / simdag / sd_workstation.c
index 0c3ab6e..f2c7afe 100644 (file)
@@ -2,47 +2,51 @@
 #include "simdag/simdag.h"
 #include "xbt/dict.h"
 #include "xbt/sysdep.h"
+#include "surf/surf.h"
 
-/* Creates a workstation and registers it in SG.
+/* Creates a workstation and registers it in SD.
  */
-SG_workstation_t __SG_workstation_create(const char *name, void *surf_workstation, void *data) {
-  SG_workstation_data_t sgdata = xbt_new0(s_SG_workstation_data_t, 1); /* workstation private data */
-  sgdata->surf_workstation = surf_workstation;
+SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) {
+  CHECK_INIT_DONE();
+
+  SD_workstation_data_t sd_data = xbt_new0(s_SD_workstation_data_t, 1); /* workstation private data */
+  sd_data->surf_workstation = surf_workstation;
   
-  SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1);
-  workstation->name = xbt_strdup(name);
+  SD_workstation_t workstation = xbt_new0(s_SD_workstation_t, 1);
   workstation->data = data; /* user data */
-  workstation->sgdata = sgdata; /* private data */
+  workstation->sd_data = sd_data; /* private data */
   
-  xbt_dict_set(sg_global->workstations, name, workstation, free); /* add the workstation to the dictionary */
+  const char *name = SD_workstation_get_name(workstation);
+  xbt_dict_set(sd_global->workstations, name, workstation, free); /* add the workstation to the dictionary */
 
   /* TODO: route */
-
   return workstation;
 }
 
 /* Returns a workstation given its name, or NULL if there is no such workstation.
  */
-SG_workstation_t SG_workstation_get_by_name(const char *name) {
-  xbt_assert0(sg_global != NULL, "SG_init not called yet");
+SD_workstation_t SD_workstation_get_by_name(const char *name) {
+  CHECK_INIT_DONE();
+
   xbt_assert0(name != NULL, "Invalid parameter");
 
-  return xbt_dict_get_or_null(sg_global->workstations, name);
+  return xbt_dict_get_or_null(sd_global->workstations, name);
 }
 
 /* Returns a NULL-terminated array of existing workstations.
  */
-SG_workstation_t*  SG_workstation_get_list(void) {
-  xbt_assert0(sg_global != NULL, "SG_init not called yet");
-  SG_workstation_t* array = xbt_new0(SG_workstation_t, sg_global->workstation_count + 1);
+SD_workstation_t*  SD_workstation_get_list(void) {
+  CHECK_INIT_DONE();
+
+  SD_workstation_t* array = xbt_new0(SD_workstation_t, sd_global->workstation_count + 1);
   
   xbt_dict_cursor_t cursor;
   char *key;
   void *data;
   int i=0;
 
-  xbt_dict_foreach(sg_global->workstations,cursor,key,data) {
-    array[i++] = (SG_workstation_t) data;
+  xbt_dict_foreach(sd_global->workstations,cursor,key,data) {
+    array[i++] = (SD_workstation_t) data;
   }
   array[i] = NULL;
 
@@ -51,54 +55,59 @@ SG_workstation_t*  SG_workstation_get_list(void) {
 
 /* Returns the number or workstations.
  */
-int SG_workstation_get_number(void) {
-  xbt_assert0(sg_global != NULL, "SG_init not called yet");
-  return sg_global->workstation_count;
+int SD_workstation_get_number(void) {
+  CHECK_INIT_DONE();
+  return sd_global->workstation_count;
 }
 
 /* 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.
  */
-void SG_workstation_set_data(SG_workstation_t workstation, void *data) {
+void SD_workstation_set_data(SD_workstation_t workstation, void *data) {
+  CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
   workstation->data = data;
 }
 
 /* Returns the data of a workstation. The user data can be NULL.
  */
-void* SG_workstation_get_data(SG_workstation_t workstation) {
+void* SD_workstation_get_data(SD_workstation_t workstation) {
+  CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
   return workstation->data;
 }
 
 /* Returns the name of a workstation.
  */
-const char* SG_workstation_get_name(SG_workstation_t workstation) {
+const char* SD_workstation_get_name(SD_workstation_t workstation) {
+  CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
-  return workstation->name;
+  return surf_workstation_resource->common_public->get_resource_name(workstation->sd_data->surf_workstation);
 }
 
-SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) {
+SD_link_t* SD_workstation_route_get_list(SD_workstation_t src, SD_workstation_t dst) {
+  CHECK_INIT_DONE();
   /* TODO */
   return NULL;
 }
 
-int SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst) {
+int SD_workstation_route_get_size(SD_workstation_t src, SD_workstation_t dst) {
+  CHECK_INIT_DONE();
   /* TODO */
   return 0;
 }
 
 /* Returns the total power of a workstation.
  */
-double SG_workstation_get_power(SG_workstation_t workstation) {
+double SD_workstation_get_power(SD_workstation_t workstation) {
+  CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
-  /* TODO */
-  return 0;
-  /*  return workstation->power;*/
+  return surf_workstation_resource->extension_public->get_speed(workstation->sd_data->surf_workstation, 1.0);
 }
 
-/* Return the available power of a workstation.
+/* Returns the proportion of available power in a workstation (normally a number between 0 and 1).
  */
-double SG_workstation_get_available_power(SG_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;
@@ -107,15 +116,12 @@ double SG_workstation_get_available_power(SG_workstation_t workstation) {
 
 /* Destroys a workstation. The user data (if any) should have been destroyed first.
  */
-void __SG_workstation_destroy(SG_workstation_t workstation) {
+void __SD_workstation_destroy(SD_workstation_t workstation) {
+  CHECK_INIT_DONE();
   xbt_assert0(workstation != NULL, "Invalid parameter");
 
-  if (workstation->sgdata != NULL) {
-    xbt_free(workstation->sgdata);
-  }
-  
-  if (workstation->name != NULL) {
-    xbt_free(workstation->name);
+  if (workstation->sd_data != NULL) {
+    xbt_free(workstation->sd_data);
   }
   
   /* TODO: route */