Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7d43b69be03384c92e6f8fd5c6c10175c57683ae
[simgrid.git] / src / surf / vm_interface.cpp
1 /* Copyright (c) 2013-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "cpu_cas01.hpp"
8 #include "vm_interface.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf,
11                                 "Logging specific to the SURF VM module");
12
13 VMModel *surf_vm_model = NULL;
14
15 /*************
16  * Callbacks *
17  *************/
18
19 surf_callback(void, VM*) VMCreatedCallbacks;
20 surf_callback(void, VM*) VMDestructedCallbacks;
21 surf_callback(void, VM*) VMStateChangedCallbacks;
22
23 /*********
24  * Model *
25  *********/
26
27 VMModel::VMModel() : HostModel("Virtual Machine") {}
28
29 VMModel::vm_list_t VMModel::ws_vms;
30
31 /************
32  * Resource *
33  ************/
34
35 VM::VM(Model *model, const char *name, xbt_dict_t props,
36                         RoutingEdge *netElm, Cpu *cpu)
37 : Host(model, name, props, NULL, netElm, cpu)
38 {
39   VMModel::ws_vms.push_back(*this);
40   surf_callback_emit(VMCreatedCallbacks, this);
41 }
42
43 /*
44  * A physical host does not disapper in the current SimGrid code, but a VM may
45  * disapper during a simulation.
46  */
47 VM::~VM()
48 {
49   surf_callback_emit(VMDestructedCallbacks, this);
50   VMModel::ws_vms.erase(VMModel::
51                                    vm_list_t::s_iterator_to(*this));
52 }
53
54 void VM::setState(e_surf_resource_state_t state){
55   Resource::setState(state);
56   surf_callback_emit(VMStateChangedCallbacks, this);
57 }
58
59 /*
60  * A surf level object will be useless in the upper layer. Returing the
61  * dict_elm of the host.
62  **/
63 surf_resource_t VM::getPm()
64 {
65   return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName());
66 }
67
68 /**********
69  * Action *
70  **********/
71
72 //FIME:: handle action cancel
73