Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid into no_simix_global
[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   ~VirtualMachine() override;
27
28 public:
29   explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount);
30   explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount, size_t ramsize);
31
32 #ifndef DOXYGEN
33   // No copy/move
34   VirtualMachine(VirtualMachine const&) = delete;
35   VirtualMachine& operator=(VirtualMachine const&) = delete;
36 #endif
37
38   // enum class State { ... }
39   XBT_DECLARE_ENUM_CLASS(State,
40     CREATED, /**< created, but not yet started */
41     RUNNING,
42     SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */
43     DESTROYED
44   );
45 #ifndef DOXYGEN
46   using state XBT_ATTRIB_DEPRECATED_v332("Please use VirtualMachine::State") = State;
47 #endif
48
49   vm::VirtualMachineImpl* get_vm_impl() const { return pimpl_vm_; }
50   void start();
51   void suspend();
52   void resume();
53   void shutdown();
54   void destroy() override;
55
56   Host* get_pm() const;
57   VirtualMachine* set_pm(Host* pm);
58   size_t get_ramsize() const;
59   VirtualMachine* set_ramsize(size_t ramsize);
60   VirtualMachine* set_bound(double bound);
61
62   State get_state() const;
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 };
71 } // namespace s4u
72 } // namespace simgrid
73
74 #endif