X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9ba3bfdef0f13d77474c16059ca813b75ade43ab..578dd56a4a07709db1922ff5edd98f0c8f3090f9:/src/surf/virtual_machine.cpp diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 37b24e7400..75017d8790 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -7,8 +7,7 @@ #include "cpu_cas01.hpp" #include "virtual_machine.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, - "Logging specific to the SURF VM module"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module"); simgrid::surf::VMModel *surf_vm_model = NULL; @@ -19,9 +18,9 @@ namespace surf { * Callbacks * *************/ -simgrid::surf::signal VMCreatedCallbacks; -simgrid::surf::signal VMDestructedCallbacks; -simgrid::surf::signal VMStateChangedCallbacks; +simgrid::xbt::signal VMCreatedCallbacks; +simgrid::xbt::signal VMDestructedCallbacks; +simgrid::xbt::signal VMStateChangedCallbacks; /********* * Model * @@ -33,43 +32,50 @@ VMModel::vm_list_t VMModel::ws_vms; * Resource * ************/ -VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props, - RoutingEdge *netElm, Cpu *cpu) -: Host(model, name, props, NULL, netElm, cpu) +VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u::Host *hostPM) +: HostImpl(model, name, NULL, NULL, NULL) +, hostPM_(hostPM) { VMModel::ws_vms.push_back(*this); - simgrid::Host::by_name_or_create(name)->extension_set(this); + simgrid::s4u::Host::by_name_or_create(name)->extension_set(this); } /* - * A physical host does not disappear in the current SimGrid code, but a VM may - * disappear during a simulation. + * A physical host does not disappear in the current SimGrid code, but a VM may disappear during a simulation. */ VirtualMachine::~VirtualMachine() { VMDestructedCallbacks(this); VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this)); + /* Free the cpu_action of the VM. */ + XBT_ATTRIB_UNUSED int ret = action_->unref(); + xbt_assert(ret == 1, "Bug: some resource still remains"); } -void VirtualMachine::setState(e_surf_resource_state_t state){ - Resource::setState(state); - VMStateChangedCallbacks(this); +e_surf_vm_state_t VirtualMachine::getState() { + return p_vm_state; } -/* - * A surf level object will be useless in the upper layer. Returning the - * dict_elm of the host. - **/ -sg_host_t VirtualMachine::getPm() -{ - return p_subWs->getHost(); +void VirtualMachine::setState(e_surf_vm_state_t state) { + p_vm_state = state; +} +void VirtualMachine::turnOn() { + if (isOff()) { + Resource::turnOn(); + VMStateChangedCallbacks(this); + } +} +void VirtualMachine::turnOff() { + if (isOn()) { + Resource::turnOff(); + VMStateChangedCallbacks(this); + } } -/********** - * Action * - **********/ - -//FIME:: handle action cancel +/** @brief returns the physical machine on which the VM is running **/ +sg_host_t VirtualMachine::getPm() { + return hostPM_; +} } }