Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into disk
[simgrid.git] / include / simgrid / s4u / Disk.hpp
1 /* Copyright (c) 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 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   friend Engine;
30   friend Io;
31   friend kernel::resource::DiskImpl;
32
33 public:
34   explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl);
35
36 protected:
37   virtual ~Disk() = default;
38
39 public:
40   /** @brief Callback signal fired when a new Storage is created */
41   static xbt::signal<void(Disk&)> on_creation;
42   /** @brief Callback signal fired when a Storage is destroyed */
43   static xbt::signal<void(Disk const&)> on_destruction;
44   /** @brief Callback signal fired when a Storage's state changes */
45   static xbt::signal<void(Disk const&)> on_state_change;
46
47   /** Retrieve a Storage by its name. It must exist in the platform file */
48   static Disk* by_name(const std::string& name);
49   static Disk* by_name_or_null(const std::string& name);
50
51   /** @brief Retrieves the name of that storage as a C++ string */
52   std::string const& get_name() const { return name_; }
53   /** @brief Retrieves the name of that storage as a C string */
54   const char* get_cname() const { return name_.c_str(); }
55
56   Host* get_host() { return attached_to_; };
57   void set_host(Host* host) { attached_to_ = host; }
58
59   const std::unordered_map<std::string, std::string>* get_properties() const;
60   const char* get_property(const std::string& key) const;
61   void set_property(const std::string&, const std::string& value);
62
63   void set_data(void* data) { userdata_ = data; }
64   void* get_data() { return userdata_; }
65
66   IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
67
68   IoPtr read_async(sg_size_t size);
69   sg_size_t read(sg_size_t size);
70
71   IoPtr write_async(sg_size_t size);
72   sg_size_t write(sg_size_t size);
73   kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
74
75 private:
76   Host* attached_to_ = nullptr;
77   kernel::resource::DiskImpl* const pimpl_;
78   std::string name_;
79   void* userdata_ = nullptr;
80 };
81
82 } // namespace s4u
83 } // namespace simgrid
84
85 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */