Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More consistency in resource creation/destruction
[simgrid.git] / include / simgrid / s4u / VirtualMachine.hpp
1 /* Copyright (c) 2015-2021. 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 #ifndef SIMGRID_S4U_VM_HPP
7 #define SIMGRID_S4U_VM_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Host.hpp>
11 #include <xbt/utility.hpp>
12
13 namespace simgrid {
14 namespace s4u {
15
16 /** @ingroup s4u_api
17  *
18  * @tableofcontents
19  *
20  * A VM represents a virtual machine (or a container) that hosts actors.
21  * The total computing power that the contained actors can get is constrained to the virtual machine size.
22  *
23  */
24 class XBT_PUBLIC VirtualMachine : public s4u::Host {
25   vm::VirtualMachineImpl* const pimpl_vm_;
26
27 public:
28   explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount);
29   explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount, size_t ramsize);
30
31 #ifndef DOXYGEN
32   // No copy/move
33   VirtualMachine(VirtualMachine const&) = delete;
34   VirtualMachine& operator=(VirtualMachine const&) = delete;
35 #endif
36
37   // enum class State { ... }
38   XBT_DECLARE_ENUM_CLASS(State,
39     CREATED, /**< created, but not yet started */
40     RUNNING,
41     SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */
42     DESTROYED
43   );
44 #ifndef DOXYGEN
45   using state XBT_ATTRIB_DEPRECATED_v332("Please use VirtualMachine::State") = State;
46 #endif
47
48   vm::VirtualMachineImpl* get_vm_impl() const { return pimpl_vm_; }
49   void start();
50   void suspend();
51   void resume();
52   void shutdown();
53   void destroy() override;
54
55   Host* get_pm() const;
56   VirtualMachine* set_pm(Host* pm);
57   size_t get_ramsize() const;
58   VirtualMachine* set_ramsize(size_t ramsize);
59   VirtualMachine* set_bound(double bound);
60
61   State get_state() const;
62   static xbt::signal<void(VirtualMachine&)> on_creation;
63   static xbt::signal<void(VirtualMachine const&)> on_start;
64   static xbt::signal<void(VirtualMachine const&)> on_started;
65   static xbt::signal<void(VirtualMachine const&)> on_shutdown;
66   static xbt::signal<void(VirtualMachine const&)> on_suspend;
67   static xbt::signal<void(VirtualMachine const&)> on_resume;
68   static xbt::signal<void(VirtualMachine const&)> on_migration_start;
69   static xbt::signal<void(VirtualMachine const&)> on_migration_end;
70   static xbt::signal<void(VirtualMachine const&)> on_destruction;
71 };
72 } // namespace s4u
73 } // namespace simgrid
74
75 #endif