X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18d23a87c23647366cfffbc61d3f7c632301159c..9a74a4d9c970bf6b49d2c15d284ca190451d5ef6:/src/surf/vm_workstation_interface.cpp diff --git a/src/surf/vm_workstation_interface.cpp b/src/surf/vm_workstation_interface.cpp index 4c4959162e..688ad12418 100644 --- a/src/surf/vm_workstation_interface.cpp +++ b/src/surf/vm_workstation_interface.cpp @@ -1,9 +1,9 @@ -/* - * vm_workstation.cpp - * - * Created on: Nov 12, 2013 - * Author: bedaride - */ +/* Copyright (c) 2013-2014. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include "vm_workstation_interface.hpp" #include "cpu_cas01.hpp" @@ -12,6 +12,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf, WorkstationVMModelPtr surf_vm_workstation_model = NULL; +/************* + * Callbacks * + *************/ + +surf_callback(void, WorkstationVMPtr) workstationVMCreatedCallbacks; +surf_callback(void, WorkstationVMPtr) workstationVMDestructedCallbacks; +surf_callback(void, WorkstationVMPtr) workstationVMStateChangedCallbacks; + /********* * Model * *********/ @@ -20,15 +28,19 @@ WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation p_cpuModel = surf_cpu_model_vm; } +WorkstationVMModel::vm_list_t WorkstationVMModel::ws_vms; + /************ * Resource * ************/ - -WorkstationVMLmm::WorkstationVMLmm(RoutingEdgePtr netElm, CpuPtr cpu) - : WorkstationVM(netElm, cpu) - , WorkstationLmm() -{} +WorkstationVM::WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props, + RoutingEdgePtr netElm, CpuPtr cpu) +: Workstation(model, name, props, NULL, netElm, cpu) +{ + WorkstationVMModel::ws_vms.push_back(*this); + surf_callback_emit(workstationVMCreatedCallbacks, this); +} /* * A physical host does not disapper in the current SimGrid code, but a VM may @@ -36,34 +48,14 @@ WorkstationVMLmm::WorkstationVMLmm(RoutingEdgePtr netElm, CpuPtr cpu) */ WorkstationVM::~WorkstationVM() { - /* ind_phys_workstation equals to smx_host_t */ - surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName()); - - /* Before clearing the entries in host_lib, we have to pick up resources. */ - CpuCas01LmmPtr cpu = dynamic_cast( - static_cast( - surf_cpu_resource_priv(ind_vm_workstation))); - - /* We deregister objects from host_lib, without invoking the freeing callback - * of each level. - * - * Do not call xbt_lib_remove() here. It deletes all levels of the key, - * including MSG_HOST_LEVEL and others. We should unregister only what we know. - */ - xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0); - xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0); - xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0); - - /* TODO: comment out when VM stroage is implemented. */ - // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); - - - /* Free the cpu_action of the VM. */ - int ret = p_action->unref(); - xbt_assert(ret == 1, "Bug: some resource still remains"); - - /* Free the cpu resource of the VM. If using power_trace, we will have to */ - delete cpu; + surf_callback_emit(workstationVMDestructedCallbacks, this); + WorkstationVMModel::ws_vms.erase(WorkstationVMModel:: + vm_list_t::s_iterator_to(*this)); +} + +void WorkstationVM::setState(e_surf_resource_state_t state){ + Resource::setState(state); + surf_callback_emit(workstationVMStateChangedCallbacks, this); } /*