1 /* Copyright (c) 2013-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <xbt/signal.hpp>
9 #include "cpu_cas01.hpp"
10 #include "virtual_machine.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module");
14 simgrid::surf::VMModel *surf_vm_model = nullptr;
23 simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMCreatedCallbacks;
24 simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMDestructedCallbacks;
25 simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMStateChangedCallbacks;
31 VMModel::vm_list_t VMModel::ws_vms;
37 VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u::Host *hostPM)
38 : HostImpl(model, name, nullptr, nullptr, nullptr)
41 VMModel::ws_vms.push_back(*this);
42 simgrid::s4u::Host::by_name_or_create(name)->extension_set<simgrid::surf::HostImpl>(this);
46 * A physical host does not disappear in the current SimGrid code, but a VM may disappear during a simulation.
48 VirtualMachine::~VirtualMachine()
50 VMDestructedCallbacks(this);
51 VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this));
52 /* Free the cpu_action of the VM. */
53 XBT_ATTRIB_UNUSED int ret = action_->unref();
54 xbt_assert(ret == 1, "Bug: some resource still remains");
57 e_surf_vm_state_t VirtualMachine::getState() {
61 void VirtualMachine::setState(e_surf_vm_state_t state) {
64 void VirtualMachine::turnOn() {
67 VMStateChangedCallbacks(this);
70 void VirtualMachine::turnOff() {
73 VMStateChangedCallbacks(this);
77 /** @brief returns the physical machine on which the VM is running **/
78 sg_host_t VirtualMachine::getPm() {