Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5f395d667eeb1bd1f7477412564dcc3f57a57dc6
[simgrid.git] / include / simgrid / s4u / Disk.hpp
1 /* Copyright (c) 2019-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 INCLUDE_SIMGRID_S4U_DISK_HPP_
7 #define INCLUDE_SIMGRID_S4U_DISK_HPP_
8
9 #include <simgrid/disk.h>
10 #include <simgrid/forward.h>
11 #include <simgrid/s4u/Io.hpp>
12 #include <xbt/Extendable.hpp>
13 #include <xbt/base.h>
14 #include <xbt/signal.hpp>
15
16 #include <map>
17 #include <string>
18 #include <unordered_map>
19
20 namespace simgrid {
21
22 extern template class XBT_PUBLIC xbt::Extendable<s4u::Disk>;
23
24 namespace s4u {
25
26 /** Disk represent the disk resources associated to a host
27  *
28  * By default, SimGrid does not keep track of the actual data being written but
29  * only computes the time taken by the corresponding data movement.
30  */
31
32 class XBT_PUBLIC Disk : public xbt::Extendable<Disk> {
33   friend Engine;
34   friend Io;
35   friend kernel::resource::DiskImpl;
36
37   explicit Disk(kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl) {}
38   virtual ~Disk() = default;
39
40   // The private implementation, that never changes
41   kernel::resource::DiskImpl* const pimpl_;
42
43 public:
44 #ifndef DOXYGEN
45   kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
46 #endif
47
48   std::string const& get_name() const;
49   /** @brief Retrieves the name of that disk as a C string */
50   const char* get_cname() const;
51
52   Disk* set_read_bandwidth(double read_bw);
53   double get_read_bandwidth() const;
54
55   Disk* set_write_bandwidth(double write_bw);
56   double get_write_bandwidth() const;
57
58   const std::unordered_map<std::string, std::string>* get_properties() const;
59   const char* get_property(const std::string& key) const;
60   Disk* set_property(const std::string&, const std::string& value);
61   Disk* set_properties(const std::unordered_map<std::string, std::string>& properties);
62
63   Disk* set_host(Host* host);
64   Host* get_host() const;
65
66   Disk* set_state_profile(kernel::profile::Profile* profile);
67   Disk* set_read_bandwidth_profile(kernel::profile::Profile* profile);
68   Disk* set_write_bandwidth_profile(kernel::profile::Profile* profile);
69
70   IoPtr io_init(sg_size_t size, s4u::Io::OpType type) const;
71
72   IoPtr read_async(sg_size_t size) const;
73   sg_size_t read(sg_size_t size) const;
74
75   IoPtr write_async(sg_size_t size) const;
76   sg_size_t write(sg_size_t size) const;
77
78   Disk* seal();
79
80   /* The signals */
81   /** @brief Callback signal fired when a new Disk is created */
82   static xbt::signal<void(Disk&)> on_creation;
83   /** @brief Callback signal fired when a Disk is destroyed */
84   static xbt::signal<void(Disk const&)> on_destruction;
85   /** @brief Callback signal fired when a Disk's state changes */
86   static xbt::signal<void(Disk const&)> on_state_change;
87 };
88
89 } // namespace s4u
90 } // namespace simgrid
91
92 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */