Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use CRTP to factor refcounting across activity types
[simgrid.git] / include / simgrid / s4u / VirtualMachine.hpp
1 /* Copyright (c) 2015-2019. 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
12 namespace simgrid {
13 namespace s4u {
14
15 /** @ingroup s4u_api
16  *
17  * @tableofcontents
18  *
19  * A VM represents a virtual machine (or a container) that hosts actors.
20  * The total computing power that the contained actors can get is constrained to the virtual machine size.
21  *
22  */
23 class XBT_PUBLIC VirtualMachine : public s4u::Host {
24   vm::VirtualMachineImpl* const pimpl_vm_;
25   virtual ~VirtualMachine();
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   // No copy/move
32   VirtualMachine(VirtualMachine const&) = delete;
33   VirtualMachine& operator=(VirtualMachine const&) = delete;
34
35   enum class state {
36     CREATED, /**< created, but not yet started */
37     RUNNING,
38     SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */
39     DESTROYED
40   };
41
42   vm::VirtualMachineImpl* get_impl() const { return pimpl_vm_; }
43   void start();
44   void suspend();
45   void resume();
46   void shutdown();
47   void destroy();
48
49   Host* get_pm();
50   void set_pm(Host* pm);
51   size_t get_ramsize();
52   void set_ramsize(size_t ramsize);
53   void set_bound(double bound);
54
55   VirtualMachine::state get_state();
56   static xbt::signal<void(VirtualMachine const&)> on_start;
57   static xbt::signal<void(VirtualMachine const&)> on_started;
58   static xbt::signal<void(VirtualMachine const&)> on_shutdown;
59   static xbt::signal<void(VirtualMachine const&)> on_suspend;
60   static xbt::signal<void(VirtualMachine const&)> on_resume;
61   static xbt::signal<void(VirtualMachine const&)> on_migration_start;
62   static xbt::signal<void(VirtualMachine const&)> on_migration_end;
63 };
64 } // namespace s4u
65 } // namespace simgrid
66
67 #endif