Logo AND Algorithmique Numérique Distribuée

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