Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-stoprofiles'
[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/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   kernel::resource::DiskImpl* const pimpl_;
34   std::string name_;
35   friend Engine;
36   friend Io;
37   friend kernel::resource::DiskImpl;
38
39 protected:
40 #ifndef DOXYGEN
41   virtual ~Disk() = default;
42 #endif
43
44 public:
45 #ifndef DOXYGEN
46   explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name) {}
47 #endif
48
49   /** @brief Callback signal fired when a new Disk is created */
50   static xbt::signal<void(Disk&)> on_creation;
51   /** @brief Callback signal fired when a Disk is destroyed */
52   static xbt::signal<void(Disk const&)> on_destruction;
53   /** @brief Callback signal fired when a Disk's state changes */
54   static xbt::signal<void(Disk const&)> on_state_change;
55
56   /** @brief Retrieves the name of that disk as a C++ string */
57   std::string const& get_name() const { return name_; }
58   /** @brief Retrieves the name of that disk as a C string */
59   const char* get_cname() const { return name_.c_str(); }
60   double get_read_bandwidth() const;
61   double get_write_bandwidth() const;
62   const std::unordered_map<std::string, std::string>* get_properties() const;
63   const char* get_property(const std::string& key) const;
64   void set_property(const std::string&, const std::string& value);
65   Host* get_host() const;
66
67   IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
68
69   IoPtr read_async(sg_size_t size);
70   sg_size_t read(sg_size_t size);
71
72   IoPtr write_async(sg_size_t size);
73   sg_size_t write(sg_size_t size);
74 #ifndef DOXYGEN
75   kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
76 #endif
77 };
78
79 } // namespace s4u
80 } // namespace simgrid
81
82 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */