Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Still fixing bugs - Adrien
[simgrid.git] / src / surf / vm_workstation.c
index 90242e9..94933eb 100644 (file)
@@ -22,23 +22,44 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
 
 surf_model_t surf_vm_workstation_model = NULL;
 
-static void vm_ws_create (const char *name, void *phys_workstation)
+static void vm_ws_create(const char *name, void *ind_phys_workstation)
 {
   workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1);
-// TODO Implement the surf vm workstation model
+// TODO Complete the surf vm workstation model
   vm_ws->generic_resource.model = surf_vm_workstation_model;
   vm_ws->generic_resource.name = xbt_strdup(name);
-  vm_ws->physical_workstation = phys_workstation;
+ // ind means ''indirect'' that this is a reference on the whole dict_elm structure (i.e not on the surf_resource_private infos)
+  vm_ws->physical_workstation = surf_workstation_resource_priv(ind_phys_workstation);
   vm_ws->current_state=msg_vm_state_created,
   xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
 }
 
-static int vm_ws_get_state(void *vm_ws){
-       return ((workstation_VM2013_t)vm_ws)->current_state;
+
+/*
+ * A physical host does not disapper in the current SimGrid code, but a VM may
+ * disapper during a simulation.
+ */
+static void vm_ws_destroy(void *ind_phys_workstation)
+{ 
+       /* ind_phys_workstation equals to smx_host_t */
+       workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_phys_workstation);
+       xbt_assert(vm_ws);
+       xbt_assert(vm_ws->generic_resource.model == surf_vm_workstation_model);
+
+       const char *name = vm_ws->generic_resource.name;
+       /* this will call surf_resource_free() */
+       xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL);
+
+       xbt_free(vm_ws->generic_resource.name);
+       xbt_free(vm_ws);
+}
+
+static int vm_ws_get_state(void *ind_vm_ws){
+       return ((workstation_VM2013_t) surf_workstation_resource_priv(ind_vm_ws))->current_state;
 }
 
-static void vm_ws_set_state(void *vm_ws, int state){
-        ((workstation_VM2013_t)vm_ws)->current_state=state;
+static void vm_ws_set_state(void *ind_vm_ws, int state){
+        ((workstation_VM2013_t) surf_workstation_resource_priv(ind_vm_ws))->current_state=state;
 }
 static void surf_vm_workstation_model_init_internal(void)
 {
@@ -49,6 +70,7 @@ static void surf_vm_workstation_model_init_internal(void)
   surf_vm_workstation_model->extension.vm_workstation.create = vm_ws_create;
   surf_vm_workstation_model->extension.vm_workstation.set_state = vm_ws_set_state;
   surf_vm_workstation_model->extension.vm_workstation.get_state = vm_ws_get_state;
+  surf_vm_workstation_model->extension.vm_workstation.destroy = vm_ws_destroy;
 
 }