Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / include / simgrid / s4u / Disk.hpp
1 /* Copyright (c) 2019-2020. 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/forward.h>
10 #include <simgrid/s4u/Io.hpp>
11 #include <xbt/Extendable.hpp>
12 #include <xbt/base.h>
13 #include <xbt/signal.hpp>
14
15 #include <map>
16 #include <string>
17 #include <unordered_map>
18
19 namespace simgrid {
20 namespace s4u {
21
22 /** Disk represent the disk resources associated to a host
23  *
24  * By default, SimGrid does not keep track of the actual data being written but
25  * only computes the time taken by the corresponding data movement.
26  */
27
28 class XBT_PUBLIC Disk : public xbt::Extendable<Disk> {
29   kernel::resource::DiskImpl* const pimpl_;
30   std::string name_;
31   friend Engine;
32   friend Io;
33   friend kernel::resource::DiskImpl;
34
35 protected:
36   virtual ~Disk() = default;
37
38 public:
39   explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name) {}
40
41   /** @brief Callback signal fired when a new Disk is created */
42   static xbt::signal<void(Disk&)> on_creation;
43   /** @brief Callback signal fired when a Disk is destroyed */
44   static xbt::signal<void(Disk const&)> on_destruction;
45   /** @brief Callback signal fired when a Disk's state changes */
46   static xbt::signal<void(Disk const&)> on_state_change;
47
48   /** @brief Retrieves the name of that disk as a C++ string */
49   std::string const& get_name() const { return name_; }
50   /** @brief Retrieves the name of that disk as a C string */
51   const char* get_cname() const { return name_.c_str(); }
52   double get_read_bandwidth() const;
53   double get_write_bandwidth() const;
54   const std::unordered_map<std::string, std::string>* get_properties() const;
55   const char* get_property(const std::string& key) const;
56   void set_property(const std::string&, const std::string& value);
57   Host* get_host() const;
58
59   IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
60
61   IoPtr read_async(sg_size_t size);
62   sg_size_t read(sg_size_t size);
63
64   IoPtr write_async(sg_size_t size);
65   sg_size_t write(sg_size_t size);
66   kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
67 };
68
69 } // namespace s4u
70 } // namespace simgrid
71
72 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */